[x3d-public] PBR > freewrl experience

GPU Group gpugroup at gmail.com
Sun Apr 5 15:26:30 PDT 2020


My experience with freewrl mixing appearance.material / backMaterial types:
- the old TwoSidedMaterial already implemented and working paved the way
- I just needed a bit of tinkering, and presto, I can do any combination of
(front/back) no material, Material, UnlitMaterial and PhycalMaterial. I can
even have no front material and assign something to backMaterial - and do
it all in one pass in one shader:
http://dug9.users.sourceforge.net/web3d/tests/PBR/sidedness.x3dv
http://dug9.users.sourceforge.net/web3d/tests/PBR/screenshot_sidedness.jpg
- in the frag shader, first thing in main() I check gl_FrontFacing and mat
= frontmat else mat = backmat, then use mat for all the getters like
getDiffuse() getEmissive() and have a mat.type int for
non,unlit,material,physical so I can do some if-else.

Before doing that, I tried two pass -a loop on the CPU side, with only one
material, and switching the cull face -, but in freewrl I was making a
mess, but I did see a bit of unlit on one side, and regular on the other
side, proving it can be done if necessary:
http://dug9.users.sourceforge.net/web3d/tests/PBR/lit_unlit_2_pass.jpg

Hypothesis: for distributions with limited texture units, one idea is to
use a textureArray sampler type. I haven't studied it but if something like
that would save textureUnits then there might be no need for 2-pass.
-Doug Sanden

On Thu, Mar 19, 2020 at 9:33 AM Michalis Kamburelis <
michalis.kambi at gmail.com> wrote:

> Many, many thanks for this work, and for writing a detailed report
> summarizing the implementation experience. This is great! Very
> valuable to me, and I'm sure to other implementors too. And I'm very
> happy that you got these results so quickly (16 days for PBR rendering
> implementation is very quick, IMHO :) ).
>
> I looked at your code and I only noticed one thing:
>
> https://sourceforge.net/p/freewrl/git/ci/develop/tree/freex3d/src/lib/scenegraph/Component_Shape.c
> calls "baseColorTexture", but the node field should be just
> "baseTexture". This naming (without additional "Color" in the middle)
> looks a bit simpler, and is consistent with CommonSurfaceShader too.
>
> Regards,
> Michalis
>
> czw., 19 mar 2020 o 16:03 GPU Group <gpugroup at gmail.com> napisał(a):
> >
> > My experience implementing some of the PBR v4 features in freewrl:
> > - took 16 days
> > - I started by defining the PhysicalMaterial, UnlitMaterial and
> extending the Material node fields, using Michalis's documetation.
> >
> https://github.com/michaliskambi/x3d-tests/wiki/X3D-version-4:-New-features-of-materials,-lights-and-textures#new-x3dmaterialnode-node-with-emissive-and-normalmap-textures
> > - and internally extended structs in program and shader to hold all the
> new fields
> > - then most of the 2 weeks was getting the information flowing to the
> shader without breaking current functionality,
> > -- appearance.backMaterial - I spent a few days harmonizing
> TwoMaterialShader and this new approach
> > -- for the texture maps I found there ware lots of issues with old code
> assuming certain scenarios, and I spent about a week refactoring messy old
> code
> > - I found the khronos glTF sample had some interesting hints beyond
> physical, for example they use getter() functions in frag code that
> hides/abstracts the issue of whether or not there's a texture map.
> >
> >
> https://github.com/KhronosGroup/glTF-Sample-Viewer/tree/master/src/shaders
> >
> > - see the metallic-roughness.frag
> >
> > normal = getNormal();
> >
> > And I refactored the frag shader to use getters like they do.
> >
> > - I spent a few extra hours reading up on normal maps (which I learned
> are in 'tangent space' so need a transform matrix called TBN applied):
> >
> > https://learnopengl.com/Advanced-Lighting/Normal-Mapping
> >
> > - normal map normals are expressed in tangent space
> >
> >
> > Once I had getters, and had all the info flowing to the frag shader,
> then it only took a few days to do the metalic-roughness functionality.
> >
> > If you have a loop where you are applying the lights, you probably have
> something like:
> >
> > diffuse += ...
> >
> > specular +=
> >
> > ambient +=
> >
> > inside the loop.
> >
> > For metalic-roughness, I found I could replace those 3 with
> >
> > shade = getPointShade(pointToLight, materialInfo, normal, view);
> >
> > from the khronos example to make a PBR equivalent light loop.
> >
> >
> > So in hindsight, it would have been easy to start with the scalar
> PhyscialMaterial fields, and I could have added the texturemaps to the
> getters() later.
> >
> > For those implementing for GLES < 3.0 where texture units are in short
> supply, the scalar part of PhysicalMaterial should be no problem.
> >
> >
> > I still have some minor tinkiering to do -when to apply gamma or its
> inverse, Michalis has given some answers. And field naming,
> textureTransform/textureCoordinate 'channel' field conventions, and I
> haven't attempted EnvironmentLight.
> >
> > Results:
> >
> > 1) PBR physics based rendering via PhysicalMaterial node
> >  - the lighting equations use roughness and metallic with baseColor
> > - (instead of specular, shininess and diffuseColor)
> > - and constrain to physics principle of 'conservation of energy'
> >
> http://dug9.users.sourceforge.net/web3d/tests/PBR/screenshot_pbr_teapots_view3dscene_freewrl.jpg
> >
> http://dug9.users.sourceforge.net/web3d/tests/PBR/metallic_roughness.x3dv
> >
> > 2) extended Material node - supports texture maps for normals, emissive,
> diffuse, specularShininess, ambient
> >
> http://dug9.users.sourceforge.net/web3d/tests/PBR/screenshot_e_mat_sphere240_view3dscene_freewrl.jpg
> > http://dug9.users.sourceforge.net/web3d/tests/PBR/sphere_240_fw.x3dv
> >
> > The PhysicalMaterial node also supports texturemap for metallicRoughness
> although I haven't tested.
> >
> > 3) UnlitMaterial - roughed in plumbing but haven't tested thoroughly -
> should work and support normal and emissive texture maps
> >
> > freewrl code samples:
> >
> https://sourceforge.net/p/freewrl/git/ci/develop/tree/freex3d/src/lib/opengl/Compositing_Shaders.c
> > L.1106 MaterialInfo and gamma functions from Khronos glTF example
> > L.1155 getNormal() and getter() farm starts
> > L.1300-1340 getting ready for apply_lights_physical
> > L.1806 apply_lights_physical code with khronos glTF sample functions,
> followed by freewrl light loop calling shade = pointShade(...) L.1917
> >
> https://sourceforge.net/p/freewrl/git/ci/develop/tree/freex3d/src/lib/scenegraph/Component_Shape.c
> > L.1417 compile_PhysicalMaterial - organizes into internal structs and
> flags for sending to shader
> > _______________________________________________
> > x3d-public mailing list
> > x3d-public at web3d.org
> > http://web3d.org/mailman/listinfo/x3d-public_web3d.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20200405/10b697d1/attachment-0001.html>


More information about the x3d-public mailing list