diff --git a/src/corelibs/cgl/rendertargets.js b/src/corelibs/cgl/rendertargets.js index 8923a21cc..93cb4a10f 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(); diff --git a/src/corelibs/cgl/rendertargets_slots.vert b/src/corelibs/cgl/rendertargets_slots.vert index f6320e64c..7e87aa32a 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