소스 검색

Update Sheen to latest GLTF spec (#8393)

sebavan 5 년 전
부모
커밋
8582bb4d71
3개의 변경된 파일23개의 추가작업 그리고 18개의 파일을 삭제
  1. 12 16
      loaders/src/glTF/2.0/Extensions/KHR_materials_sheen.ts
  2. 1 1
      src/Materials/PBR/pbrSheenConfiguration.ts
  3. 10 1
      src/Shaders/ShadersInclude/pbrBlockSheen.fx

+ 12 - 16
loaders/src/glTF/2.0/Extensions/KHR_materials_sheen.ts

@@ -10,10 +10,9 @@ import { Color3 } from 'babylonjs/Maths/math.color';
 const NAME = "KHR_materials_sheen";
 const NAME = "KHR_materials_sheen";
 
 
 interface IKHR_materials_sheen {
 interface IKHR_materials_sheen {
-    intensityFactor: number;
-    colorFactor: number[];
-    colorIntensityTexture: ITextureInfo;
-    roughnessFactor: number;
+    sheenColorFactor: number[];
+    sheenTexture: ITextureInfo;
+    sheenRoughnessFactor: number;
 }
 }
 
 
 /**
 /**
@@ -68,27 +67,24 @@ export class KHR_materials_sheen implements IGLTFLoaderExtension {
         const promises = new Array<Promise<any>>();
         const promises = new Array<Promise<any>>();
 
 
         babylonMaterial.sheen.isEnabled = true;
         babylonMaterial.sheen.isEnabled = true;
+        babylonMaterial.sheen.intensity = 1;
 
 
-        if (properties.intensityFactor != undefined) {
-            babylonMaterial.sheen.intensity = properties.intensityFactor;
+        if (properties.sheenColorFactor != undefined) {
+            babylonMaterial.sheen.color = Color3.FromArray(properties.sheenColorFactor);
         }
         }
         else {
         else {
-            babylonMaterial.sheen.intensity = 0;
+            babylonMaterial.sheen.color = Color3.Black();
         }
         }
 
 
-        if (properties.colorFactor != undefined) {
-            babylonMaterial.sheen.color = Color3.FromArray(properties.colorFactor);
-        }
-
-        if (properties.colorIntensityTexture) {
-            promises.push(this._loader.loadTextureInfoAsync(`${context}/sheenTexture`, properties.colorIntensityTexture, (texture) => {
-                texture.name = `${babylonMaterial.name} (Sheen Intensity)`;
+        if (properties.sheenTexture) {
+            promises.push(this._loader.loadTextureInfoAsync(`${context}/sheenTexture`, properties.sheenTexture, (texture) => {
+                texture.name = `${babylonMaterial.name} (Sheen Color)`;
                 babylonMaterial.sheen.texture = texture;
                 babylonMaterial.sheen.texture = texture;
             }));
             }));
         }
         }
 
 
-        if (properties.roughnessFactor !== undefined) {
-            babylonMaterial.sheen.roughness = properties.roughnessFactor;
+        if (properties.sheenRoughnessFactor !== undefined) {
+            babylonMaterial.sheen.roughness = properties.sheenRoughnessFactor;
         } else {
         } else {
             babylonMaterial.sheen.roughness = 0;
             babylonMaterial.sheen.roughness = 0;
         }
         }

+ 1 - 1
src/Materials/PBR/pbrSheenConfiguration.ts

@@ -61,7 +61,7 @@ export class PBRSheenConfiguration {
     /**
     /**
      * Stores the sheen tint values in a texture.
      * Stores the sheen tint values in a texture.
      * rgb is tint
      * rgb is tint
-     * a is a intensity
+     * a is a intensity or roughness if roughness has been defined
      */
      */
     @serializeAsTexture()
     @serializeAsTexture()
     @expandToProperty("_markAllSubMeshesAsTexturesDirty")
     @expandToProperty("_markAllSubMeshesAsTexturesDirty")

+ 10 - 1
src/Shaders/ShadersInclude/pbrBlockSheen.fx

@@ -75,7 +75,6 @@
         float sheenIntensity = vSheenColor.a;
         float sheenIntensity = vSheenColor.a;
 
 
         #ifdef SHEEN_TEXTURE
         #ifdef SHEEN_TEXTURE
-            sheenIntensity *= sheenMapData.a;
             #if DEBUGMODE > 0
             #if DEBUGMODE > 0
                 outParams.sheenMapData = sheenMapData;
                 outParams.sheenMapData = sheenMapData;
             #endif
             #endif
@@ -86,6 +85,10 @@
             vec3 sheenColor = baseColor.rgb*(1.0-sheenFactor);
             vec3 sheenColor = baseColor.rgb*(1.0-sheenFactor);
             float sheenRoughness = sheenIntensity;
             float sheenRoughness = sheenIntensity;
             outParams.surfaceAlbedo = surfaceAlbedo * sheenFactor;
             outParams.surfaceAlbedo = surfaceAlbedo * sheenFactor;
+
+            #ifdef SHEEN_TEXTURE
+                sheenIntensity *= sheenMapData.a;
+            #endif
         #else
         #else
             vec3 sheenColor = vSheenColor.rgb;
             vec3 sheenColor = vSheenColor.rgb;
             #ifdef SHEEN_TEXTURE
             #ifdef SHEEN_TEXTURE
@@ -94,8 +97,14 @@
             
             
             #ifdef SHEEN_ROUGHNESS
             #ifdef SHEEN_ROUGHNESS
                 float sheenRoughness = vSheenRoughness;
                 float sheenRoughness = vSheenRoughness;
+                #ifdef SHEEN_TEXTURE
+                    sheenRoughness *= sheenMapData.a;
+                #endif
             #else
             #else
                 float sheenRoughness = roughness;
                 float sheenRoughness = roughness;
+                #ifdef SHEEN_TEXTURE
+                    sheenIntensity *= sheenMapData.a;
+                #endif
             #endif
             #endif
 
 
             // Sheen Lobe Layering.
             // Sheen Lobe Layering.