|
@@ -145,6 +145,26 @@ export class LightBlock extends NodeMaterialBlock {
|
|
let worldPos = this.worldPosition;
|
|
let worldPos = this.worldPosition;
|
|
let worldNormal = this.worldNormal;
|
|
let worldNormal = this.worldNormal;
|
|
|
|
|
|
|
|
+ let comments = `//${this.name}`;
|
|
|
|
+
|
|
|
|
+ // Declaration
|
|
|
|
+ if (!this.light) { // Emit for all lights
|
|
|
|
+ state._emitFunctionFromInclude(state.supportUniformBuffers ? "lightUboDeclaration" : "lightFragmentDeclaration", comments, {
|
|
|
|
+ repeatKey: "maxSimultaneousLights"
|
|
|
|
+ });
|
|
|
|
+ this._lightId = 0;
|
|
|
|
+
|
|
|
|
+ state.sharedData.dynamicUniformBlocks.push(this);
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ this._lightId = (state.counters["lightCounter"] !== undefined ? state.counters["lightCounter"] : -1) + 1;
|
|
|
|
+ state.counters["lightCounter"] = this._lightId;
|
|
|
|
+
|
|
|
|
+ state._emitFunctionFromInclude(state.supportUniformBuffers ? "lightUboDeclaration" : "lightFragmentDeclaration", comments, {
|
|
|
|
+ replaceStrings: [{ search: /{X}/g, replace: this._lightId.toString() }]
|
|
|
|
+ }, this._lightId.toString());
|
|
|
|
+ }
|
|
|
|
+
|
|
// Inject code in vertex
|
|
// Inject code in vertex
|
|
let worldPosVaryingName = "v_" + worldPos.associatedVariableName;
|
|
let worldPosVaryingName = "v_" + worldPos.associatedVariableName;
|
|
state._emitVaryingFromString(worldPosVaryingName, "vec3");
|
|
state._emitVaryingFromString(worldPosVaryingName, "vec3");
|
|
@@ -152,6 +172,20 @@ export class LightBlock extends NodeMaterialBlock {
|
|
let worldNormalVaryingName = "v_" + worldNormal.associatedVariableName;
|
|
let worldNormalVaryingName = "v_" + worldNormal.associatedVariableName;
|
|
state._emitVaryingFromString(worldNormalVaryingName, "vec3");
|
|
state._emitVaryingFromString(worldNormalVaryingName, "vec3");
|
|
|
|
|
|
|
|
+ if (this.light) {
|
|
|
|
+ state.compilationString += state._emitCodeFromInclude("shadowsVertex", comments, {
|
|
|
|
+ replaceStrings: [
|
|
|
|
+ { search: /{X}/g, replace: this._lightId.toString() },
|
|
|
|
+ { search: /worldPos/g, replace: worldPos.associatedVariableName }
|
|
|
|
+ ]
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ state.compilationString += `vec4 worldPos = ${worldPos.associatedVariableName};\r\n`;
|
|
|
|
+ state.compilationString += state._emitCodeFromInclude("shadowsVertex", comments, {
|
|
|
|
+ repeatKey: "maxSimultaneousLights"
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
state.compilationString += `${worldPosVaryingName} = ${worldPos.associatedVariableName}.xyz;\r\n`;
|
|
state.compilationString += `${worldPosVaryingName} = ${worldPos.associatedVariableName}.xyz;\r\n`;
|
|
state.compilationString += `${worldNormalVaryingName} = ${worldNormal.associatedVariableName}.xyz;\r\n`;
|
|
state.compilationString += `${worldNormalVaryingName} = ${worldNormal.associatedVariableName}.xyz;\r\n`;
|
|
}
|
|
}
|
|
@@ -172,6 +206,8 @@ export class LightBlock extends NodeMaterialBlock {
|
|
|
|
|
|
let comments = `//${this.name}`;
|
|
let comments = `//${this.name}`;
|
|
let worldPos = this.worldPosition;
|
|
let worldPos = this.worldPosition;
|
|
|
|
+
|
|
|
|
+ state._emitFunctionFromInclude("helperFunctions", comments);
|
|
|
|
|
|
state._emitFunctionFromInclude("lightsFragmentFunctions", comments, {
|
|
state._emitFunctionFromInclude("lightsFragmentFunctions", comments, {
|
|
replaceStrings: [
|
|
replaceStrings: [
|
|
@@ -179,18 +215,17 @@ export class LightBlock extends NodeMaterialBlock {
|
|
]
|
|
]
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ state._emitFunctionFromInclude("shadowsFragmentFunctions", comments, {
|
|
|
|
+ replaceStrings: [
|
|
|
|
+ { search: /vPositionW/g, replace: "v_" + worldPos.associatedVariableName }
|
|
|
|
+ ]
|
|
|
|
+ });
|
|
|
|
+
|
|
if (!this.light) { // Emit for all lights
|
|
if (!this.light) { // Emit for all lights
|
|
state._emitFunctionFromInclude(state.supportUniformBuffers ? "lightUboDeclaration" : "lightFragmentDeclaration", comments, {
|
|
state._emitFunctionFromInclude(state.supportUniformBuffers ? "lightUboDeclaration" : "lightFragmentDeclaration", comments, {
|
|
repeatKey: "maxSimultaneousLights"
|
|
repeatKey: "maxSimultaneousLights"
|
|
});
|
|
});
|
|
- this._lightId = 0;
|
|
|
|
-
|
|
|
|
- state.sharedData.dynamicUniformBlocks.push(this);
|
|
|
|
} else {
|
|
} else {
|
|
-
|
|
|
|
- this._lightId = (state.counters["lightCounter"] !== undefined ? state.counters["lightCounter"] : -1) + 1;
|
|
|
|
- state.counters["lightCounter"] = this._lightId;
|
|
|
|
-
|
|
|
|
state._emitFunctionFromInclude(state.supportUniformBuffers ? "lightUboDeclaration" : "lightFragmentDeclaration", comments, {
|
|
state._emitFunctionFromInclude(state.supportUniformBuffers ? "lightUboDeclaration" : "lightFragmentDeclaration", comments, {
|
|
replaceStrings: [{ search: /{X}/g, replace: this._lightId.toString() }]
|
|
replaceStrings: [{ search: /{X}/g, replace: this._lightId.toString() }]
|
|
}, this._lightId.toString());
|
|
}, this._lightId.toString());
|