Monday, November 3, 2014

Hobby Quest: ShaderToy - Light Columns

I spent some time last month creating this shader in ShaderToy.  It came to me in a dream while I was developing ShaderToy VR (more to come on that later).  The idea was to create an interesting perspective in all directions from a relatively fixed point.

Thanks to a recommendation from Dave Hoskins (an active and brilliant member on ShaderToy), I added this cool transition between 2 textures which seeds the light colors and positions in the columns.

The shader works by creating a simple pin-hole camera model and then for each pixel of the camera plane, ray march through the columns perpendicular to the x-z plane (y is up) using digital differential analysis (aka dda marching).

When a ray passes through a column, the shader computes two ray-plane intersection tests against a smaller column inside that volume that is rotating with time.  The two planes tested are determined based on the faces that would be presenting to the ray.

If there is an intersection, I compute the shading of the column, including the traveling light.  I also add any bounce contribution from neighboring columns.  I only compute bounce for the neighboring columns that are facing towards the shaded surface normal which allows me to limit the computation to only 4 neighboring columns instead of 8.

The reflection works by using the absolute value of y when computing shading.