-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add OpenPBR's base_diffuse_roughness material parameter #16183
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
Closed
virtualzavie
wants to merge
6
commits into
BabylonJS:master
from
virtualzavie:openpbr/diffuse_roughness
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
11958dc
Rename BASEWEIGHT to BASE_WEIGHT for readability
virtualzavie ca7bb4a
Add Base Diffuse Roughness parameters
virtualzavie 7fa6da5
Plug diffuse roughness in the shader
virtualzavie afab542
Plug diffuse roughness uniform and texture
virtualzavie 1b8ed92
Fix typo
virtualzavie 8459ac5
Add test scene
virtualzavie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,8 +100,10 @@ export class PBRMaterialDefines extends MaterialDefines implements IImageProcess | |
public ALBEDODIRECTUV = 0; | ||
public VERTEXCOLOR = false; | ||
|
||
public BASEWEIGHT = false; | ||
public BASEWEIGHTDIRECTUV = 0; | ||
public BASE_WEIGHT = false; | ||
public BASE_WEIGHTDIRECTUV = 0; | ||
public BASE_DIFFUSE_ROUGHNESS = false; | ||
public BASE_DIFFUSE_ROUGHNESSDIRECTUV = 0; | ||
|
||
public BAKED_VERTEX_ANIMATION_TEXTURE = false; | ||
|
||
|
@@ -422,11 +424,17 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
public _albedoTexture: Nullable<BaseTexture> = null; | ||
|
||
/** | ||
* OpenPBR Base Weight (multiplier to the diffuse and metal lobes). | ||
* OpenPBR Base Weight texture (multiplier to the diffuse and metal lobes). | ||
* @internal | ||
*/ | ||
public _baseWeightTexture: Nullable<BaseTexture> = null; | ||
|
||
/** | ||
* OpenPBR Base Diffuse Roughness texture (roughness of the diffuse lobe). | ||
* @internal | ||
*/ | ||
public _baseDiffuseRoughnessTexture: Nullable<BaseTexture> = null; | ||
|
||
/** | ||
* AKA Occlusion Texture in other nomenclature. | ||
* @internal | ||
|
@@ -575,6 +583,13 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
*/ | ||
public _baseWeight = 1; | ||
|
||
/** | ||
* OpenPBR Base Diffuse Roughness (roughness of the diffuse lobe). | ||
* Can also be used to scale the corresponding texture. | ||
* @internal | ||
*/ | ||
public _baseDiffuseRoughness: Nullable<number> = null; | ||
|
||
/** | ||
* AKA Specular Color in other nomenclature. | ||
* @internal | ||
|
@@ -1131,6 +1146,12 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
} | ||
} | ||
|
||
if (this._baseDiffuseRoughnessTexture && MaterialFlags.BaseDiffuseRoughnessTextureEnabled) { | ||
if (!this._baseDiffuseRoughnessTexture.isReadyOrNotBlocking()) { | ||
return false; | ||
} | ||
} | ||
|
||
if (this._ambientTexture && MaterialFlags.AmbientTextureEnabled) { | ||
if (!this._ambientTexture.isReadyOrNotBlocking()) { | ||
return false; | ||
|
@@ -1443,6 +1464,7 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
"vAmbientColor", | ||
"vAlbedoColor", | ||
"baseWeight", | ||
"baseDiffuseRoughness", | ||
"vReflectivityColor", | ||
"vMetallicReflectanceFactors", | ||
"vEmissiveColor", | ||
|
@@ -1453,6 +1475,7 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
"pointSize", | ||
"vAlbedoInfos", | ||
"vBaseWeightInfos", | ||
"vBaseDiffuseRoughnessInfos", | ||
"vAmbientInfos", | ||
"vOpacityInfos", | ||
"vReflectionInfos", | ||
|
@@ -1469,6 +1492,7 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
"mBones", | ||
"albedoMatrix", | ||
"baseWeightMatrix", | ||
"baseDiffuseRoughnessMatrix", | ||
"ambientMatrix", | ||
"opacityMatrix", | ||
"reflectionMatrix", | ||
|
@@ -1511,6 +1535,7 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
const samplers = [ | ||
"albedoSampler", | ||
"baseWeightSampler", | ||
"baseDiffuseRoughnessSampler", | ||
"reflectivitySampler", | ||
"ambientSampler", | ||
"emissiveSampler", | ||
|
@@ -1647,7 +1672,8 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
} | ||
if (scene.texturesEnabled) { | ||
defines.ALBEDODIRECTUV = 0; | ||
defines.BASEWEIGHTDIRECTUV = 0; | ||
defines.BASE_WEIGHTDIRECTUV = 0; | ||
defines.BASE_DIFFUSE_ROUGHNESSDIRECTUV = 0; | ||
defines.AMBIENTDIRECTUV = 0; | ||
defines.OPACITYDIRECTUV = 0; | ||
defines.EMISSIVEDIRECTUV = 0; | ||
|
@@ -1670,9 +1696,15 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
} | ||
|
||
if (this._baseWeightTexture && MaterialFlags.BaseWeightTextureEnabled) { | ||
PrepareDefinesForMergedUV(this._baseWeightTexture, defines, "BASEWEIGHT"); | ||
PrepareDefinesForMergedUV(this._baseWeightTexture, defines, "BASE_WEIGHT"); | ||
} else { | ||
defines.BASE_WEIGHT = false; | ||
} | ||
|
||
if (this._baseDiffuseRoughnessTexture && MaterialFlags.BaseDiffuseRoughnessTextureEnabled) { | ||
PrepareDefinesForMergedUV(this._baseDiffuseRoughnessTexture, defines, "BASE_DIFFUSE_ROUGHNESS"); | ||
} else { | ||
defines.BASEWEIGHT = false; | ||
defines.BASE_DIFFUSE_ROUGHNESS = false; | ||
} | ||
|
||
if (this._ambientTexture && MaterialFlags.AmbientTextureEnabled) { | ||
|
@@ -2024,6 +2056,7 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
const ubo = this._uniformBuffer; | ||
ubo.addUniform("vAlbedoInfos", 2); | ||
ubo.addUniform("vBaseWeightInfos", 2); | ||
ubo.addUniform("vBaseDiffuseRoughnessInfos", 2); | ||
ubo.addUniform("vAmbientInfos", 4); | ||
ubo.addUniform("vOpacityInfos", 2); | ||
ubo.addUniform("vEmissiveInfos", 2); | ||
|
@@ -2037,6 +2070,7 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
ubo.addUniform("vBumpInfos", 3); | ||
ubo.addUniform("albedoMatrix", 16); | ||
ubo.addUniform("baseWeightMatrix", 16); | ||
ubo.addUniform("baseDiffuseRoughnessMatrix", 16); | ||
ubo.addUniform("ambientMatrix", 16); | ||
ubo.addUniform("opacityMatrix", 16); | ||
ubo.addUniform("emissiveMatrix", 16); | ||
|
@@ -2050,6 +2084,7 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
ubo.addUniform("vReflectionColor", 3); | ||
ubo.addUniform("vAlbedoColor", 4); | ||
ubo.addUniform("baseWeight", 1); | ||
ubo.addUniform("baseDiffuseRoughness", 1); | ||
ubo.addUniform("vLightingIntensity", 4); | ||
|
||
ubo.addUniform("vReflectionMicrosurfaceInfos", 3); | ||
|
@@ -2157,6 +2192,11 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
BindTextureMatrix(this._baseWeightTexture, ubo, "baseWeight"); | ||
} | ||
|
||
if (this._baseDiffuseRoughnessTexture && MaterialFlags.BaseDiffuseRoughnessTextureEnabled) { | ||
ubo.updateFloat2("vBaseDiffuseRoughnessInfos", this._baseDiffuseRoughnessTexture.coordinatesIndex, this._baseDiffuseRoughnessTexture.level); | ||
BindTextureMatrix(this._baseDiffuseRoughnessTexture, ubo, "baseDiffuseRoughness"); | ||
} | ||
|
||
if (this._ambientTexture && MaterialFlags.AmbientTextureEnabled) { | ||
ubo.updateFloat4( | ||
"vAmbientInfos", | ||
|
@@ -2319,6 +2359,11 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
} | ||
|
||
ubo.updateFloat("baseWeight", this._baseWeight); | ||
if (this._baseDiffuseRoughness !== null && this._baseDiffuseRoughness !== undefined) { | ||
ubo.updateFloat("baseDiffuseRoughness", this._baseDiffuseRoughness); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ubo.updateFloat("baseDiffuseRoughness", this._baseDiffuseRoughness ?? this._roughness); |
||
} else if (this._roughness !== null && this._roughness !== undefined) { | ||
ubo.updateFloat("baseDiffuseRoughness", this._roughness); | ||
} | ||
|
||
// Misc | ||
this._lightingInfos.x = this._directIntensity; | ||
|
@@ -2346,6 +2391,10 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
ubo.setTexture("baseWeightSampler", this._baseWeightTexture); | ||
} | ||
|
||
if (this._baseDiffuseRoughnessTexture && MaterialFlags.BaseDiffuseRoughnessTextureEnabled) { | ||
ubo.setTexture("baseDiffuseRoughnessSampler", this._baseDiffuseRoughnessTexture); | ||
} | ||
|
||
if (this._ambientTexture && MaterialFlags.AmbientTextureEnabled) { | ||
ubo.setTexture("ambientSampler", this._ambientTexture); | ||
} | ||
|
@@ -2484,6 +2533,10 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
results.push(this._baseWeightTexture); | ||
} | ||
|
||
if (this._baseDiffuseRoughnessTexture && this._baseDiffuseRoughnessTexture.animations && this._baseDiffuseRoughnessTexture.animations.length > 0) { | ||
results.push(this._baseDiffuseRoughnessTexture); | ||
} | ||
|
||
if (this._ambientTexture && this._ambientTexture.animations && this._ambientTexture.animations.length > 0) { | ||
results.push(this._ambientTexture); | ||
} | ||
|
@@ -2556,6 +2609,10 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
activeTextures.push(this._baseWeightTexture); | ||
} | ||
|
||
if (this._baseDiffuseRoughnessTexture) { | ||
activeTextures.push(this._baseDiffuseRoughnessTexture); | ||
} | ||
|
||
if (this._ambientTexture) { | ||
activeTextures.push(this._ambientTexture); | ||
} | ||
|
@@ -2621,6 +2678,10 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
return true; | ||
} | ||
|
||
if (this._baseDiffuseRoughnessTexture === texture) { | ||
return true; | ||
} | ||
|
||
if (this._ambientTexture === texture) { | ||
return true; | ||
} | ||
|
@@ -2701,6 +2762,7 @@ export abstract class PBRBaseMaterial extends PushMaterial { | |
|
||
this._albedoTexture?.dispose(); | ||
this._baseWeightTexture?.dispose(); | ||
this._baseDiffuseRoughnessTexture?.dispose(); | ||
this._ambientTexture?.dispose(); | ||
this._opacityTexture?.dispose(); | ||
this._reflectionTexture?.dispose(); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What should be done here?