فهرست منبع

Improved fog parameters

David Catuhe 6 سال پیش
والد
کامیت
2f68838bc0

+ 9 - 18
src/Materials/Node/Blocks/Dual/fogBlock.ts

@@ -16,6 +16,8 @@ import { InputBlock } from '../Input/inputBlock';
  */
 export class FogBlock extends NodeMaterialBlock {
     private _fogDistanceName: string;
+    private _fogParameters: string;
+
     /**
      * Create a new FogBlock
      * @param name defines the block name
@@ -30,7 +32,6 @@ export class FogBlock extends NodeMaterialBlock {
         // Fragment
         this.registerInput("color", NodeMaterialBlockConnectionPointTypes.Color3OrColor4, false, NodeMaterialBlockTargets.Fragment);
         this.registerInput("fogColor", NodeMaterialBlockConnectionPointTypes.Color3, false, NodeMaterialBlockTargets.Fragment);
-        this.registerInput("fogParameters", NodeMaterialBlockConnectionPointTypes.Vector4, false, NodeMaterialBlockTargets.Fragment);
 
         this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.Color3, NodeMaterialBlockTargets.Fragment);
     }
@@ -72,13 +73,6 @@ export class FogBlock extends NodeMaterialBlock {
     }
 
     /**
-     * Gets the for parameter input component
-     */
-    public get fogParameters(): NodeMaterialConnectionPoint {
-        return this._inputs[4];
-    }
-
-    /**
      * Gets the output component
      */
     public get output(): NodeMaterialConnectionPoint {
@@ -93,14 +87,9 @@ export class FogBlock extends NodeMaterialBlock {
         }
         if (!this.fogColor.isConnected) {
             let fogColorInput = new InputBlock("fogColor", undefined, NodeMaterialBlockConnectionPointTypes.Color3);
-            fogColorInput.setAsWellKnownValue(NodeMaterialWellKnownValues.Automatic);
+            fogColorInput.setAsWellKnownValue(NodeMaterialWellKnownValues.FogColor);
             fogColorInput.output.connectTo(this.fogColor);
         }
-        if (!this.fogParameters.isConnected) {
-            let fogParametersInput = new InputBlock("fogParameters", undefined, NodeMaterialBlockConnectionPointTypes.Vector4);
-            fogParametersInput.setAsWellKnownValue(NodeMaterialWellKnownValues.Automatic);
-            fogParametersInput.output.connectTo(this.fogParameters);
-        }
     }
 
     public prepareDefines(mesh: AbstractMesh, nodeMaterial: NodeMaterial, defines: NodeMaterialDefines) {
@@ -114,8 +103,7 @@ export class FogBlock extends NodeMaterialBlock {
         }
 
         const scene = mesh.getScene();
-        effect.setColor3("u_fogColor", scene.fogColor);
-        effect.setFloat4("u_fogParameters", scene.fogMode, scene.fogStart, scene.fogEnd, scene.fogDensity);
+        effect.setFloat4(this._fogParameters, scene.fogMode, scene.fogStart, scene.fogEnd, scene.fogDensity);
     }
 
     protected _buildBlock(state: NodeMaterialBuildState) {
@@ -136,11 +124,14 @@ export class FogBlock extends NodeMaterialBlock {
             let tempFogVariablename = state._getFreeVariableName("fog");
             let color = this.color;
             let fogColor = this.fogColor;
-            let fogParameters = this.fogParameters;
+            this._fogParameters = state._getFreeVariableName("fogParameters");
             let output = this._outputs[0];
 
+
+            state._emitUniformFromString(this._fogParameters, "vec4");
+
             state.compilationString += `#ifdef FOG\r\n`;
-            state.compilationString += `float ${tempFogVariablename} = CalcFogFactor(${this._fogDistanceName}, ${fogParameters.associatedVariableName});\r\n`;
+            state.compilationString += `float ${tempFogVariablename} = CalcFogFactor(${this._fogDistanceName}, ${this._fogParameters});\r\n`;
             state.compilationString += this._declareOutput(output, state) + ` = ${tempFogVariablename} * ${color.associatedVariableName}.rgb + (1.0 - ${tempFogVariablename}) * ${fogColor.associatedVariableName};\r\n`;
             state.compilationString += `#else\r\n${this._declareOutput(output, state)} =  ${color.associatedVariableName}.rgb;\r\n`;
             state.compilationString += `#endif\r\n`;

+ 3 - 0
src/Materials/Node/Blocks/Input/inputBlock.ts

@@ -347,6 +347,9 @@ export class InputBlock extends NodeMaterialBlock {
                 case NodeMaterialWellKnownValues.CameraPosition:
                     effect.setVector3(variableName, scene.activeCamera!.globalPosition);
                     break;
+                case NodeMaterialWellKnownValues.FogColor:
+                    effect.setColor3(variableName, scene.fogColor);
+                    break;
             }
             return;
         }

+ 2 - 2
src/Materials/Node/nodeMaterialWellKnownValues.ts

@@ -16,6 +16,6 @@ export enum NodeMaterialWellKnownValues {
     WorldViewProjection = 6,
     /** CameraPosition */
     CameraPosition = 7,
-    /** Will be filled by the block itself */
-    Automatic = 8
+    /** Fog Color */
+    FogColor = 8
 }