Преглед на файлове

Add pbr option for horizon and radiance occlusion

Sebastien Vandenberghe преди 7 години
родител
ревизия
83aae8b770

Файловите разлики са ограничени, защото са твърде много
+ 5440 - 5420
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


Файловите разлики са ограничени, защото са твърде много
+ 27 - 27
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js


Файловите разлики са ограничени, защото са твърде много
+ 36 - 4
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js


+ 18 - 0
src/Materials/PBR/babylon.pbrBaseMaterial.ts

@@ -78,6 +78,8 @@
         public REFLECTIONMAP_OPPOSITEZ = false;
         public LODINREFLECTIONALPHA = false;
         public GAMMAREFLECTION = false;
+        public RADIANCEOCCLUSION = false;
+        public HORIZONOCCLUSION = false;
 
         public REFRACTION = false;
         public REFRACTIONMAP_3D = false;
@@ -267,6 +269,18 @@
         protected _linkRefractionWithTransparency = false;
 
         protected _useLightmapAsShadowmap = false;
+
+        /**
+         * This parameters will enable/disable Horizon occlusion to prevent normal maps to look shiny when the normal
+         * makes the reflect vector face the model (under horizon).
+         */
+        protected _useHorizonOcclusion = false; // USEHORIZONOCCLUSION
+
+        /**
+         * This parameters will enable/disable radiance occlusion by preventing the radiance to lit
+         * too much the area relying on ambient texture to define their ambient occlusion.
+         */
+        protected _useRadianceOcclusion = false;
         
         /**
          * Specifies that the alpha is coming form the albedo channel alpha channel for alpha blending.
@@ -869,6 +883,10 @@
             }
 
             defines.FORCENORMALFORWARD = this._forceNormalForward;
+            
+            defines.RADIANCEOCCLUSION = this._useRadianceOcclusion;
+            
+            defines.HORIZONOCCLUSION = this._useHorizonOcclusion;
 
             // Misc.
             MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);

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

@@ -405,6 +405,22 @@
         public forceNormalForward = false;
 
         /**
+         * This parameters will enable/disable Horizon occlusion to prevent normal maps to look shiny when the normal
+         * makes the reflect vector face the model (under horizon).
+         */
+        @serialize()
+        @expandToProperty("_markAllSubMeshesAsTexturesDirty")
+        public useHorizonOcclusion = false;
+        
+        /**
+         * This parameters will enable/disable radiance occlusion by preventing the radiance to lit
+         * too much the area relying on ambient texture to define their ambient occlusion.
+         */
+        @serialize()
+        @expandToProperty("_markAllSubMeshesAsTexturesDirty")
+        public useRadianceOcclusion = false;
+
+        /**
          * Gets the image processing configuration used either in this material.
          */
         public get imageProcessingConfiguration(): ImageProcessingConfiguration {

+ 15 - 11
src/Shaders/pbr.fragment.fx

@@ -616,19 +616,23 @@ void main(void) {
 
 	vec3 specularEnvironmentReflectance = specularEnvironmentR0 * environmentBrdf.x + environmentBrdf.y;
 
-	#ifdef AMBIENTINGRAYSCALE
-		float ambientMonochrome = ambientOcclusionColor.r;
-	#else
-		float ambientMonochrome = getLuminance(ambientOcclusionColor);
-	#endif
+	#ifdef RADIANCEOCCLUSION
+		#ifdef AMBIENTINGRAYSCALE
+			float ambientMonochrome = ambientOcclusionColor.r;
+		#else
+			float ambientMonochrome = getLuminance(ambientOcclusionColor);
+		#endif
 
-	float seo = environmentRadianceOcclusion(ambientMonochrome, NdotVUnclamped);
-	specularEnvironmentReflectance *= seo;
+		float seo = environmentRadianceOcclusion(ambientMonochrome, NdotVUnclamped);
+		specularEnvironmentReflectance *= seo;
+	#endif
 
-	#ifdef BUMP
-		#ifdef REFLECTIONMAP_3D
-			float eho = environmentHorizonOcclusion(reflectionCoords, normalW);
-			specularEnvironmentReflectance *= eho;
+	#ifdef HORIZONOCCLUSION
+		#ifdef BUMP
+			#ifdef REFLECTIONMAP_3D
+				float eho = environmentHorizonOcclusion(reflectionCoords, normalW);
+				specularEnvironmentReflectance *= eho;
+			#endif
 		#endif
 	#endif
 #else