0

I tried to use shadowMap on a receiver with ShaderMaterial. I have read that if the ShaderChunks are added properly, it can be done.

Yes, I added into the due places.

THREE.UniformsLib['shadowmap'],
THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
THREE.ShaderChunk[ "shadowmap_vertex" ],
THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
THREE.ShaderChunk[ "shadowmap_fragment" ]

Somehow, I need to add 'worldPosition' in the vertex shader (and I did) Then, some shadow appears, but not what I expected (from torusKnot).

Could someone take a look at the code and tell me why?

fiddle: 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'),               
});
Sam
  • 2,935
  • 1
  • 19
  • 26
  • (1) Try `MeshPhongMaterial` for the plane and you will see the same problem. (2) See [this answer](http://stackoverflow.com/questions/37581812/shadow-is-abnormally-shaped-for-meshlambertmaterial-in-three-js-r76/37644913#37644913). (3) Avoid outdated versions of three.js. Upgrade to the current one. – WestLangley Jun 13 '16 at 12:45
  • Indeed, I mistakenly set the FOV to be 5 (degrees). after I change to 120, it runs fine. – Jyun-Ming Chen Jun 13 '16 at 14:08

0 Answers0