0

I'm trying to copy the shadowCascade functionality from http://threejs.org/examples/webgl_morphtargets_md2_control.html to my project. I did this 1:1 however I only get a a little bit of shadowing at a certain angles and rotations, and often cut off. Further, enabling shadowCascade from start throws shader errors. I have to wait for some time until I can set shadowCascade = true.

I tried to find documentation, links or hints explaining how shadowCascade works and what all those parameters do, without success so far.

All in all I'm rather confused, I don't really understand what is happening and why. Thanks in advance for some clarification and help!

Here's a screenshot

Edit: Here's a video of the effect

Doidel
  • 1,743
  • 1
  • 14
  • 22
  • The errors I get when directly enabling shadowCascade is "array size must be a positive integer" for stuff like 136: varying vec4 vShadowCoord[ MAX_SHADOWS ]; 137: uniform mat4 shadowMatrix[ MAX_SHADOWS ]; or in another shader 114: uniform sampler2D shadowMap[ MAX_SHADOWS ]; 115: uniform vec2 shadowMapSize[ MAX_SHADOWS ]; 116: uniform float shadowDarkness[ MAX_SHADOWS ]; 117: uniform float shadowBias[ MAX_SHADOWS ]; 118: varying vec4 vShadowCoord[ MAX_SHADOWS ]; – Doidel Mar 15 '14 at 08:06
  • These mean that maxShadows is 0. maxShadows is set by allocateShadows in three.js. max_shadows only increases if a DirectionalLight has no shadowCascade. That's why it remains 0. Why this works in other examples I don't know yet though. – Doidel Mar 15 '14 at 08:40
  • Ok I solved some part. Removing shadowCameraVisible = true helped to get rid of the errors, and I instead switched on shadowMapDebug = true; – Doidel Mar 15 '14 at 08:55
  • When I use shadowMapDebug = true on the three.js example nothing happens... – Doidel Mar 15 '14 at 09:08
  • Somehow the shadow camera moves when I move my camera... – Doidel Mar 15 '14 at 09:15
  • The `shadowCascade` code has not been a significant focus of development in more than a year. There may be problems. If you want to pursue this, and track down possible bugs, that would be great. Some issues may be due to your device and/or browser, however. – WestLangley Mar 15 '14 at 15:24
  • If Id' like to create shadows for a 3rd person character which should look similar to sunlight, would you recommend using a SpotLight like http://threejs.org/examples/webgl_shadowmap_performance.html? – Doidel Mar 15 '14 at 16:36
  • For that I would use a directional light with the character as the `target` and a tight shadow box. – WestLangley Mar 15 '14 at 23:38

1 Answers1

1

The shadowCascade code has not been a significant focus of development in more than a year. There may be problems. If you want to pursue this, and track down possible bugs, that would be great. Some issues may be due to your device and/or browser, however.

For now, I would suggest you use a directional light with the character as the target and a tight shadow box.

three.js r.66

WestLangley
  • 102,557
  • 10
  • 276
  • 276
  • Further, since I use 3rd person, I do not need to have a shadow map behind the camera. Therefore I adjust the DirectionalLight's position according to the player's position and rotation. Onto the player I mounted a reference point (an Object3D with, in my case, position (0,0,-19)). Then I position the light in the render/tick method accordingly: var p2 = new THREE.Vector3(0,45,0).applyMatrix4(sunlightReferencePoint.matrixWorld); light.position.set(p2.x + 20, p2.y + 50, p2.z); – Doidel Mar 16 '14 at 15:57