浏览代码

Merge pull request #5148 from sebavan/master

Fix Linear Fog
David Catuhe 7 年之前
父节点
当前提交
4608613e1e

+ 1 - 1
src/Materials/Background/babylon.backgroundMaterial.ts

@@ -1095,7 +1095,7 @@
                 this.bindView(effect);
 
                 // Fog
-                MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
+                MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect, true);
 
                 // image processing
                 if (this._imageProcessingConfiguration) {

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

@@ -1674,7 +1674,7 @@
                 }
 
                 // Fog
-                MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
+                MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect, true);
 
                 // Morph targets
                 if (defines.NUM_MORPH_INFLUENCERS) {

+ 11 - 2
src/Materials/babylon.materialHelper.ts

@@ -569,16 +569,25 @@ module BABYLON {
             }
         }
 
+        private static _tempFogColor = BABYLON.Color3.Black();
         /**
          * Binds the fog information from the scene to the effect for the given mesh.
          * @param scene The scene the lights belongs to
          * @param mesh The mesh we are binding the information to render 
          * @param effect The effect we are binding the data to
+         * @param linearSpace Defines if the fog effect is applied in linear space
          */
-        public static BindFogParameters(scene: Scene, mesh: AbstractMesh, effect: Effect): void {
+        public static BindFogParameters(scene: Scene, mesh: AbstractMesh, effect: Effect, linearSpace = false): void {
             if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
                 effect.setFloat4("vFogInfos", scene.fogMode, scene.fogStart, scene.fogEnd, scene.fogDensity);
-                effect.setColor3("vFogColor", scene.fogColor);
+                // Convert fog color to linear space if used in a linear space computed shader.
+                if (linearSpace) {
+                    scene.fogColor.toLinearSpaceToRef(this._tempFogColor);
+                    effect.setColor3("vFogColor", this._tempFogColor);
+                }
+                else {
+                    effect.setColor3("vFogColor", scene.fogColor);
+                }
             }
         }