From 16f4143e43492dae692dc1ec071fa3ad02934f45 Mon Sep 17 00:00:00 2001 From: "Alex." Date: Tue, 17 Mar 2026 18:25:59 +0100 Subject: [PATCH 1/2] Added mMatrix switch for instancing to rendertargets_slots.vert world normals --- src/corelibs/cgl/rendertargets_slots.vert | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/corelibs/cgl/rendertargets_slots.vert b/src/corelibs/cgl/rendertargets_slots.vert index f6320e64c1..7e87aa32a9 100644 --- a/src/corelibs/cgl/rendertargets_slots.vert +++ b/src/corelibs/cgl/rendertargets_slots.vert @@ -20,6 +20,15 @@ #ifdef MOD_SLOT_POS_NORMAL_WORLD - MOD_normal_world=(mMatrix*vec4(norm,1.0)).xyz; + mat4 MOD_fmMatrix=mMatrix; + #ifdef INSTANCING + #ifdef TEXINSTMAT + MOD_fmMatrix = texInstMat; + #endif + #ifndef TEXINSTMAT + MOD_fmMatrix = iMat; + #endif + #endif + MOD_normal_world=vec3(MOD_fmMatrix * vec4(norm, 0.0)); #endif From 18afd80aa9f91632467cc5ffd41e9b1ab2158910 Mon Sep 17 00:00:00 2001 From: "Alex." Date: Tue, 17 Mar 2026 18:26:38 +0100 Subject: [PATCH 2/2] Normalize world space normals in fragment in rendertargets.js --- src/corelibs/cgl/rendertargets.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelibs/cgl/rendertargets.js b/src/corelibs/cgl/rendertargets.js index 8923a21ccf..93cb4a10f7 100644 --- a/src/corelibs/cgl/rendertargets.js +++ b/src/corelibs/cgl/rendertargets.js @@ -89,7 +89,7 @@ export class RenderTargets else if (type == "Position * ModelView") return " " + outcolor + i + " = vec4(MOD_pos_mv,1.);".endl(); else if (type == "Position Object") return " " + outcolor + i + " = vec4(MOD_pos_object,1.);".endl(); - else if (type == "Normal World") return " " + outcolor + i + " = vec4(MOD_normal_world,1.);".endl(); + else if (type == "Normal World") return " " + outcolor + i + " = vec4(normalize(MOD_normal_world),1.);".endl(); else if (type == "Normal * ModelView") return " " + outcolor + i + " = vec4(MOD_normal_mv,1.);".endl(); else if (type == "Material Id") return " " + outcolor + i + " = vec4(round(materialId),round(instIdx),0.,1.);".endl(); else if (type == "Object Id") return " " + outcolor + i + " = vec4(objectId,0.,0.,1.);".endl();