Real time shader ray tracing (Kinda)


Here is a rendering of the 0 crossing of a density field procedurally generated in a shader on a full screen quad. It projects rays out into the density field, and tries to find the surface (and often fails). The density field equation has derivative data for lighting, and I reflect rays as they cross a r=1 sphere. Currently no rays are traced for shadows, though it should not be hard to add.

As the camera moves, the edges tend to jitter quite a bit. With some low rez surface finding passes, and some edge detection and higher rez passes, this could be fixed, and probably sped up slightly.

It is not a serious attempt at a rendering system for a game. It has major issues. It probably could be made to work well enough for some real use, and it could be fed the depth buffer so it could not overlay on everything. Ambient occlusion could be added, and so could shadows, refraction, and some other cool effects, but doing all of this would most likely make it even slower, and it has nasty artifacts, and interacts with pre made models horribly as it is only created as needed in the shader. Currently I am unable to get decent noise into it until I can get the proper derivatives of 3D noise functions. It could be made to work with height maps, and add detail noise that can include overhangs and caves. Currently it just takes a pile on sin functions and adds them up.

I will continue to play with it, and if I get anything more interesting, I’ll post it here. Basically everything (other than making the full screen quad and passing in the camera position) is in the fragment shader. The source is here–files/miscfiles/ incase anyone wants to look at it.


Very nicely done!