Skip to content

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

Open
wants to merge 39 commits into
base: master
Choose a base branch
from

Conversation

MiiBond
Copy link
Contributor

@MiiBond MiiBond commented Mar 5, 2025

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
roughnessCompare

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

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
image

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
image

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
image

@MiiBond MiiBond marked this pull request as draft March 5, 2025 22:03
@bjsplat
Copy link
Collaborator

bjsplat commented Mar 5, 2025

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Mar 5, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Mar 5, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Mar 5, 2025

1 similar comment
@bjsplat
Copy link
Collaborator

bjsplat commented Mar 6, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Mar 6, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Mar 6, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Mar 6, 2025

@MiiBond MiiBond force-pushed the openpbr/diffuse_roughness branch from 3580a82 to 55f34a0 Compare March 7, 2025 04:29
@bjsplat
Copy link
Collaborator

bjsplat commented Mar 7, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Mar 7, 2025

1 similar comment
@bjsplat
Copy link
Collaborator

bjsplat commented Mar 7, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Mar 7, 2025

Copy link
Contributor

@virtualzavie virtualzavie left a 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.

Copy link
Contributor

@virtualzavie virtualzavie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continued review.

@bjsplat
Copy link
Collaborator

bjsplat commented Mar 10, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Mar 10, 2025

1 similar comment
@bjsplat
Copy link
Collaborator

bjsplat commented Mar 10, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Mar 10, 2025

@MiiBond MiiBond force-pushed the openpbr/diffuse_roughness branch from 203a6cf to 5ee9410 Compare March 11, 2025 23:57
@bjsplat
Copy link
Collaborator

bjsplat commented Mar 12, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Mar 12, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Mar 12, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Mar 12, 2025

@MiiBond MiiBond marked this pull request as ready for review March 12, 2025 18:25
@MiiBond MiiBond force-pushed the openpbr/diffuse_roughness branch from 6b0f7a4 to 2f1cf0e Compare March 12, 2025 18:37
@bjsplat
Copy link
Collaborator

bjsplat commented Mar 12, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Mar 12, 2025

@MiiBond
Copy link
Contributor Author

MiiBond commented Apr 15, 2025

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.

@sebavan
Copy link
Member

sebavan commented Apr 15, 2025

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 ?

@MiiBond
Copy link
Contributor Author

MiiBond commented Apr 16, 2025

Cause I guess in this case we should more aim at back compat in default case ?

I think the most backwards-compatible behaviour would be to default baseDiffuseRoughness to 0.0 so that diffuse lighting is effectively Lambertian for every type of lighting. This effects only the backwards compatibility of rough surfaces for analytical lights.

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 16, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 16, 2025

@Popov72
Copy link
Contributor

Popov72 commented Apr 17, 2025

@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":

image

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 17, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 17, 2025

Copy link
Contributor

@virtualzavie virtualzavie left a 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;
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Comment on lines 274 to 277
/**
* Base Diffuse Roughness Model
*/
@editableInPropertyPage("Diffuse Roughness Model", PropertyTypeForEdition.List, "RENDERING", {
Copy link
Contributor

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".

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 17, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 17, 2025

@MiiBond
Copy link
Contributor Author

MiiBond commented Apr 17, 2025

there are still a few issues to be resolved

@Popov72 Thank you, I did miss some of those. I've addressed them all now, I think, except for the pbrBaseMaterial VS pbrMaterial question.

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 17, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 17, 2025

@sebavan
Copy link
Member

sebavan commented Apr 17, 2025

Cause I guess in this case we should more aim at back compat in default case ?

I think the most backwards-compatible behaviour would be to default baseDiffuseRoughness to 0.0 so that diffuse lighting is effectively Lambertian for every type of lighting. This effects only the backwards compatibility of rough surfaces for analytical lights.

Is there a way for full back compat ? In case this breaks prod apps ?

@MiiBond
Copy link
Contributor Author

MiiBond commented Apr 21, 2025

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.
Do you have a communications channel for breaking changes?

@sebavan
Copy link
Member

sebavan commented Apr 21, 2025

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.

@sebavan
Copy link
Member

sebavan commented Apr 21, 2025

I would even say we need some solution even for minor changes if they are not bugs.

@MiiBond
Copy link
Contributor Author

MiiBond commented Apr 22, 2025

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.

@MiiBond
Copy link
Contributor Author

MiiBond commented Apr 23, 2025

I'd like to suggest that we don't add a special flag to enable the legacy behaviour. Here is my reasoning:

  1. The legacy behaviour was inconsistent in that it applied Burley diffuse only for analytical lights and not for IBL. This makes adding a backwards-compatibility flag pretty awkward and messy.
  2. The change is not noticeable in most cases and pretty subtle when it is. Existing projects will only appear different if they use analytical lights and rough surfaces. Only the diffuse lobe changes and only when viewing the surface from the direction of the light. For example, here is the most extreme comparison between Burley and Lambert. A fully-rough sphere, viewed directly along the directional light vector.
    Roughness1
    When viewed from the side, there is no difference.
    Roughness1-side
  3. If a user really wants the legacy appearance, it can be achieved by choosing Burley as the diffuse model and setting diffuse roughness to match specular roughness.

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 23, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 23, 2025

@sebavan
Copy link
Member

sebavan commented Apr 23, 2025

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants