so far i make my own custom system for shadow which have two render pass, one for static shadow and one for dyhamic shadow , it workign perfectly now the problem i want to solve it to make the shadow only be rendered around the player to not use gigantic shadow map , my map is huge and i just want shadow to be rendered near the player , is there any native function that help me do that or do i need to start from scratch, separating the render pass for dynamic and static shadow was almost fast since it was just copy and paste and addign soem uniform on the program but i dont see any code that make the shadowmap to be asociated with a center point , is mostly aboslute position , thanks
Normally you do this by repositioning the shadow casting light.
What threejs light type are you using to cast your shadow?
directional light , do i need to do updatematrix everytime i move light, correct?
No. It should update automatically.. unless you have set .matrixAutoUpdate = false on it.
But you reminded me that DirectionalLight has one other tricky thing though.. it has a field called .target which is an empty object that the light will point at…
so if you move the directionalLight, you also have to move it’s .target object also and update its matrix. (since it’s not added to the scene by default)
Or… you can add its target to itself.. directionalLight.add( directionalLight.target ).. then it should move automatically with the light.
three.js/src/lights/DirectionalLight.js at dev · mrdoob/three.js · GitHub this one? just to double check ,is this variablerelated to generate limited shadowmap so shadowmap have limits around the player correct, in this case the target should be the player object and i define the size of the shadomap by defining the size around the player, everytime i move/rotate the player i also move/rotate the directionalligth so the shadow remain the same but the environemtn will change since the player is moving around it, correct?
Yes that sounds roughly correct. I don’t usually resize the lights camera.. but I pick a size that works and isn’t blurry up close…
then each frame, before render, move the dir light to follow the player…
the problem ^ is.. if you move it every frame.. the shadows can shimmer .. but if you only move it when the player has moved some certain distance first.. then you can get rid of a lot of the shimmer. If you’re up for the math behind it.. there is an actual correct amount of movement in the X or Z direction that can move the shadow without it shimmering.. you have to move the shadow light by a multiple of its shadow texel size in worldspace.. but that is a bit tricky to calculate.. and just using some threshold like > ~1 meter movement.. is often acceptable.