From 8d7012f0afec5465980ee19a0dc733c14f0ddb48 Mon Sep 17 00:00:00 2001 From: Starryi Date: Wed, 1 Nov 2023 20:42:40 +0800 Subject: [PATCH] Fix undeclared identifier error in NodeMaterial shader --- .../core/src/Materials/Node/Blocks/Dual/lightBlock.ts | 6 +++++- .../Node/Blocks/PBR/pbrMetallicRoughnessBlock.ts | 10 ++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/dev/core/src/Materials/Node/Blocks/Dual/lightBlock.ts b/packages/dev/core/src/Materials/Node/Blocks/Dual/lightBlock.ts index 52dfcdeaa2d..012a07d96a7 100644 --- a/packages/dev/core/src/Materials/Node/Blocks/Dual/lightBlock.ts +++ b/packages/dev/core/src/Materials/Node/Blocks/Dual/lightBlock.ts @@ -371,11 +371,15 @@ export class LightBlock extends NodeMaterialBlock { if (this.light) { state.compilationString += state._emitCodeFromInclude("lightFragment", comments, { - replaceStrings: [{ search: /{X}/g, replace: this._lightId.toString() }], + replaceStrings: [ + { search: /{X}/g, replace: this._lightId.toString() }, + { search: /vPositionW/g, replace: worldPosVariableName + ".xyz" }, + ], }); } else { state.compilationString += state._emitCodeFromInclude("lightFragment", comments, { repeatKey: "maxSimultaneousLights", + replaceStrings: [{ search: /vPositionW/g, replace: worldPosVariableName + ".xyz" }], }); } diff --git a/packages/dev/core/src/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.ts b/packages/dev/core/src/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.ts index 64416a62fb6..cf6fe6f2997 100644 --- a/packages/dev/core/src/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.ts +++ b/packages/dev/core/src/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.ts @@ -1116,9 +1116,7 @@ export class PBRMetallicRoughnessBlock extends NodeMaterialBlock { state._emitFunctionFromInclude("imageProcessingDeclaration", comments); state._emitFunctionFromInclude("imageProcessingFunctions", comments); - state._emitFunctionFromInclude("shadowsFragmentFunctions", comments, { - replaceStrings: [{ search: /vPositionW/g, replace: worldPosVarName + ".xyz" }], - }); + state._emitFunctionFromInclude("shadowsFragmentFunctions", comments); state._emitFunctionFromInclude("pbrDirectLightingSetupFunctions", comments, { replaceStrings: [{ search: /vPositionW/g, replace: worldPosVarName + ".xyz" }], @@ -1331,11 +1329,15 @@ export class PBRMetallicRoughnessBlock extends NodeMaterialBlock { if (this.light) { state.compilationString += state._emitCodeFromInclude("lightFragment", comments, { - replaceStrings: [{ search: /{X}/g, replace: this._lightId.toString() }], + replaceStrings: [ + { search: /{X}/g, replace: this._lightId.toString() }, + { search: /vPositionW/g, replace: worldPosVarName + ".xyz" }, + ], }); } else { state.compilationString += state._emitCodeFromInclude("lightFragment", comments, { repeatKey: "maxSimultaneousLights", + replaceStrings: [{ search: /vPositionW/g, replace: worldPosVarName + ".xyz" }], }); }