The goal i am trying to achieve is to create a 2d lightshafts shader that can be applied to particle sprites for pseudo volumetric glows. This is the same effect many games use to simulate sun light shafts etc. (before everything went voxel based) I wanted it to be as simple and effiecient as possible. I dont want to have to setup render target camera or any extra entities in the world for it to work. Ideally it would be a simple shader you apply to the sprite.
Chapter 13. Volumetric Light Scattering as a Post-Process | NVIDIA Developer
Most engines do this process in screenspace. However, since i want this applied to a particle sprite, it needs to sample the depth of the scene and compare it to the depth of the particle. My idea was to create a material, sample the scene depth and pixel depth and do an “if” statment to color it black and white (black is all geo in front, white is behind. I would then save that material to a render target which is then used for the radial blur and compositing into the scene.
Unfortunately this isnt working. For some reason the render target isnt accepting the data. It seems to be missing the depth info. However this is not the only problem, if the RT is created using geometry thats in the world, then it needs to exist somewhere in the world at all times. The final material on the particle sprite is not this material that creates the RT, but a new material that is reading and blurring the render target. I experimented with having 2 sprite renderers in my niagara system (one for the RT material and one for the final effect) but no luck.
Does anyone know of a way i can achieve this result? I essentially need to make a black and white mask of the scene depth, with the seperation determined by the depth of the sprite, and have that added into a render target. I did get some results using the scene capture 2d camera but it requires that extra entity in the world and some extra setups. (is there a way to set the current/local cam to that scene capture2d camera?) Another thing to consider is what to do if more than one of these are on screen…
Here are some pics…
This is the black and white mask. The material is currently applied to niagara particle (for visualization). I want a result like this in the RT.