|
@@ -5,6 +5,11 @@ import { NodeMaterialWellKnownValues } from '../../nodeMaterialWellKnownValues';
|
|
|
import { NodeMaterialBlockTargets } from '../../nodeMaterialBlockTargets';
|
|
|
import { Mesh } from '../../../../Meshes/mesh';
|
|
|
import { Effect } from '../../../effect';
|
|
|
+import { NodeMaterialConnectionPoint } from '../../nodeMaterialBlockConnectionPoint';
|
|
|
+import { MaterialDefines } from '../../../materialDefines';
|
|
|
+import { AbstractMesh } from '../../../../Meshes/abstractMesh';
|
|
|
+import { MaterialHelper} from '../../../materialHelper';
|
|
|
+import { NodeMaterial} from '../../nodeMaterial';
|
|
|
|
|
|
/**
|
|
|
* Block used to add support for scene fog
|
|
@@ -24,9 +29,10 @@ export class FogBlock extends NodeMaterialBlock {
|
|
|
this.registerOutput("vFogDistance", NodeMaterialBlockConnectionPointTypes.Vector3, NodeMaterialBlockTargets.Vertex);
|
|
|
|
|
|
// Fragment
|
|
|
- this.registerInput("input", NodeMaterialBlockConnectionPointTypes.Color3OrColor4, false, NodeMaterialBlockTargets.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);
|
|
|
|
|
|
// Auto configuration
|
|
@@ -44,6 +50,18 @@ export class FogBlock extends NodeMaterialBlock {
|
|
|
return "FogBlock";
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Gets the color input component
|
|
|
+ */
|
|
|
+ public get color(): NodeMaterialConnectionPoint {
|
|
|
+ return this._inputs[2];
|
|
|
+ }
|
|
|
+
|
|
|
+ public prepareDefines(mesh: AbstractMesh, nodeMaterial: NodeMaterial, defines: MaterialDefines) {
|
|
|
+ let scene = mesh.getScene();
|
|
|
+ defines["FOG"] = nodeMaterial.fogEnabled && MaterialHelper.GetFogState(mesh, scene)
|
|
|
+ }
|
|
|
+
|
|
|
public bind(effect: Effect, mesh?: Mesh) {
|
|
|
if (!mesh) {
|
|
|
return;
|
|
@@ -54,31 +72,31 @@ export class FogBlock extends NodeMaterialBlock {
|
|
|
effect.setFloat4("fogParameters", scene.fogMode, scene.fogStart, scene.fogEnd, scene.fogDensity);
|
|
|
}
|
|
|
|
|
|
- /** @hidden */
|
|
|
- public get _canAddAtFragmentRoot(): boolean {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
protected _buildBlock(state: NodeMaterialBuildState) {
|
|
|
super._buildBlock(state);
|
|
|
|
|
|
+ state.sharedData.blocksWithDefines.push(this);
|
|
|
+
|
|
|
if (state.target === NodeMaterialBlockTargets.Fragment) {
|
|
|
state._emitFunctionFromInclude("CalcFogFactor", "fogFragmentDeclaration", {
|
|
|
removeUniforms: true,
|
|
|
removeVaryings: true,
|
|
|
- removeifDef: true,
|
|
|
+ removeifDef: false,
|
|
|
replaceStrings: [{ search: /float CalcFogFactor\(\)/, replace: "float CalcFogFactor(vec3 vFogDistance, vec4 vFogInfos)" }]
|
|
|
});
|
|
|
|
|
|
let tempFogVariablename = state._getFreeVariableName("fog");
|
|
|
- let input = this._inputs[2];
|
|
|
+ let color = this.color;
|
|
|
let fogColor = this._inputs[3];
|
|
|
let fogParameters = this._inputs[4];
|
|
|
let output = this._outputs[1];
|
|
|
let vFogDistance = this._outputs[0];
|
|
|
|
|
|
+ state.compilationString += `#ifdef FOG\r\n`;
|
|
|
state.compilationString += `float ${tempFogVariablename} = CalcFogFactor(${vFogDistance.associatedVariableName}, ${fogParameters.associatedVariableName});\r\n`;
|
|
|
- state.compilationString += this._declareOutput(output, state) + ` = ${tempFogVariablename} * ${input.associatedVariableName}.rgb + (1.0 - ${tempFogVariablename}) * ${fogColor.associatedVariableName};\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`;
|
|
|
} else {
|
|
|
let worldPos = this._inputs[0];
|
|
|
let view = this._inputs[1];
|