Browse Source

Add explicit variable for volume IOR

Michael Bond 5 năm trước cách đây
mục cha
commit
37037f1567

+ 1 - 1
loaders/src/glTF/2.0/Extensions/KHR_materials_transmission.ts

@@ -71,7 +71,7 @@ export class KHR_materials_transmission implements IGLTFLoaderExtension {
         pbrMaterial.subSurface.isRefractionEnabled = true;
 
         // Since this extension models thin-surface transmission only, we must make IOR = 1.0
-        pbrMaterial.subSurface.indexOfRefraction = 1.0;
+        pbrMaterial.subSurface.volumeIndexOfRefraction = 1.0;
 
         // Albedo colour will tint transmission.
         pbrMaterial.subSurface.useAlbedoToTintRefraction = true;

+ 28 - 2
src/Materials/PBR/pbrSubSurfaceConfiguration.ts

@@ -134,6 +134,32 @@ export class PBRSubSurfaceConfiguration {
     @expandToProperty("_markAllSubMeshesAsTexturesDirty")
     public indexOfRefraction = 1.5;
 
+    
+    private _volumeIndexOfRefraction = -1.0;
+    
+    /**
+     * Index of refraction of the material's volume.
+     * https://en.wikipedia.org/wiki/List_of_refractive_indices
+     *
+     * This ONLY impacts refraction. If not provided or given a non-valid value,
+     * the volume will use the same IOR as the surface.
+     */
+    @serialize()
+    @expandToProperty("_markAllSubMeshesAsTexturesDirty")
+    public get volumeIndexOfRefraction(): number {
+        if (this._volumeIndexOfRefraction >= 1.0) {
+            return this._volumeIndexOfRefraction;
+        }
+        return this._indexOfRefraction;
+    }
+    public set volumeIndexOfRefraction(value: number) {
+        if (value >= 1.0) {
+            this._volumeIndexOfRefraction = value;
+        } else {
+            this._volumeIndexOfRefraction = -1.0;
+        }
+    }
+
     private _invertRefractionY = false;
     /**
      * Controls if refraction needs to be inverted on Y. This could be useful for procedural texture.
@@ -326,8 +352,8 @@ export class PBRSubSurfaceConfiguration {
                 }
 
                 var width = refractionTexture.getSize().width;
-
-                uniformBuffer.updateFloat4("vRefractionInfos", refractionTexture.level, 1 / this._indexOfRefraction, depth, this._invertRefractionY ? -1 : 1);
+                var refractionIor = this.volumeIndexOfRefraction;
+                uniformBuffer.updateFloat4("vRefractionInfos", refractionTexture.level, 1 / refractionIor, depth, this._invertRefractionY ? -1 : 1);
                 uniformBuffer.updateFloat3("vRefractionMicrosurfaceInfos",
                     width,
                     refractionTexture.lodGenerationScale,