I have been toying with the idea of writing a deferred shading or lighting renderer for a while and it’s really easy to do with the myriads of tutorials online.

The main thing I wanted to try was an idea I had floating in my head about a potential idea for a realtime global illumination or simple light bounce.

Not very feasible for a game or anything, but something I wanted to try.


My main idea was for a single light source first.

What if we store a fullscreen reflection vector rendertarget (not the normals from the objects but the direction the light bounces off of them). In a different renderTarget or potentially just the alpha channel of the first one I then store the distance to the light source from each pixel.

The idea then would be – for each pixel I know which path the light will take and I know how much it has traveled already. With specular information gathered in some alpha channel of the g-buffer I can estimate how reflective and how “rough/smooth” the current pixel is.

My first idea was I could just ray march from this pixel until I hit another pixel and add some color to it. Doesn’t have to be full resolution.

And if the pixel is relatively unsmooth I just go in a random direction, depending on how unlike a mirror my surface was. Would be a bit noisy, but for a lot of pixels and maybe some temporal blending it would be ok, maybe?

Well and here the whole thing fell apart. I forgot that I can’t write on just any pixel. I can sample from a certain point and write my pixel, but I can’t manipulate others (unless I use computer shader or CUDA etc. I’d love to, but I felt like staying with MonoGame since it’s so fast to setup and stuff like this is not supported).

So basically RIP.

I thought I might at least finish what I started and I decided to go with the sampling approach. For each pixel I check in a chunk of its neighbours. If their reflection value points towards me and they still have some light distance “left” I color my pixel a bit with their color multiplied by light color.

Looks like an expensive bloom/glow now. Mission fucking accomplished.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s