Sfoglia il codice sorgente

Merge pull request #4961 from sebavan/master

Add AO control over analytical lights
sebavan 7 anni fa
parent
commit
b7b6e0843b

+ 2 - 1
dist/preview release/what's new.md

@@ -49,7 +49,6 @@
 - All NPM packages have `latest`and `preview` streams [#3055](https://github.com/BabylonJS/Babylon.js/issues/3055) ([RaananW](https://github.com/RaananW))
 - Added New Tools Tab in the inspector (env texture and screenshot tools so far) ([sebavan](http://www.github.com/sebavan))
 - Moved to gulp 4, updated dependencies to latest ([RaananW](https://github.com/RaananW))
-- Added EdgesLineRenderer to address [#4919](https://github.com/BabylonJS/Babylon.js/pull/4919) ([barteq100](https://github.com/barteq100))
 
 ### GUI
 - Added dead key support and before key add observable to InputText. [Doc](https://doc.babylonjs.com/how_to/gui#using-onbeforekeyaddobservable-for-extended-keyboard-layouts-and-input-masks)([theom](https://github.com/theom))
@@ -104,6 +103,8 @@
 - Added Video Recorder [Issue 4708](https://github.com/BabylonJS/Babylon.js/issues/4708) ([sebavan](http://www.github.com/sebavan))
 - Added support for main WebGL2 texture formats ([PeapBoy](https://github.com/NicolasBuecher))
 - Added fadeInOutBehavior and tooltipText for holographic buttons ([TrevorDev](https://github.com/TrevorDev))
+- Added EdgesLineRenderer to address [#4919](https://github.com/BabylonJS/Babylon.js/pull/4919) ([barteq100](https://github.com/barteq100))
+- Added ```ambientTextureImpactOnAnalyticalLights``` in PBRMaterial to allow fine grained control of the AmbientTexture on the analytical diffuse light ([sebavan](http://www.github.com/sebavan))
 
 ### glTF Loader
 

+ 9 - 2
src/Materials/PBR/babylon.pbrBaseMaterial.ts

@@ -236,6 +236,13 @@
         protected _ambientTextureStrength: number = 1.0;
 
         /**
+         * Defines how much the AO map is occluding the analytical lights (point spot...).
+         * 1 means it completely occludes it 
+         * 0 mean it has no impact
+         */
+        protected _ambientTextureImpactOnAnalyticalLights: number = PBRMaterial.DEFAULT_AO_ON_ANALYTICAL_LIGHTS;
+
+        /**
          * Stores the alpha values in a texture.
          */
         protected _opacityTexture: BaseTexture;
@@ -1320,7 +1327,7 @@
         public buildUniformLayout(): void {
             // Order is important !
             this._uniformBuffer.addUniform("vAlbedoInfos", 2);
-            this._uniformBuffer.addUniform("vAmbientInfos", 3);
+            this._uniformBuffer.addUniform("vAmbientInfos", 4);
             this._uniformBuffer.addUniform("vOpacityInfos", 2);
             this._uniformBuffer.addUniform("vEmissiveInfos", 2);
             this._uniformBuffer.addUniform("vLightmapInfos", 2);
@@ -1426,7 +1433,7 @@
                         }
 
                         if (this._ambientTexture && StandardMaterial.AmbientTextureEnabled) {
-                            this._uniformBuffer.updateFloat3("vAmbientInfos", this._ambientTexture.coordinatesIndex, this._ambientTexture.level, this._ambientTextureStrength);
+                            this._uniformBuffer.updateFloat4("vAmbientInfos", this._ambientTexture.coordinatesIndex, this._ambientTexture.level, this._ambientTextureStrength, this._ambientTextureImpactOnAnalyticalLights);
                             MaterialHelper.BindTextureMatrix(this._ambientTexture, this._uniformBuffer, "ambient");
                         }
 

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

@@ -29,6 +29,12 @@
         public static readonly PBRMATERIAL_ALPHATESTANDBLEND = 3;
 
         /**
+         * Defines the default value of how much AO map is occluding the analytical lights
+         * (point spot...).
+         */
+        public static DEFAULT_AO_ON_ANALYTICAL_LIGHTS = 1;
+
+        /**
          * Intensity of the direct lights e.g. the four lights available in your scene.
          * This impacts both the direct diffuse and specular highlights.
          */
@@ -89,6 +95,15 @@
         public ambientTextureStrength: number = 1.0;
 
         /**
+         * Defines how much the AO map is occluding the analytical lights (point spot...).
+         * 1 means it completely occludes it 
+         * 0 mean it has no impact
+         */
+        @serialize()
+        @expandToProperty("_markAllSubMeshesAsTexturesDirty")
+        public ambientTextureImpactOnAnalyticalLights: number = PBRMaterial.DEFAULT_AO_ON_ANALYTICAL_LIGHTS;
+
+        /**
          * Stores the alpha values in a texture.
          */
         @serializeAsTexture()

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

@@ -13,7 +13,7 @@ uniform vec2 vAlbedoInfos;
 #endif
 
 #ifdef AMBIENT
-uniform vec3 vAmbientInfos;
+uniform vec4 vAmbientInfos;
 #endif
 
 #ifdef BUMP

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

@@ -3,7 +3,7 @@ layout(std140, column_major) uniform;
 uniform Material
 {
 	uniform vec2 vAlbedoInfos;
-	uniform vec3 vAmbientInfos;
+	uniform vec4 vAmbientInfos;
 	uniform vec2 vOpacityInfos;
 	uniform vec2 vEmissiveInfos;
 	uniform vec2 vLightmapInfos;

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

@@ -8,7 +8,7 @@ uniform vec2 vAlbedoInfos;
 
 #ifdef AMBIENT
 uniform mat4 ambientMatrix;
-uniform vec3 vAmbientInfos;
+uniform vec4 vAmbientInfos;
 #endif
 
 #ifdef OPACITY

+ 8 - 1
src/Shaders/pbr.fragment.fx

@@ -788,11 +788,18 @@ void main(void) {
     finalEmissive *=  vEmissiveInfos.y;
 #endif
 
+// ______________________________ Ambient ________________________________________
+#ifdef AMBIENT
+    vec3 ambientOcclusionForDirectDiffuse = mix(vec3(1.), ambientOcclusionColor, vAmbientInfos.w);
+#else
+    vec3 ambientOcclusionForDirectDiffuse = ambientOcclusionColor;
+#endif
+
 // _______________________________________________________________________________
 // _____________________________ Composition _____________________________________
     // Reflection already includes the environment intensity.
     vec4 finalColor = vec4(
-        finalDiffuse			* ambientOcclusionColor * vLightingIntensity.x +
+        finalDiffuse			* ambientOcclusionForDirectDiffuse * vLightingIntensity.x +
 #ifndef UNLIT
     #ifdef REFLECTION
         finalIrradiance			* ambientOcclusionColor * vLightingIntensity.z +