Browse Source

Merge pull request #2005 from sebavan/Development

Fetch ambient in grayscale support
David Catuhe 8 years ago
parent
commit
2b47f70653
2 changed files with 11 additions and 0 deletions
  1. 8 0
      src/Materials/babylon.pbrMaterial.ts
  2. 3 0
      src/Shaders/pbr.fragment.fx

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

@@ -2,6 +2,7 @@
     class PBRMaterialDefines extends MaterialDefines {
         public ALBEDO = false;
         public AMBIENT = false;
+        public AMBIENTINGRAYSCALE = false;
         public OPACITY = false;
         public OPACITYRGB = false;
         public REFLECTION = false;
@@ -443,6 +444,12 @@
          */
         @serialize()
         public useAmbientOcclusionFromMetallicTextureRed = false;
+
+        /**
+         * Specifies if the ambient texture contains the ambient occlusion information in its red channel only.
+         */
+        @serialize()
+        public useAmbientInGrayScale = false;
         
         /**
          * In case the reflectivity map does not contain the microsurface information in its alpha channel,
@@ -701,6 +708,7 @@
                     
                     needUVs = true;
                     this._defines.AMBIENT = true;
+                    this._defines.AMBIENTINGRAYSCALE = this.useAmbientInGrayScale;
                 }
 
                 if (this.opacityTexture && StandardMaterial.OpacityTextureEnabled) {

+ 3 - 0
src/Shaders/pbr.fragment.fx

@@ -245,6 +245,9 @@ void main(void) {
 
 #ifdef AMBIENT
 	vec3 ambientOcclusionColorMap = texture2D(ambientSampler, vAmbientUV + uvOffset).rgb * vAmbientInfos.y;
+	#ifdef AMBIENTINGRAYSCALE			
+		ambientOcclusionColorMap = vec3(ambientOcclusionColorMap.r, ambientOcclusionColorMap.r, ambientOcclusionColorMap.r);
+	#endif
 	ambientOcclusionColor = mix(ambientOcclusionColor, ambientOcclusionColorMap, vAmbientInfos.z);
 
 	#ifdef OVERLOADEDVALUES