Try this:
node.material.onBeforeCompile = (shader) => {
shader.vertexShader = `
varying vec3 vN;
${shader.vertexShader}
`.replace(
`#include <normal_vertex>`,
`#include <normal_vertex>
vN = normal;
//vN = (modelMatrix * vec4(normal, 1.)).xyz;
`
);
shader.fragmentShader = `
varying vec3 vN;
${shader.fragmentShader}
`.replace(
`#include <dithering_fragment>`,
`#include <dithering_fragment>
if(vN.y<0.0){ gl_FragColor.rgb=vec3(0.0,1.0,0.0); }`
);
};
Depends on your needs, use
vN = normal;
- object’s space
or
vN = (modelMatrix * vec4(normal, 1.)).xyz;
- global space