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
Open
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
29e67a2
Rename BASEWEIGHT to BASE_WEIGHT for readability
virtualzavie Feb 11, 2025
80d16d0
Add Base Diffuse Roughness parameters
virtualzavie Feb 11, 2025
e9ce268
Plug diffuse roughness in the shader
virtualzavie Feb 12, 2025
fdb02fd
Plug diffuse roughness uniform and texture
virtualzavie Feb 13, 2025
7c4de63
Fix typo
virtualzavie Feb 13, 2025
914d254
Add test scene
virtualzavie Feb 12, 2025
6614545
Adding Lambert, EON and Burley as separate diffuse models.
Mar 5, 2025
19af1f5
Fixes for WebGPU
Mar 6, 2025
6515d9f
Change default diffuse roughness model to EON
Mar 6, 2025
09dfefe
Remove albedo being passed through to irradiance calc
Mar 6, 2025
19943bb
Fix for EON calculation
Mar 7, 2025
6f6c9f4
Add diffuse roughness vis tests
Mar 7, 2025
8a002b8
Update vis test reference
Mar 10, 2025
f964985
Fix baseDiffuseRoughness in WebGL 1.0
Mar 10, 2025
7b79ce1
Add diffuse roughness for prefiltered IBL
Mar 11, 2025
7f9e792
Fix for Burley IBL calculation
Mar 12, 2025
220c783
Update vis tests
Mar 15, 2025
b4159da
Add diffuse roughness prefiltered IBL approximation
Mar 15, 2025
4680584
Add shaders
Mar 17, 2025
499de22
Fix import error
Mar 18, 2025
39d557c
Add support for diffuse roughness with SH
Mar 18, 2025
70afee7
Fix vis tests
Mar 18, 2025
0080252
Explicitly define eye position in pbr vert
Mar 19, 2025
ad5a6ed
Define diffuse roughness in pbr vert
Mar 19, 2025
522ba17
Add EXT_materials_diffuse_roughness loader
Apr 1, 2025
3aa0836
Fix import
Apr 1, 2025
dc805f7
Address PR comments.
Apr 7, 2025
4dce91f
Fix shader compile error
MiiBond Apr 8, 2025
ad4bbc6
Update vis test reference
Apr 8, 2025
11215b5
Add diffuse roughness for analytical light transmission
MiiBond Apr 9, 2025
0b31a55
Add some comments
MiiBond Apr 9, 2025
9b5bca6
Make dominant direction internal
MiiBond Apr 14, 2025
38a3b82
Change diffuse roughness default
MiiBond Apr 15, 2025
1e5d962
Diffuse Roughness defaults to 0.0 and EON
MiiBond Apr 16, 2025
36965f6
Pass surfaceAlbedo to EON function
MiiBond Apr 16, 2025
11a6e33
Update packages/dev/core/src/Materials/PBR/pbrBaseMaterial.ts
MiiBond Apr 17, 2025
a346f2e
Add defines for diffuse roughness models
MiiBond Apr 17, 2025
bd8ba81
Rename diffuse roughness model to diffuse model
MiiBond Apr 17, 2025
d4c2ce8
Move diffuse model param to pbrMaterial
MiiBond Apr 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/dev/core/src/Engines/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,21 @@ export class Constants {
*/
public static readonly MATERIAL_CounterClockWiseSideOrientation = 1;

/**
* Energy-conserving Oren Nayar diffuse model type.
*/
public static readonly MATERIAL_DIFFUSE_ROUGHNESS_E_OREN_NAYAR = 0;

/**
* Burley diffuse model type.
*/
public static readonly MATERIAL_DIFFUSE_ROUGHNESS_BURLEY = 1;

/**
* 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?


/**
* Nothing
* @see https://doc.babylonjs.com/features/featuresDeepDive/events/actions#triggers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class PBRMetallicRoughnessBlock extends NodeMaterialBlock {
private _metallicReflectanceColor: Color3 = Color3.White();
private _metallicF0Factor = 1;
private _vMetallicReflectanceFactorsName: string;
private _baseDiffuseRoughnessName: string;

/**
* Create a new ReflectionBlock
Expand Down Expand Up @@ -270,6 +271,19 @@ export class PBRMetallicRoughnessBlock extends NodeMaterialBlock {
})
public realTimeFilteringQuality = Constants.TEXTURE_FILTERING_QUALITY_LOW;

/**
* 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

notifiers: { update: true },
options: [
{ label: "Lambert", value: Constants.MATERIAL_DIFFUSE_ROUGHNESS_LAMBERT },
{ label: "Burley", value: Constants.MATERIAL_DIFFUSE_ROUGHNESS_BURLEY },
{ label: "Oren-Nayar", value: Constants.MATERIAL_DIFFUSE_ROUGHNESS_E_OREN_NAYAR },
],
})
public baseDiffuseRoughnessModel = Constants.MATERIAL_DIFFUSE_ROUGHNESS_E_OREN_NAYAR;

/**
* Defines if the material uses energy conservation.
*/
Expand Down Expand Up @@ -761,6 +775,8 @@ export class PBRMetallicRoughnessBlock extends NodeMaterialBlock {
defines.setValue("NUM_SAMPLES", "" + this.realTimeFilteringQuality, true);
}

defines.setValue("BASE_DIFFUSE_ROUGHNESS_MODEL", this.baseDiffuseRoughnessModel, true);

// Advanced
defines.setValue("BRDF_V_HEIGHT_CORRELATED", true);
defines.setValue("MS_BRDF_ENERGY_CONSERVATION", this.useEnergyConservation, true);
Expand Down Expand Up @@ -1013,13 +1029,21 @@ export class PBRMetallicRoughnessBlock extends NodeMaterialBlock {
this._vMetallicReflectanceFactorsName = state._getFreeVariableName("vMetallicReflectanceFactors");
state._emitUniformFromString(this._vMetallicReflectanceFactorsName, NodeMaterialBlockConnectionPointTypes.Vector4);

this._baseDiffuseRoughnessName = state._getFreeVariableName("baseDiffuseRoughness");
state._emitUniformFromString(this._baseDiffuseRoughnessName, NodeMaterialBlockConnectionPointTypes.Float);

code += `${state._declareLocalVar("baseColor", NodeMaterialBlockConnectionPointTypes.Vector3)} = surfaceAlbedo;
${isWebGPU ? "let" : `vec4${state.fSuffix}`} vReflectivityColor = vec4${state.fSuffix}(${this.metallic.associatedVariableName}, ${this.roughness.associatedVariableName}, ${this.indexOfRefraction.associatedVariableName || "1.5"}, 1.0);
reflectivityOut = reflectivityBlock(
vReflectivityColor
#ifdef METALLICWORKFLOW
, surfaceAlbedo
, ${(isWebGPU ? "uniforms." : "") + this._vMetallicReflectanceFactorsName}
#endif
, ${(isWebGPU ? "uniforms." : "") + this._baseDiffuseRoughnessName}
#ifdef BASE_DIFFUSE_ROUGHNESS
, 0.
, vec2${state.fSuffix}(0., 0.)
#endif
#ifdef REFLECTIVITY
, vec3${state.fSuffix}(0., 0., ${aoIntensity})
Expand All @@ -1035,6 +1059,7 @@ export class PBRMetallicRoughnessBlock extends NodeMaterialBlock {

${state._declareLocalVar("microSurface", NodeMaterialBlockConnectionPointTypes.Float)} = reflectivityOut.microSurface;
${state._declareLocalVar("roughness", NodeMaterialBlockConnectionPointTypes.Float)} = reflectivityOut.roughness;
${state._declareLocalVar("diffuseRoughness", NodeMaterialBlockConnectionPointTypes.Float)} = reflectivityOut.diffuseRoughness;

#ifdef METALLICWORKFLOW
surfaceAlbedo = reflectivityOut.surfaceAlbedo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ export class ReflectionBlock extends ReflectionTextureBaseBlock {
#ifdef USEIRRADIANCEMAP
, irradianceSampler // ** not handled **
${isWebGPU ? `, irradianceSamplerSampler` : ""}
#ifdef USE_IRRADIANCE_DOMINANT_DIRECTION
, vReflectionDominantDirection
#endif
#endif
#ifndef LODBASEDMICROSFURACE
#ifdef ${this._define3DName}
Expand All @@ -459,6 +462,8 @@ export class ReflectionBlock extends ReflectionTextureBaseBlock {
${isWebGPU ? `, icdfSamplerSampler` : ""}
#endif
#endif
, viewDirectionW
, diffuseRoughness
);
#endif\n`;

Expand Down
Loading
Loading