소스 검색

Merge pull request #1003 from sebavan/PMREMEdgeFix

Edge Fix for PMREM
David Catuhe 9 년 전
부모
커밋
daa2f80582

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 2 - 2
materialsLibrary/dist/babylon.pbrMaterial.js


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 2 - 2
materialsLibrary/dist/babylon.pbrMaterial.min.js


+ 1 - 1
materialsLibrary/materials/pbr/babylon.pbrMaterial.ts

@@ -1024,7 +1024,7 @@ module BABYLON {
                         this._effect.setFloat4("vRefractionInfos", this.refractionTexture.level, this.indexOfRefraction, depth, this.invertRefractionY ? -1 : 1);
                     }
                     
-                    if ((this.reflectionTexture || this.refractionTexture) && this._myScene.getEngine().getCaps().textureLOD) {
+                    if ((this.reflectionTexture || this.refractionTexture)) {
                         this._effect.setFloat2("vMicrosurfaceTextureLods", this._microsurfaceTextureLods.x, this._microsurfaceTextureLods.y);
                     }
                 }

+ 10 - 9
materialsLibrary/materials/pbr/pbr.fragment.fx

@@ -72,7 +72,7 @@ uniform vec4 vCameraInfos;
     }
 #endif
 
-#ifdef LODBASEDMICROSFURACE
+#if defined(REFLECTION) || defined(REFRACTION)
     uniform vec2 vMicrosurfaceTextureLods;
 #endif
 
@@ -1078,13 +1078,10 @@ vec3 surfaceRefractionColor = vec3(0., 0., 0.);
 // Go mat -> blurry reflexion according to microSurface
 #ifdef LODBASEDMICROSFURACE
     float alphaG = convertRoughnessToAverageSlope(roughness);
-#else
-    float bias = 20. * (1.0 - microSurface);
 #endif
         
 #ifdef REFRACTION
-	//vec3 refractionVector = normalize(refract(-viewDirectionW, normalW, vRefractionInfos.y));
-    vec3 refractionVector = refract(-viewDirectionW, normalW, vRefractionInfos.y);
+	vec3 refractionVector = refract(-viewDirectionW, normalW, vRefractionInfos.y);
     
     #ifdef LODBASEDMICROSFURACE
         #ifdef USEPMREMREFRACTION
@@ -1092,6 +1089,8 @@ vec3 surfaceRefractionColor = vec3(0., 0., 0.);
         #else
             float lodRefraction = getMipMapIndexFromAverageSlope(vMicrosurfaceTextureLods.y, alphaG);
         #endif
+    #else
+        float biasRefraction = (vMicrosurfaceTextureLods.y + 2.) * (1.0 - microSurface);
     #endif
     
     #ifdef REFRACTIONMAP_3D
@@ -1115,7 +1114,7 @@ vec3 surfaceRefractionColor = vec3(0., 0., 0.);
                 
                 surfaceRefractionColor = textureCubeLodEXT(refractionCubeSampler, refractionVector, lodRefraction).rgb * vRefractionInfos.x;
             #else
-                surfaceRefractionColor = textureCube(refractionCubeSampler, refractionVector, bias).rgb * vRefractionInfos.x;
+                surfaceRefractionColor = textureCube(refractionCubeSampler, refractionVector, biasRefraction).rgb * vRefractionInfos.x;
             #endif
         }
         
@@ -1132,7 +1131,7 @@ vec3 surfaceRefractionColor = vec3(0., 0., 0.);
         #ifdef LODBASEDMICROSFURACE
             surfaceRefractionColor = texture2DLodEXT(refraction2DSampler, refractionCoords, lodRefraction).rgb * vRefractionInfos.x;
         #else
-            surfaceRefractionColor = texture2D(refraction2DSampler, refractionCoords, bias).rgb * vRefractionInfos.x;
+            surfaceRefractionColor = texture2D(refraction2DSampler, refractionCoords, biasRefraction).rgb * vRefractionInfos.x;
         #endif    
         
         surfaceRefractionColor = toLinearSpace(surfaceRefractionColor.rgb); 
@@ -1152,6 +1151,8 @@ vec3 environmentIrradiance = vReflectionColor.rgb;
         #else
             float lodReflection = getMipMapIndexFromAverageSlope(vMicrosurfaceTextureLods.x, alphaG);
         #endif
+    #else
+        float biasReflection = (vMicrosurfaceTextureLods.x + 2.) * (1.0 - microSurface);
     #endif
     
     #ifdef REFLECTIONMAP_3D
@@ -1172,7 +1173,7 @@ vec3 environmentIrradiance = vReflectionColor.rgb;
                 
             environmentRadiance = textureCubeLodEXT(reflectionCubeSampler, vReflectionUVW, lodReflection).rgb * vReflectionInfos.x;
         #else
-            environmentRadiance = textureCube(reflectionCubeSampler, vReflectionUVW, bias).rgb * vReflectionInfos.x;
+            environmentRadiance = textureCube(reflectionCubeSampler, vReflectionUVW, biasReflection).rgb * vReflectionInfos.x;
         #endif
         
         #ifdef PoissonSamplingEnvironment
@@ -1202,7 +1203,7 @@ vec3 environmentIrradiance = vReflectionColor.rgb;
         #ifdef LODBASEDMICROSFURACE
             environmentRadiance = texture2DLodEXT(reflection2DSampler, coords, lodReflection).rgb * vReflectionInfos.x;
         #else
-            environmentRadiance = texture2D(reflection2DSampler, coords, bias).rgb * vReflectionInfos.x;
+            environmentRadiance = texture2D(reflection2DSampler, coords, biasReflection).rgb * vReflectionInfos.x;
         #endif
     
         environmentRadiance = toLinearSpace(environmentRadiance.rgb);

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 4860 - 4817
materialsLibrary/test/refs/babylon.max.js


+ 3 - 3
src/Materials/Textures/babylon.hdrcubetexture.ts

@@ -33,9 +33,9 @@ module BABYLON {
             this.hasAlpha = false;
             this._size = size;
             this._useInGammaSpace = useInGammaSpace;
-            this._usePMREMGenerator = usePMREMGenerator;
-            this.isPMREM = usePMREMGenerator;
-
+            this._usePMREMGenerator = usePMREMGenerator && scene.getEngine().getCaps().textureLOD;
+            this.isPMREM = this._usePMREMGenerator;
+            
             if (!url) {
                 return;
             }