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 38 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

@sebavan I'm not sure if this is what you're asking for but here's a quick comparison of the only case where backwards compatibility will be lost. The only change is that roughness will no longer affect diffuse roughness for analytical lights. It only affects specular roughness now because we have a separate parameter for the diffuse roughness.

Here's what it used to look like for rough spheres with a single directional light:
https://playground.babylonjs.com/?snapshot=refs/pull/16253/merge#MXACV7#17

And here's what it will look like now for rough spheres with a single directional light:
https://playground.babylonjs.com/?snapshot=refs/pull/16253/merge#MXACV7#18

@MiiBond MiiBond force-pushed the openpbr/diffuse_roughness branch from eededd0 to 38a3b82 Compare April 15, 2025 17:18
@MiiBond
Copy link
Contributor Author

MiiBond commented Apr 15, 2025

@sebavan I've changed the default to Burley and also changed the logic so that if diffuseRoughness isn't set, we'll use the value from roughness instead. Note that this will change the look of IBL irradiance on rough surfaces, compared to the current behaviour.

@Popov72 I've marked _dominantDirection @internal.

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 15, 2025

@bjsplat
Copy link
Collaborator

bjsplat commented Apr 15, 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 ?

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