Skip to content

Commit 6a284da

Browse files
author
Mike Bond
committed
Added OpenPBR inspector data and WIP on coat noramls
1 parent 2bdb407 commit 6a284da

24 files changed

+710
-85
lines changed

packages/dev/core/src/Materials/PBR/openPbrMaterial.ts

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,15 @@ export class OpenPBRMaterial extends OpenPBRMaterialBase {
625625
// eslint-disable-next-line @typescript-eslint/no-unused-vars
626626
private _geometryNormalTexture: Sampler = new Sampler("geometry_normal", "geometryNormal", "GEOMETRY_NORMAL");
627627

628+
/**
629+
* Defines the normal of the material's coat layer.
630+
* See OpenPBR's specs for geometry_coat_normal
631+
*/
632+
public geometryCoatNormalTexture: BaseTexture;
633+
@addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "geometryCoatNormalTexture")
634+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
635+
private _geometryCoatNormalTexture: Sampler = new Sampler("geometry_coat_normal", "geometryCoatNormal", "GEOMETRY_COAT_NORMAL");
636+
628637
/**
629638
* Defines the opacity of the material's geometry.
630639
* See OpenPBR's specs for geometry_opacity
@@ -643,6 +652,15 @@ export class OpenPBRMaterial extends OpenPBRMaterialBase {
643652
// eslint-disable-next-line @typescript-eslint/no-unused-vars
644653
private _geometryOpacityTexture: Sampler = new Sampler("geometry_opacity", "geometryOpacity", "GEOMETRY_OPACITY");
645654

655+
/**
656+
* Defines the opacity of the material's geometry.
657+
* See OpenPBR's specs for geometry_opacity
658+
*/
659+
public emissionLuminance: number;
660+
@addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "emissionLuminance")
661+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
662+
private _emissionLuminance: Property<number> = new Property<number>("emission_luminance", 1.0, "vLightingIntensity", 4, 1);
663+
646664
/**
647665
* Defines the color of the material's emission.
648666
* See OpenPBR's specs for emission_color
@@ -656,10 +674,10 @@ export class OpenPBRMaterial extends OpenPBRMaterialBase {
656674
* Defines the color of the material's emission.
657675
* See OpenPBR's specs for emission_color
658676
*/
659-
public emissionTexture: BaseTexture;
660-
@addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "emissionTexture")
677+
public emissionColorTexture: BaseTexture;
678+
@addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "emissionColorTexture")
661679
// eslint-disable-next-line @typescript-eslint/no-unused-vars
662-
private _emissionTexture: Sampler = new Sampler("emission", "emission", "EMISSION");
680+
private _emissionColorTexture: Sampler = new Sampler("emission_color", "emissionColor", "EMISSION_COLOR");
663681

664682
/**
665683
* Defines the ambient occlusion texture.
@@ -682,14 +700,6 @@ export class OpenPBRMaterial extends OpenPBRMaterialBase {
682700
@expandToProperty("_markAllSubMeshesAsTexturesDirty")
683701
public directIntensity: number = 1.0;
684702

685-
/**
686-
* Intensity of the emissive part of the material.
687-
* This helps controlling the emissive effect without modifying the emissive color.
688-
*/
689-
@serialize()
690-
@expandToProperty("_markAllSubMeshesAsTexturesDirty")
691-
public emissiveIntensity: number = 1.0;
692-
693703
/**
694704
* Intensity of the environment e.g. how much the environment will light the object
695705
* either through harmonics for rough material or through the reflection for shiny ones.
@@ -967,13 +977,6 @@ export class OpenPBRMaterial extends OpenPBRMaterialBase {
967977
*/
968978
public _directIntensity: number = 1.0;
969979

970-
/**
971-
* Intensity of the emissive part of the material.
972-
* This helps controlling the emissive effect without modifying the emissive color.
973-
* @internal
974-
*/
975-
public _emissiveIntensity: number = 1.0;
976-
977980
/**
978981
* Intensity of the environment e.g. how much the environment will light the object
979982
* either through harmonics for rough material or through the reflection for shiny ones.
@@ -984,7 +987,7 @@ export class OpenPBRMaterial extends OpenPBRMaterialBase {
984987
/**
985988
* This stores the direct, emissive, environment, and specular light intensities into a Vector4.
986989
*/
987-
private _lightingInfos: Vector4 = new Vector4(this._directIntensity, this._emissiveIntensity, this._environmentIntensity, 1.0);
990+
private _lightingInfos: Vector4 = new Vector4(this._directIntensity, 1.0, this._environmentIntensity, 1.0);
988991

989992
/**
990993
* Stores the radiance (and, possibly, irradiance) values in a texture.
@@ -1317,10 +1320,12 @@ export class OpenPBRMaterial extends OpenPBRMaterialBase {
13171320
this._coatRoughnessTexture;
13181321
this._coatIor;
13191322
this._geometryNormalTexture;
1323+
this._geometryCoatNormalTexture;
13201324
this._geometryOpacity;
13211325
this._geometryOpacityTexture;
1326+
this._emissionLuminance;
13221327
this._emissionColor;
1323-
this._emissionTexture;
1328+
this._emissionColorTexture;
13241329
this._ambientOcclusionTexture;
13251330
}
13261331

@@ -1781,7 +1786,7 @@ export class OpenPBRMaterial extends OpenPBRMaterialBase {
17811786

17821787
// Misc
17831788
this._lightingInfos.x = this._directIntensity;
1784-
this._lightingInfos.y = this._emissiveIntensity;
1789+
this._lightingInfos.y = this.emissionLuminance;
17851790
this._lightingInfos.z = this._environmentIntensity * scene.environmentIntensity;
17861791
this._lightingInfos.w = 1.0; // This is used to be _specularIntensity.
17871792

packages/dev/core/src/Rendering/IBLShadows/iblShadowsPluginMaterial.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ export class IBLShadowsPluginMaterial extends MaterialPluginBase {
170170
#ifdef COLORED_IBL_SHADOWS
171171
var shadowValue: vec3f = computeIndirectShadow();
172172
slab_diffuse *= shadowValue;
173-
slab_glossy *= mix(vec3f(1.0), shadowValue, alphaG);
173+
slab_glossy *= mix(vec3f(1.0), shadowValue, specularAlphaG);
174174
#else
175175
var shadowValue: vec2f = computeIndirectShadow();
176176
slab_diffuse *= vec3f(shadowValue.x);
177-
slab_glossy *= vec3f(mix(pow(shadowValue.y, 4.0), shadowValue.x, alphaG));
177+
slab_glossy *= vec3f(mix(pow(shadowValue.y, 4.0), shadowValue.x, specularAlphaG));
178178
#endif
179179
#endif
180180
#else
@@ -248,11 +248,11 @@ export class IBLShadowsPluginMaterial extends MaterialPluginBase {
248248
#ifdef COLORED_IBL_SHADOWS
249249
vec3 shadowValue = computeIndirectShadow();
250250
slab_diffuse.rgb *= shadowValue.rgb;
251-
slab_glossy *= mix(vec3(1.0), shadowValue.rgb, alphaG);
251+
slab_glossy *= mix(vec3(1.0), shadowValue.rgb, specularAlphaG);
252252
#else
253253
vec2 shadowValue = computeIndirectShadow();
254254
slab_diffuse *= shadowValue.x;
255-
slab_glossy *= mix(pow(shadowValue.y, 4.0), shadowValue.x, alphaG);
255+
slab_glossy *= mix(pow(shadowValue.y, 4.0), shadowValue.x, specularAlphaG);
256256
#endif
257257
#endif
258258
#else

packages/dev/core/src/Shaders/ShadersInclude/openPbrUboDeclaration.fx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ uniform Material {
9191
mat4 coatRoughnessMatrix;
9292
vec2 vGeometryNormalInfos;
9393
mat4 geometryNormalMatrix;
94+
vec2 vGeometryCoatNormalInfos;
95+
mat4 geometryCoatNormalMatrix;
9496
vec2 vGeometryOpacityInfos;
9597
mat4 geometryOpacityMatrix;
96-
vec2 vEmissionInfos;
97-
mat4 emissionMatrix;
98+
vec2 vEmissionColorInfos;
99+
mat4 emissionColorMatrix;
98100
vec2 vAmbientOcclusionInfos;
99101
mat4 ambientOcclusionMatrix;
100102

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#if defined(FORCENORMALFORWARD) && defined(NORMAL)
2+
vec3 faceNormal = normalize(cross(dFdx(vPositionW), dFdy(vPositionW))) * vEyePosition.w;
3+
#if defined(TWOSIDEDLIGHTING)
4+
faceNormal = gl_FrontFacing ? faceNormal : -faceNormal;
5+
#endif
6+
7+
normalW *= sign(dot(normalW, faceNormal));
8+
coatNormalW *= sign(dot(coatNormalW, faceNormal));
9+
#endif
10+
11+
#if defined(TWOSIDEDLIGHTING) && defined(NORMAL)
12+
#if defined(MIRRORED)
13+
normalW = gl_FrontFacing ? -normalW : normalW;
14+
coatNormalW = gl_FrontFacing ? -coatNormalW : coatNormalW;
15+
#else
16+
normalW = gl_FrontFacing ? normalW : -normalW;
17+
coatNormalW = gl_FrontFacing ? coatNormalW : -coatNormalW;
18+
#endif
19+
#endif

packages/dev/core/src/Shaders/ShadersInclude/openpbrDirectLightingDiffuse.fx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
#ifdef LIGHT{X}
22
vec4 diffuse{X} = light{X}.vLightDiffuse;
33

4-
// Diffuse contribution
5-
#ifdef SS_TRANSLUCENCY
6-
info{X}.diffuseTransmission = vec3(0.0);
7-
#endif
8-
94
#ifdef HEMILIGHT{X}
105
info{X}.diffuse = computeHemisphericDiffuseLighting(preInfo{X}, diffuse{X}.rgb, light{X}.vLightGround);
116
#elif defined(AREALIGHT{X})

packages/dev/core/src/Shaders/ShadersInclude/openpbrDirectLightingInit.fx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifdef LIGHT{X}
22
preLightingInfo preInfo{X};
3-
lightingInfo info{X};
3+
openpbrLightingInfo info{X};
44
float shadow{X} = 1.;
55
#if defined(SHADOWONLY) || defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X}) && defined(LIGHTMAPNOSPECULAR{X})
66
//No light calculation

packages/dev/core/src/Shaders/ShadersInclude/openpbrFragmentDeclaration.fx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
uniform vec4 vEyePosition;
22

3-
uniform vec3 vReflectionColor;
4-
uniform vec4 vBaseColor;
53
uniform float vBaseWeight;
4+
uniform vec4 vBaseColor;
65
uniform float vBaseDiffuseRoughness;
7-
uniform vec4 vCoatColor;
6+
uniform vec4 vReflectanceInfo;
7+
uniform vec4 vSpecularColor;
8+
uniform float vCoatWeight;
9+
uniform vec3 vCoatColor;
10+
uniform float vCoatRoughness;
11+
uniform float vCoatIor;
12+
uniform vec3 vEmissionColor;
813

914
// CUSTOM CONTROLS
1015
uniform vec4 vLightingIntensity;
11-
12-
uniform vec3 vEmissionColor;
13-
1416
uniform float visibility;
1517

1618
// Samplers
@@ -35,12 +37,16 @@ uniform vec2 vGeometryNormalInfos;
3537
uniform vec2 vTangentSpaceParams;
3638
#endif
3739

40+
#ifdef GEOMETRY_COAT_NORMAL
41+
uniform vec2 vGeometryCoatNormalInfos;
42+
#endif
43+
3844
#ifdef GEOMETRY_OPACITY
3945
uniform vec2 vGeometryOpacityInfos;
4046
#endif
4147

42-
#ifdef EMISSION
43-
uniform vec2 vEmissionInfos;
48+
#ifdef EMISSION_COLOR
49+
uniform vec2 vEmissionColorInfos;
4450
#endif
4551

4652
#ifdef METALLIC_ROUGHNESS

packages/dev/core/src/Shaders/ShadersInclude/openpbrFragmentSamplersDeclaration.fx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include<samplerFragmentDeclaration>(_DEFINENAME_,COAT_COLOR,_VARYINGNAME_,CoatColor,_SAMPLERNAME_,coatColor)
99
#include<samplerFragmentDeclaration>(_DEFINENAME_,COAT_ROUGHNESS,_VARYINGNAME_,CoatRoughness,_SAMPLERNAME_,coatRoughness)
1010
#include<samplerFragmentDeclaration>(_DEFINENAME_,GEOMETRY_OPACITY,_VARYINGNAME_,GeometryOpacity,_SAMPLERNAME_,geometryOpacity)
11-
#include<samplerFragmentDeclaration>(_DEFINENAME_,EMISSION,_VARYINGNAME_,Emission,_SAMPLERNAME_,emission)
11+
#include<samplerFragmentDeclaration>(_DEFINENAME_,EMISSION_COLOR,_VARYINGNAME_,EmissionColor,_SAMPLERNAME_,emissionColor)
1212

1313
#include<samplerFragmentDeclaration>(_DEFINENAME_,AMBIENT_OCCLUSION,_VARYINGNAME_,AmbientOcclusion,_SAMPLERNAME_,ambientOcclusion)
1414
#include<samplerFragmentDeclaration>(_DEFINENAME_,DECAL,_VARYINGNAME_,Decal,_SAMPLERNAME_,decal)

packages/dev/core/src/Shaders/ShadersInclude/openpbrGeometryInfo.fx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ geometryInfoOutParams geometryInfo(
2626
outParams.horizonOcclusion = 1.0;
2727
#if defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)
2828
#ifdef HORIZONOCCLUSION
29-
#ifdef GEOMETRY_NORMAL
29+
#if defined(GEOMETRY_NORMAL) || defined(GEOMETRY_COAT_NORMAL)
3030
#ifdef REFLECTIONMAP_3D
3131
outParams.horizonOcclusion = environmentHorizonOcclusion(-viewDirectionW, normalW, geometricNormalW);
3232
#endif

packages/dev/core/src/Shaders/ShadersInclude/openpbrNormalMapFragment.fx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
vec2 uvOffset = vec2(0.0, 0.0);
2-
32
#if defined(GEOMETRY_NORMAL) || defined(PARALLAX) || defined(DETAIL)
43
#ifdef NORMALXYSCALE
54
float normalScale = 1.0;
@@ -48,6 +47,10 @@
4847
vec3 detailNormal = vec3(detailNormalRG, detailNormalB);
4948
#endif
5049

50+
#ifdef GEOMETRY_COAT_NORMAL
51+
coatNormalW = perturbNormal(TBN, texture2D(geometryNormalSampler, vGeometryNormalUV + uvOffset).xyz, vGeometryNormalInfos.y);
52+
#endif
53+
5154
#ifdef GEOMETRY_NORMAL
5255
#ifdef OBJECTSPACE_NORMALMAP
5356

0 commit comments

Comments
 (0)