-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Diffuse Roughness support #16253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Diffuse Roughness support #16253
Conversation
Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). |
Snapshot stored with reference name: Test environment: To test a playground add it to the URL, for example: https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/16253/merge/index.html#WGZLGJ#4600 Links to test babylon tools with this snapshot: https://playground.babylonjs.com/?snapshot=refs/pull/16253/merge To test the snapshot in the playground with a playground ID add it after the snapshot query string: https://playground.babylonjs.com/?snapshot=refs/pull/16253/merge#BCU1XR#0 |
WebGL2 visualization test reporter: |
Visualization tests for WebGPU |
1 similar comment
Visualization tests for WebGPU |
WebGL2 visualization test reporter: |
Visualization tests for WebGPU |
WebGL2 visualization test reporter: |
3580a82
to
55f34a0
Compare
WebGL2 visualization test reporter: |
Visualization tests for WebGPU |
1 similar comment
Visualization tests for WebGPU |
WebGL2 visualization test reporter: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only a partial review with a couple of comments.
packages/tools/tests/test/visualization/ReferenceImages/openpbr-base-diffuse-roughness.png
Outdated
Show resolved
Hide resolved
...ols/tests/test/visualization/ReferenceImages/openpbr-base-diffuse-roughness-realtime-ibl.png
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Continued review.
packages/dev/core/src/Shaders/ShadersInclude/hdrFilteringFunctions.fx
Outdated
Show resolved
Hide resolved
packages/dev/core/src/Shaders/ShadersInclude/pbrDirectLightingFunctions.fx
Outdated
Show resolved
Hide resolved
packages/dev/core/src/Shaders/ShadersInclude/pbrDirectLightingFunctions.fx
Outdated
Show resolved
Hide resolved
packages/dev/core/src/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.fx
Outdated
Show resolved
Hide resolved
packages/dev/core/src/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.fx
Outdated
Show resolved
Hide resolved
Visualization tests for WebGPU |
WebGL2 visualization test reporter: |
1 similar comment
WebGL2 visualization test reporter: |
Visualization tests for WebGPU |
203a6cf
to
5ee9410
Compare
WebGL2 visualization test reporter: |
Visualization tests for WebGPU |
WebGL2 visualization test reporter: |
Visualization tests for WebGPU |
6b0f7a4
to
2f1cf0e
Compare
WebGL2 visualization test reporter: |
Visualization tests for WebGPU |
Note that a lot more of the visualization tests have now failed because we're defaulting the diffuse roughness to the specular roughness when not set. This was the previous behaviour but now we support diffuse roughness for IBL's so any Playground that uses rough materials and IBL will look different. |
Oh is it not equivalent to the legacy code if we do diffuse roughness = spec roughness in burley mode ? Cause I guess in this case we should more aim at back compat in default case ? |
packages/dev/core/src/Shaders/ShadersInclude/pbrBRDFFunctions.fx
Outdated
Show resolved
Hide resolved
I think the most backwards-compatible behaviour would be to default |
Visualization tests for WebGPU |
WebGL2 visualization test reporter: |
@MiiBond I don't know if you missed them, but just in case, there are still a few issues to be resolved, which are hidden under the link "48 hidden items": |
Co-authored-by: Popov72 <[email protected]>
WebGL2 visualization test reporter: |
Visualization tests for WebGPU |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very partial review as I'm reading this implementation.
/** | ||
* Lambertian diffuse model type. | ||
*/ | ||
public static readonly MATERIAL_DIFFUSE_ROUGHNESS_LAMBERT = 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit counter intuitive to have both "ROUGHNESS" and "LAMBERT" in the same name, given that the Lambert model is for perfectly flat diffuse surface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. Maybe MATERIAL_DIFFUSE_ROUGHNESS_NONE
is better?
/** | ||
* Base Diffuse Roughness Model | ||
*/ | ||
@editableInPropertyPage("Diffuse Roughness Model", PropertyTypeForEdition.List, "RENDERING", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following my previous remark, maybe this should simply be called "Diffuse Model".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yeah, that's a good point. I like that more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to look quite noisy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. This scene is prefiltering without CDF and the IBL has a strong sunlight in it so I expect noise. I could have chosen a different IBL but I thought I'd keep it consistent with the other test scenes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok, without a CDF that's expected indeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This render looks very dark. Is something wrong with the setup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just what the spherical harmonics look like with this IBL. I assume it's just the lack of accuracy that you get with SH but I couldn't say for sure that it's correct.
I didn't change the SH generation or anything though so, if there is an issue, I don't think we should worry about it in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll let @sebavan look if this is expected or if something's amiss.
I was just surprised to see this render being much darker than the others.
Visualization tests for WebGPU |
WebGL2 visualization test reporter: |
@Popov72 Thank you, I did miss some of those. I've addressed them all now, I think, except for the |
WebGL2 visualization test reporter: |
Visualization tests for WebGPU |
Is there a way for full back compat ? In case this breaks prod apps ? |
Well, we could hard code the analytical lighting functions to always use Burley with specular roughness and ignore diffuse roughness completely. |
You can ask on the forum, as we had quite a few users coming back to use for broken back compat on previous changes and we had to add back compat flags :-( When the impact is mid/large visually we need some solutions for it even more when it is not a bug fix. |
I would even say we need some solution even for minor changes if they are not bugs. |
Would we be able to make this new behaviour the default but add a flag to enable some sort of legacy mode? Or maybe diffuse roughness is just disabled by default and the user has to flip it on via a flag? Loaded assets could also flip the flag since this is only used by a brand new glTF extension. |
WebGL2 visualization test reporter: |
Visualization tests for WebGPU |
The point 3. is selling it to me. As long as we have a Documented way to go back to the previous renders, I am totally fine with it. Now which model should be the default is the tricky one ? |
This PR replaces #16183
This PR implements the base_diffuse_roughness parameter from the OpenPBR specification.
The diffuse roughness is implemented for analytic lights, realtime-filtered IBL, prefiltered IBL and spherical harmonics.
I've added a flag to a material to choose between Lambert, Burley and the new Energy Conserving Oren-Nayar (EON) model used by OpenPBR. The default is OpenPBR's EON model.
The previous behaviour was to use Burley diffuse for analytical lights and Lambert for IBL. Also, previously, specular roughness was applied to diffuse roughness for analytical lights while IBL didn't use it at all (because it was simply Lambertian). So, the new default slightly changes existing projects that used analytical lights but I question how noticeable that will be.
Analytical Light:

https://playground.babylonjs.com/?snapshot=refs/pull/16253/merge#MXACV7#3
Realtime IBL:

https://playground.babylonjs.com/?snapshot=refs/pull/16253/merge#MXACV7#5
The diffuse roughness models are heavily dependent on the light direction and view direction and are therefore difficult to handle with a prefiltered IBL. I came up with two methods for approximating roughness with prefiltered IBL's. The first, if we prefiltered using CDF, we generate a dominant light direction to use in the BRDF calculations. It works reasonably well.
Prefiltered IBL with CDF:

https://playground.babylonjs.com/?snapshot=refs/pull/16253/merge#MXACV7#9
The second approach, if you don't use CDF, is by approximating roughness by bending the surface normal towards the camera to add some of the retro-reflective behaviour that you get with EON. Because of this, you'll notice that Burley and EON are identical and the shadow terminator appears to move as diffuse roughness increases. In practice, however, this example uses an extreme IBL with a bright sunlight. With other IBL's, the effect tends to be more convincing.
Prefiltered IBL without CDF

https://playground.babylonjs.com/?snapshot=refs/pull/16253/merge#MXACV7#10
The default IBL lighting in Sandbox uses spherical harmonics so we need to approximate diffuse roughness with this as well. I'm using the same bent normal technique as with prefiltered IBL without CDF.
Spherical Harmonics IBL

https://playground.babylonjs.com/?snapshot=refs/pull/16253/merge#MXACV7#11