How to render "sunlight" around a moving object as opposed to a fixed location?

I’ve tried creating a “Sun” with Directional and SpotLight to no avail - specifically the shadowMap of the Sun - the normal shadows on materials that take them work as expected.

All the tutorials I’ve found have had huge, static suns. I want mine to follow the player. But tracking the player position with the Light position doesn’t do it … the shadowMap does not seem to move, so the shadows disappear eventually.

I tried a lot of things and it just feels like a needle in a haystack.
Setting the Light.position to player.position, nope
Setting the Light.target to player.position, nope
updating shadowMap position along with player and light position, nope

An extreme example of what I want is, to make a 10 unit area tracking the player constantly casting shadows… any pointers?

I thought the shadow should update itself as long as you move the light. It appears it is not so straight-forwrd :unamused: https://jsfiddle.net/sj9xv2w8/

I did get this working with Spotlight, enough.
Still no luck with DirectionLight.
With SpotLight I set the Light.target once to the player model at intialization, and then inside the animation loop, update the Light position a fixed offset from player.position… I assume a “player.model.add(spotlight)” would also work there. I thought target was a fixed internal vector (“back to origin”), but it refers to an actual world object it seems.

Docs suggest that a DirectionLight “position” is a normalized vector, but if thats the case, why are we updating it in the anim loop… it’s confusing, idk.

Not sure what the deal was with DirectionLight but I really just wanted a simple sun for now. And these are really simple - the spotlight offset and FOV has to be far away for this work, which is making it pretty blurry

What’s wrong with this example? It seems to be doing what you want.

yes. and figuring out how to do it was not simple. e g 1st thing I tried was to add the light as a child to some object, and you know how that went, right… but I was surprized.

1 Like