以普通情况而论
vNormal = normal;//...gl_FragColor = vec4( vNormal, 1. );
vNormal = normal;//...gl_FragColor = vec4( normalize( vNormal ) * 0.5 + 0.5, 1. );
vNormal = normalMatrix * normal;//...gl_FragColor = vec4( normalize( vNormal ) * 0.5 + 0.5, 1. );
normalMatrix
threejs会自动传递至uniform
import * as THREE from "three";export class NormalShaderMaterial extends THREE.ShaderMaterial {constructor(params?: ConstructorParameters<typeof THREE.ShaderMaterial>[0]) {super({uniforms: {},vertexShader: /* glsl */ `varying vec3 vNormal;void main() {vNormal = normalMatrix * normal;vec4 modelViewPosition = modelViewMatrix * vec4(position, 1.0);gl_Position = projectionMatrix * modelViewPosition;}`,fragmentShader: /* glsl */ `varying vec3 vNormal; void main() {gl_FragColor = vec4( normalize( vNormal ) * 0.5 + 0.5, 1. );}`,});}
}