|
@@ -1,33 +1,9 @@
|
|
import { NodeMaterialConnectionPoint } from './nodeMaterialBlockConnectionPoint';
|
|
import { NodeMaterialConnectionPoint } from './nodeMaterialBlockConnectionPoint';
|
|
import { NodeMaterialBlockConnectionPointTypes } from './nodeMaterialBlockConnectionPointTypes';
|
|
import { NodeMaterialBlockConnectionPointTypes } from './nodeMaterialBlockConnectionPointTypes';
|
|
import { NodeMaterialWellKnownValues } from './nodeMaterialWellKnownValues';
|
|
import { NodeMaterialWellKnownValues } from './nodeMaterialWellKnownValues';
|
|
-import { NodeMaterialBlockTargets } from './nodeMaterialBlock';
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * Class used to store shared data between 2 NodeMaterialCompilationState
|
|
|
|
- */
|
|
|
|
-export class NodeMaterialCompilationStateSharedData {
|
|
|
|
- /**
|
|
|
|
- * Gets the list of emitted varyings
|
|
|
|
- */
|
|
|
|
- public varyings = new Array<string>();
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Gets the varying declaration string
|
|
|
|
- */
|
|
|
|
- public varyingDeclaration = "";
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Build Id used to avoid multiple recompilations
|
|
|
|
- */
|
|
|
|
- public buildId: number;
|
|
|
|
-
|
|
|
|
- /** List of emitted variables */
|
|
|
|
- public variableNames: { [key: string]: number } = {};
|
|
|
|
-
|
|
|
|
- /** Should emit comments? */
|
|
|
|
- public emitComments: boolean;
|
|
|
|
-}
|
|
|
|
|
|
+import { NodeMaterialBlockTargets } from './nodeMaterialBlockTargets';
|
|
|
|
+import { NodeMaterialCompilationStateSharedData } from './nodeMaterialCompilationStateSharedData';
|
|
|
|
+import { Effect } from '../../Materials/effect';
|
|
|
|
|
|
/**
|
|
/**
|
|
* Class used to store node based material compilation state
|
|
* Class used to store node based material compilation state
|
|
@@ -65,20 +41,6 @@ export class NodeMaterialCompilationState {
|
|
/** @hidden */
|
|
/** @hidden */
|
|
public _vertexState: NodeMaterialCompilationState;
|
|
public _vertexState: NodeMaterialCompilationState;
|
|
|
|
|
|
- /**
|
|
|
|
- * Gets the compilation hints emitted at compilation time
|
|
|
|
- */
|
|
|
|
- public hints = {
|
|
|
|
- needWorldMatrix: false,
|
|
|
|
- needViewMatrix: false,
|
|
|
|
- needProjectionMatrix: false,
|
|
|
|
- needViewProjectionMatrix: false,
|
|
|
|
- needWorldViewMatrix: false,
|
|
|
|
- needWorldViewProjectionMatrix: false,
|
|
|
|
- needFogColor: false,
|
|
|
|
- needFogParameters: false
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
private _attributeDeclaration = "";
|
|
private _attributeDeclaration = "";
|
|
private _uniformDeclaration = "";
|
|
private _uniformDeclaration = "";
|
|
private _samplerDeclaration = "";
|
|
private _samplerDeclaration = "";
|
|
@@ -111,19 +73,19 @@ export class NodeMaterialCompilationState {
|
|
this.compilationString = `${this.compilationString}\r\n}`;
|
|
this.compilationString = `${this.compilationString}\r\n}`;
|
|
|
|
|
|
if (this.sharedData.varyingDeclaration) {
|
|
if (this.sharedData.varyingDeclaration) {
|
|
- this.compilationString = `\r\n${emitComments ? "//Varyings\r\n" : ""}${this.sharedData.varyingDeclaration}\r\n\r\n${this.compilationString}`;
|
|
|
|
|
|
+ this.compilationString = `\r\n${emitComments ? "//Varyings\r\n" : ""}${this.sharedData.varyingDeclaration}\r\n${this.compilationString}`;
|
|
}
|
|
}
|
|
|
|
|
|
if (this._samplerDeclaration) {
|
|
if (this._samplerDeclaration) {
|
|
- this.compilationString = `\r\n${emitComments ? "//Samplers\r\n" : ""}${this._samplerDeclaration}\r\n\r\n${this.compilationString}`;
|
|
|
|
|
|
+ this.compilationString = `\r\n${emitComments ? "//Samplers\r\n" : ""}${this._samplerDeclaration}\r\n${this.compilationString}`;
|
|
}
|
|
}
|
|
|
|
|
|
if (this._uniformDeclaration) {
|
|
if (this._uniformDeclaration) {
|
|
- this.compilationString = `\r\n${emitComments ? "//Uniforms\r\n" : ""}${this._uniformDeclaration}\r\n\r\n${this.compilationString}`;
|
|
|
|
|
|
+ this.compilationString = `\r\n${emitComments ? "//Uniforms\r\n" : ""}${this._uniformDeclaration}\r\n${this.compilationString}`;
|
|
}
|
|
}
|
|
|
|
|
|
if (this._attributeDeclaration && !isFragmentMode) {
|
|
if (this._attributeDeclaration && !isFragmentMode) {
|
|
- this.compilationString = `\r\n${emitComments ? "//Attributes\r\n" : ""}${this._attributeDeclaration}\r\n\r\n${this.compilationString}`;
|
|
|
|
|
|
+ this.compilationString = `\r\n${emitComments ? "//Attributes\r\n" : ""}${this._attributeDeclaration}\r\n${this.compilationString}`;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -174,6 +136,42 @@ export class NodeMaterialCompilationState {
|
|
}
|
|
}
|
|
|
|
|
|
/** @hidden */
|
|
/** @hidden */
|
|
|
|
+ public _emitFunctionFromInclude(name: string, includeName: string, options?: {
|
|
|
|
+ removeUniforms?: boolean,
|
|
|
|
+ removeVaryings?: boolean,
|
|
|
|
+ removeifDef?: boolean,
|
|
|
|
+ replaceString?: string[],
|
|
|
|
+ }) {
|
|
|
|
+ if (this.functions[name]) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.functions[name] = Effect.IncludesShadersStore[includeName];
|
|
|
|
+
|
|
|
|
+ if (!options) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (options.removeifDef) {
|
|
|
|
+ this.functions[name] = this.functions[name].replace(/^\s*?#.+$/gm, "");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (options.removeUniforms) {
|
|
|
|
+ this.functions[name] = this.functions[name].replace(/^\s*?uniform.+$/gm, "");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (options.removeVaryings) {
|
|
|
|
+ this.functions[name] = this.functions[name].replace(/^\s*?varying.+$/gm, "");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (options.replaceString) {
|
|
|
|
+ for (var index = 0; index < options.replaceString.length; index += 2) {
|
|
|
|
+ this.functions[name] = this.functions[name].replace(options.replaceString[index], options.replaceString[index + 1]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /** @hidden */
|
|
public _emitVaryings(point: NodeMaterialConnectionPoint, force = false, fromFragment = false) {
|
|
public _emitVaryings(point: NodeMaterialConnectionPoint, force = false, fromFragment = false) {
|
|
if (point.isVarying || force) {
|
|
if (point.isVarying || force) {
|
|
if (this.sharedData.varyings.indexOf(point.associatedVariableName) !== -1) {
|
|
if (this.sharedData.varyings.indexOf(point.associatedVariableName) !== -1) {
|
|
@@ -222,31 +220,32 @@ export class NodeMaterialCompilationState {
|
|
this._uniformDeclaration += `uniform ${this._getGLType(point.type)} ${point.name};\r\n`;
|
|
this._uniformDeclaration += `uniform ${this._getGLType(point.type)} ${point.name};\r\n`;
|
|
|
|
|
|
// well known
|
|
// well known
|
|
|
|
+ let hints = this.sharedData.hints;
|
|
if (point._wellKnownValue !== null) {
|
|
if (point._wellKnownValue !== null) {
|
|
switch (point._wellKnownValue) {
|
|
switch (point._wellKnownValue) {
|
|
case NodeMaterialWellKnownValues.World:
|
|
case NodeMaterialWellKnownValues.World:
|
|
- this.hints.needWorldMatrix = true;
|
|
|
|
|
|
+ hints.needWorldMatrix = true;
|
|
break;
|
|
break;
|
|
case NodeMaterialWellKnownValues.View:
|
|
case NodeMaterialWellKnownValues.View:
|
|
- this.hints.needViewMatrix = true;
|
|
|
|
|
|
+ hints.needViewMatrix = true;
|
|
break;
|
|
break;
|
|
case NodeMaterialWellKnownValues.Projection:
|
|
case NodeMaterialWellKnownValues.Projection:
|
|
- this.hints.needProjectionMatrix = true;
|
|
|
|
|
|
+ hints.needProjectionMatrix = true;
|
|
break;
|
|
break;
|
|
case NodeMaterialWellKnownValues.ViewProjection:
|
|
case NodeMaterialWellKnownValues.ViewProjection:
|
|
- this.hints.needViewProjectionMatrix = true;
|
|
|
|
|
|
+ hints.needViewProjectionMatrix = true;
|
|
break;
|
|
break;
|
|
case NodeMaterialWellKnownValues.WorldView:
|
|
case NodeMaterialWellKnownValues.WorldView:
|
|
- this.hints.needWorldViewMatrix = true;
|
|
|
|
|
|
+ hints.needWorldViewMatrix = true;
|
|
break;
|
|
break;
|
|
case NodeMaterialWellKnownValues.WorldViewProjection:
|
|
case NodeMaterialWellKnownValues.WorldViewProjection:
|
|
- this.hints.needWorldViewProjectionMatrix = true;
|
|
|
|
|
|
+ hints.needWorldViewProjectionMatrix = true;
|
|
break;
|
|
break;
|
|
case NodeMaterialWellKnownValues.FogColor:
|
|
case NodeMaterialWellKnownValues.FogColor:
|
|
- this.hints.needFogColor = true;
|
|
|
|
|
|
+ hints.needFogColor = true;
|
|
break;
|
|
break;
|
|
case NodeMaterialWellKnownValues.FogParameters:
|
|
case NodeMaterialWellKnownValues.FogParameters:
|
|
- this.hints.needFogParameters = true;
|
|
|
|
|
|
+ hints.needFogParameters = true;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|