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

Merged
merged 46 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
06ff8b5
Rename BASEWEIGHT to BASE_WEIGHT for readability
virtualzavie Feb 11, 2025
ad9c6eb
Add Base Diffuse Roughness parameters
virtualzavie Feb 11, 2025
aa6bb9e
Plug diffuse roughness in the shader
virtualzavie Feb 12, 2025
84b1199
Plug diffuse roughness uniform and texture
virtualzavie Feb 13, 2025
9204d3d
Fix typo
virtualzavie Feb 13, 2025
0ec91b5
Add test scene
virtualzavie Feb 12, 2025
af5d0bd
Adding Lambert, EON and Burley as separate diffuse models.
Mar 5, 2025
2c188d9
Fixes for WebGPU
Mar 6, 2025
8068163
Change default diffuse roughness model to EON
Mar 6, 2025
ad24207
Remove albedo being passed through to irradiance calc
Mar 6, 2025
bf83b6d
Fix for EON calculation
Mar 7, 2025
1981892
Add diffuse roughness vis tests
Mar 7, 2025
2a5021b
Update vis test reference
Mar 10, 2025
306c0d7
Fix baseDiffuseRoughness in WebGL 1.0
Mar 10, 2025
f1f7c34
Add diffuse roughness for prefiltered IBL
Mar 11, 2025
edd49b3
Fix for Burley IBL calculation
Mar 12, 2025
1c49178
Update vis tests
Mar 15, 2025
6d52d50
Add diffuse roughness prefiltered IBL approximation
Mar 15, 2025
e9e5b42
Add shaders
Mar 17, 2025
e6c1fb8
Fix import error
Mar 18, 2025
0c064d5
Add support for diffuse roughness with SH
Mar 18, 2025
7ccc631
Fix vis tests
Mar 18, 2025
97f63b5
Explicitly define eye position in pbr vert
Mar 19, 2025
bd9d442
Define diffuse roughness in pbr vert
Mar 19, 2025
fd4fba9
Add EXT_materials_diffuse_roughness loader
Apr 1, 2025
5cdbaf4
Fix import
Apr 1, 2025
782a98a
Address PR comments.
Apr 7, 2025
de751dc
Fix shader compile error
MiiBond Apr 8, 2025
cfa127d
Update vis test reference
Apr 8, 2025
c3a56a9
Add diffuse roughness for analytical light transmission
MiiBond Apr 9, 2025
fd885dc
Add some comments
MiiBond Apr 9, 2025
bc3588d
Make dominant direction internal
MiiBond Apr 14, 2025
3c9c45a
Change diffuse roughness default
MiiBond Apr 15, 2025
56279ac
Diffuse Roughness defaults to 0.0 and EON
MiiBond Apr 16, 2025
7ef870a
Pass surfaceAlbedo to EON function
MiiBond Apr 16, 2025
a9d9965
Update packages/dev/core/src/Materials/PBR/pbrBaseMaterial.ts
MiiBond Apr 17, 2025
1ec22e7
Add defines for diffuse roughness models
MiiBond Apr 17, 2025
3ce5fa8
Rename diffuse roughness model to diffuse model
MiiBond Apr 17, 2025
9e914d6
Move diffuse model param to pbrMaterial
MiiBond Apr 23, 2025
f3b936a
Add default diffuse model to PBRMaterial
MiiBond Apr 30, 2025
d4278a2
Simplify dominantDirection setting
MiiBond May 5, 2025
ad419a4
Rename GLTFLoaderExtensionOptions
MiiBond May 5, 2025
a5f0dbf
Revert "Rename GLTFLoaderExtensionOptions"
MiiBond May 5, 2025
4250924
Add eslint-disable line in rough diffuse glTF loader
MiiBond May 5, 2025
264d811
Update voxel shadow tests to make them faster
MiiBond May 5, 2025
64a669e
Add new reference image for voxel shadows test
MiiBond May 5, 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 @@ -469,6 +469,21 @@ export class Constants {
*/
public static readonly MATERIAL_CounterClockWiseSideOrientation = 1;

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

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

/**
* Lambertian diffuse model type.
*/
public static readonly MATERIAL_DIFFUSE_MODEL_LAMBERT = 2;

/**
* 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 @@ -97,6 +97,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 @@ -271,6 +272,19 @@ export class PBRMetallicRoughnessBlock extends NodeMaterialBlock {
})
public realTimeFilteringQuality = Constants.TEXTURE_FILTERING_QUALITY_LOW;

/**
* Base Diffuse Model
*/
@editableInPropertyPage("Diffuse Model", PropertyTypeForEdition.List, "RENDERING", {
notifiers: { update: true },
options: [
{ label: "Lambert", value: Constants.MATERIAL_DIFFUSE_MODEL_LAMBERT },
{ label: "Burley", value: Constants.MATERIAL_DIFFUSE_MODEL_BURLEY },
{ label: "Oren-Nayar", value: Constants.MATERIAL_DIFFUSE_MODEL_E_OREN_NAYAR },
],
})
public baseDiffuseModel = Constants.MATERIAL_DIFFUSE_MODEL_E_OREN_NAYAR;

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

defines.setValue("BASE_DIFFUSE_MODEL", this.baseDiffuseModel, true);

// Advanced
defines.setValue("BRDF_V_HEIGHT_CORRELATED", true);
defines.setValue("MS_BRDF_ENERGY_CONSERVATION", this.useEnergyConservation, true);
Expand Down Expand Up @@ -1014,13 +1030,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 @@ -1036,6 +1060,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,9 @@ export class ReflectionBlock extends ReflectionTextureBaseBlock {
${isWebGPU ? `, icdfSamplerSampler` : ""}
#endif
#endif
, viewDirectionW
, diffuseRoughness
, surfaceAlbedo
);
#endif\n`;

Expand Down
Loading