我尝试在shadowMap
的接收器上使用ShaderMaterial
。
我已经读过,如果正确添加ShaderChunks
,就可以完成。
是的,我加入了应有的位置。
THREE.UniformsLib['shadowmap'],
THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
THREE.ShaderChunk[ "shadowmap_vertex" ],
THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
THREE.ShaderChunk[ "shadowmap_fragment" ]
不知何故,我需要添加' worldPosition'在顶点着色器中(我做了) 然后,出现了一些阴影,但不是我所期望的(来自torusKnot)。
有人可以查看代码并告诉我原因吗?
小提琴:https://jsfiddle.net/jmcjc5u/9jz3se0d/5/
var shaderMaterial = new THREE.ShaderMaterial ({
uniforms: THREE.UniformsUtils.merge([
THREE.UniformsLib['common'],
THREE.UniformsLib['lights'],
THREE.UniformsLib['shadowmap'],
]),
vertexShader: [
THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
"void main() {",
" gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);",
" vec4 worldPosition = modelMatrix * vec4(position, 1.0);",
THREE.ShaderChunk[ "shadowmap_vertex" ],
"}",
].join('\n'),
fragmentShader: [
THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
"void main() {",
" gl_FragColor = vec4 (0.5,0.5,0.5,1.0);",
THREE.ShaderChunk[ "shadowmap_fragment" ],
"}",
].join('\n'),
});