CausticGL API Details: Ray and Frame Shaders

CauticGL



CausticRT is a hardware+software solution to accelerate raytracing. The CausticOne is the hardware side of CausticRT and offloads all raytracing calculations from CPU/GPU. CausticGL is the software side of CausticRT and is a modified version of OpenGL ES 2.0 with a set of specific extensions that allow to cast rays within GLSL shaders.

CausticGL exposes OpenGL functions with a different prefixe: rgl in place of gl:

OpenGL: glTexImage2D()
CausticGL: rglTexImage2D()

CausticGL adds new types of shaders programs: Ray Shaders and Frame Shaders

A ray shader is a shader that is bound to an object in the scene (known as a primitive object). It is responsible for implementing the lighting and material effects on the surface, at the point in the scene where the ray intersects the object.

CauticGL Ray Shader

CauticGL Ray Shader


Ultimately, the output from a ray shader can be a value accumulated into the frame buffer by calling accumulate(). The following example shows a ray shader that displays the normals of the geometry in color space:

uniform vec3 brightness;
varying vec3 normal;
void main()
{
  accumulate(brightness * (0.5 + 0.5 * normal));
}

A ray shader is executed when a ray intersects an object. A ray shader can also create new rays with createRay() and emitRay(). The following example shows the most basic use of ray emission to implement a perfect mirror:

varying vec3 normal;
void main()
{
  createRay();

  // Set the new ray's direction
  // by reflecting it off of 
  // the surface normal
  gl_OutRay.direction = reflect(gl_InRay.direction, 
                                normalize(normal));
  
  emitRay();
}

While ray shaders are executed when a ray intersects a piece of geometry, the first rays in the scene must come from somewhere. That somewhere is a frame shader.

A frame shader executes once for every pixel in the output Frame Buffer Object, and is responsible for emitting all of the rays that will contribute color to that pixel. Like ray shaders, frame shaders can access uniform parameters for the scene. Inside a shader, the position of the pixel can be queried through the gl_FragCoord built-in. The size of the frame buffer can be queried through gl_FrameSize. The following example implements a pinhole camera (no depth of field), that can be moved around the scene with a uniform:

uniform vec3 cameraPosition;
void main()
{
  createRay();
  
  gl_OutRay.origin = cameraPosition;
  // Set the ray's direction dependent on 
  // the position of the pixel in the frame buffer
  gl_OutRay.direction = 
     vec3(gl_FragCoord.xy / gl_FrameSize.xy - 0.5, -1.0);
  
  emitRay();
}

You can download this PDF for more details on CausticGL API.

Related Posts

[source] | [via]




Geeks3D.com

↑ Grab this Headline Animator