Browse Source

Fix of the morning

Sebastien Vandenberghe 8 years ago
parent
commit
b40ac2c412

+ 1 - 1
src/Materials/PBR/babylon.pbrBaseMaterial.ts

@@ -1145,7 +1145,7 @@
                         }
                         else {
                             if (!reflectionTexture._lodTextureMid) {
-                                refractionTexture._generateFixedLodSamplers();
+                                reflectionTexture._generateFixedLodSamplers();
                             }
 
                             this._uniformBuffer.setTexture("reflectionSampler", reflectionTexture._lodTextureMid || reflectionTexture);

+ 8 - 0
src/Materials/PBR/babylon.pbrMaterial.ts

@@ -376,6 +376,14 @@
         public useAlphaFresnel = false;
 
         /**
+         * A fresnel is applied to the alpha of the model to ensure grazing angles edges are not alpha tested.
+         * And/Or occlude the blended part.
+         */
+        @serializeAsTexture()
+        @expandToProperty("_markAllSubMeshesAsTexturesDirty")
+        public environmentBRDFTexture: BaseTexture = null;
+
+        /**
          * Gets the image processing configuration used either in this material.
          */
         public get imageProcessingConfiguration(): ImageProcessingConfiguration {

+ 1 - 1
src/Shaders/ShadersInclude/pbrFunctions.fx

@@ -110,7 +110,7 @@ float fresnelGrazingReflectance(float reflectance0) {
 
 // To enable 8 bit textures to be used we need to pack and unpack the LOD
 // Inverse alpha is used to work around low-alpha bugs in Edge and Firefox
-#define UNPACK_LOD(x) (1.0 - x) * 255.0
+#define UNPACK_LOD(x) (x)
 
 float getLodFromAlphaG(float cubeMapDimensionPixels, float alphaG, float NdotV) {
     float microsurfaceAverageSlope = alphaG;

+ 21 - 21
src/Shaders/pbr.fragment.fx

@@ -74,24 +74,24 @@ uniform sampler2D microSurfaceSampler;
 // Refraction
 #ifdef REFRACTION
 	#ifdef REFRACTIONMAP_3D
-		#define sampleRefraction textureCube
+		#define sampleRefraction(s, c) textureCube(s, c)
 		
 		uniform samplerCube refractionSampler;
 
-		#ifndef LODBASEDMICROSFURACE
-			#define sampleRefractionLod textureCubeLodEXT
-
+		#ifdef LODBASEDMICROSFURACE
+			#define sampleRefractionLod(s, c, l) textureCubeLodEXT(s, c, l)
+		#else
 			uniform samplerCube refractionSamplerLow;
 			uniform samplerCube refractionSamplerHigh;
 		#endif		
 	#else
-		#define sampleRefraction texture2D
+		#define sampleRefraction(s, c) texture2D(s, c)
 		
 		uniform sampler2D refractionSampler;
 
-		#ifndef LODBASEDMICROSFURACE
-			#define sampleRefractionLod texture2DLodEXT
-
+		#ifdef LODBASEDMICROSFURACE
+			#define sampleRefractionLod(s, c, l) texture2DLodEXT(s, c, l)
+		#else
 			uniform samplerCube refractionSamplerLow;
 			uniform samplerCube refractionSamplerHigh;
 		#endif
@@ -101,24 +101,24 @@ uniform sampler2D microSurfaceSampler;
 // Reflection
 #ifdef REFLECTION
 	#ifdef REFLECTIONMAP_3D
-		#define sampleReflection textureCube
+		#define sampleReflection(s, c) textureCube(s, c)
 
 		uniform samplerCube reflectionSampler;
 		
-		#ifndef LODBASEDMICROSFURACE
-			#define sampleReflectionLod textureCubeLodEXT
-
+		#ifdef LODBASEDMICROSFURACE
+			#define sampleReflectionLod(s, c, l) textureCubeLodEXT(s, c, l)
+		#else
 			uniform samplerCube reflectionSamplerLow;
 			uniform samplerCube reflectionSamplerHigh;
 		#endif
 	#else
-		#define sampleReflection texture2D
+		#define sampleReflection(s, c) texture2D(s, c)
 
 		uniform sampler2D reflectionSampler;
 
-		#ifndef LODBASEDMICROSFURACE
-			#define sampleReflectionLod texture2DLodEXT
-
+		#ifdef LODBASEDMICROSFURACE
+			#define sampleReflectionLod(s, c, l) texture2DLodEXT(s, c, l)
+		#else
 			uniform samplerCube reflectionSamplerLow;
 			uniform samplerCube reflectionSamplerHigh;
 		#endif
@@ -504,8 +504,8 @@ void main(void) {
 	#endif
 
 	// _____________________________ Levels _____________________________________
-	environmentRadiance *= vReflectionColor.rgb * vReflectionInfos.x;
-	environmentIrradiance *= vReflectionColor.rgb;
+	environmentRadiance *= vReflectionInfos.x;
+	//environmentIrradiance *= vReflectionColor.rgb;
 #endif
 
 // ____________________________________________________________________________________
@@ -546,13 +546,13 @@ void main(void) {
 		float ambientMonochrome = getLuminance(ambientOcclusionColor);
 	#endif
 
-	vec3 seo = environmentRadianceOcclusion(ambientMonochrome, NdotVUnclamped);
+	float seo = environmentRadianceOcclusion(ambientMonochrome, NdotVUnclamped);
 	specularEnvironmentReflectance *= seo;
 
 	#ifdef BUMP
 		#ifdef REFLECTIONMAP_3D
-			vec3 hoo = environmentHorizonOcclusion(reflectionCoords, normalW);
-			specularEnvironmentReflectance *= hoo;
+			float eho = environmentHorizonOcclusion(reflectionCoords, normalW);
+			specularEnvironmentReflectance *= eho;
 		#endif
 	#endif
 #else