Search code examples
three.jspost-processing

Three.js - Updating godrays light source position


I'm using a sprite as a light source for a god rays post-processing pass in Three.js. However, when I update the sprite position, the post-processed light stays at its initial position, resulting in the sprite moving without its god rays.

I tried resetting the light source position after initialization on each frame like so:

...    
PostProcessor.godRaysPass.lightSource.position.set(sprite.position.x, sprite.position.y, sprite.position.z)
PostProcessor.composer.render(clock.getDelta());

or

...    
godRaysPass.lightSource = sprite
PostProcessor.composer.render(clock.getDelta());

But nothing worked, and by looking at the GodRays class I'm not sure it's even possible to update the light source position without modifying the class first, or am I missing something?


Solution

  • Alright I did some digging and came to this:

    Moving the source light doesn't cause any problem, the godrays do follow the sprite source when you change the sprite position. The problem actually came from the fact that the source light was inside a rotating group. By removing the light source from the group and rotating it along the same axis as the group, the godrays behave as expected.