AcademySoftwareFoundation / AcademySoftwareFoundation/MaterialX
Reference geometric normal in `mx_forward_facing_normal`
- Dominant language
- C++
- Stars
- 2.3k
- Forks
- 451
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 8
Description
As of today, our GLSL implementation of `mx_forward_facing_normal` uses the _per-pixel shading normal_ to compute whether a surface is forward or back-facing, flipping that same per-pixel normal when the surface is found to be back-facing:
https://github.com/AcademySoftwareFoundation/MaterialX/blob/d114ab795c0ad780b2dfce0c2b6ca3b4993dff65/libraries/pbrlib/genglsl/lib/mx_microfacet.glsl#L56
Ideally, we should be using the _geometric normal_ to test the facing of the surface, flipping the per-pixel shading normal when the dot product between the geometric normal and view direction is negative. See the OSL codebase for a good reference of this approach:
https://github.com/AcademySoftwareFoundation/OpenShadingLanguage/blob/71dd75945f5257f00ecac1fe151901e81410680b/src/shaders/stdosl.h#L204
Contributor guide
Research direction
Start in libraries/pbrlib/genglsl/lib/mx_microfacet.glsl at the referenced mx_forward_facing_normal implementation, then compare the facing logic with src/shaders/stdosl.h in OpenShadingLanguage. Confirm the geometric normal controls the facing test while the shading normal is the one flipped, and verify the generated shader behavior for front- and back-facing surfaces.
Written by the indexing model from the issue text.
Assessment
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100