Ray tracing in fragment shaders

A common (if somewhat impractical) technique used to show how powerful shaders can be is using them to ray trace a scene. Thus far, all of our rendering has been done with polygon rasterization, which is the technical term for the triangle-based rendering that WebGL operates with). Ray tracing is an alternate rendering technique that traces the path of light through a scene as it interacts with mathematically defined geometry.

Ray tracing has several advantages compared to polygonal rendering, the primary of which is that it can create more realistic scenes due to a more accurate lighting model that can easily account for things like reflection and reflected lighting. Ray tracing also tends to be far slower than ...

Get WebGL Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.