Raymarching in Shadertoy, openFrameworks and Unreal Engine


Raymarching is a special method of rendering 3D objects or 3D scene:
  • It's used for rendering ocean water, clouds, metaballs in Unreal Engine 4 and other engines and 3D editors.
  • It's a main technique used for rendering 3D in Shadertoy projects.

Examples

Mehod description

The "forward" method of rendering used in OpenGL by default as a creating object from vertices and faces, and then rasterizing faces to obtain raster image for showing in on the screen.
In the opposite, the "raymarching" method creates a ray the each resulted image's pixel, which goes from the camera's origin through the pixel into 3D scene. The special point moves along the ray and accumulates colors of scene while 99-100% of opacity will be accumulated.
The step of moving along the ray can be fixed or dynamically changed (just increasing for rendering clouds or depending on the distance to the objects for rigid scene rendering such as ocean).
So in raymarching we don't need to represent object as a set of triangles, and can represent it by formula, as a 3D texture or octotree.

Raymarching is a just one particular technique and  there are two similar tecnhiques:
  • raycasting - here ray don't scanned, but place of hitting the object is computed exactly,
  • raytracing - here diffusion and reflection and lighing is dealed more delicately.

Tutorials on raymarching

More Shadertoy examples

Simple volume rendering by XT95, with light scattering: https://www.shadertoy.com/view/lss3zr
Ocean with islands by frankenburgh: https://www.shadertoy.com/view/lsBSWm
Well-documented code of ocean by bteitler: https://www.shadertoy.com/view/llsXD2

Making raymarching in openFrameworks

ofxShadertoy addon by Tiago Rezende to load Shadertoy's shaders:
https://github.com/tiagosr/ofxShadertoy

Addon for raytracing on CPU using Intel Embree library:
https://github.com/cyrildiagne/ofxEmbree

ofxVolumetrix addon by Timothy Scaffidi for working with 3D textures (voxels) in OpenGL and rendering it using raycasting:
https://github.com/timscaffidi/ofxVolumetrics

Computing ray direction from OpenGL matrix:
https://stackoverflow.com/questions/2354821/raycasting-how-to-properly-apply-a-projection-matrix/52764898#52764898

Computing ray directions in openFrameworks, our article.
Formula for backward alpha blending, our article.

Making volumetric raymarcher in Unreal Engine



Comments

Popular posts from this blog

Computing ray origin and direction from Model View Projection matrices for raymarching

Forward and backward alpha blending for raymarching

Forward, Deferred and Raytracing rendering in openFrameworks and web