Support Forum       G3D Web Page     
Public Member Functions | List of all members
glsl::screenSpaceRayTrace_glsl Class Reference

Shader program. More...

Public Member Functions

float distanceSquared (vec2 A, vec2 B)
 
bool traceScreenSpaceRay() numLayers (vec3 csOrigin, vec3 csDirection, mat4x4 projectToPixelMatrix, sampler2D csZBuffer, vec2 csZBufferSize, float csZThickness, const in bool csZBufferIsHyperbolic, vec3 clipInfo, float nearPlaneZ, float stride, float jitterFraction, float maxSteps, in float maxRayTraceDistance, out vec2 hitPixel, out int hitLayer, out vec3 csHitPoint)
 Screen-space ray trace suitable for a "peeled" depth buffer of up to four layers. More...
 
bool traceScreenSpaceRay1 (vec3 csOrigin, vec3 csDirection, mat4x4 projectToPixelMatrix, sampler2D csZBuffer, vec2 csZBufferSize, float csZThickness, const in bool csZBufferIsHyperbolic, vec3 clipInfo, float nearPlaneZ, float stride, float jitterFraction, float maxSteps, in float maxRayTraceDistance, out vec2 hitPixel, out int hitLayer, out vec3 csHitPoint)
 

Detailed Description

Shader program.

Member Function Documentation

◆ distanceSquared()

float glsl::screenSpaceRayTrace_glsl::distanceSquared ( vec2  A,
vec2  B 
)
inline

◆ numLayers()

bool traceScreenSpaceRay() glsl::screenSpaceRayTrace_glsl::numLayers ( vec3  csOrigin,
vec3  csDirection,
mat4x4  projectToPixelMatrix,
sampler2D  csZBuffer,
vec2  csZBufferSize,
float  csZThickness,
const in bool  csZBufferIsHyperbolic,
vec3  clipInfo,
float  nearPlaneZ,
float  stride,
float  jitterFraction,
float  maxSteps,
in float  maxRayTraceDistance,
out vec2  hitPixel,
out int  hitLayer,
out vec3  csHitPoint 
)
inline

Screen-space ray trace suitable for a "peeled" depth buffer of up to four layers.

The common unpeeled, single-layer case is specially optimized below. For traceScreenSpaceRay1, the termination conditions within the inner loop can be moved to the loop condition itself.

◆ traceScreenSpaceRay1()

bool glsl::screenSpaceRayTrace_glsl::traceScreenSpaceRay1 ( vec3  csOrigin,
vec3  csDirection,
mat4x4  projectToPixelMatrix,
sampler2D  csZBuffer,
vec2  csZBufferSize,
float  csZThickness,
const in bool  csZBufferIsHyperbolic,
vec3  clipInfo,
float  nearPlaneZ,
float  stride,
float  jitterFraction,
float  maxSteps,
in float  maxRayTraceDistance,
out vec2  hitPixel,
out int  hitLayer,
out vec3  csHitPoint 
)
inline
Parameters
csOriginCamera-space ray origin, which must be within the view volume and must have z < -0.01 and project within the valid screen rectangle
csDirectionUnit length camera-space ray direction
projectToPixelMatrixA projection matrix that maps to pixel coordinates (not [-1, +1] normalized device coordinates). Usually g3d_ProjectToPixelMatrix or gbuffer_camera_projectToPixelMatrix.
csZBufferThe depth or camera-space Z buffer, depending on the value of csZBufferIsHyperbolic
csZBufferSizeDimensions of csZBuffer
csZThicknessCamera space thickness to ascribe to each pixel in the depth buffer
csZBufferIsHyperbolicTrue if csZBuffer is an OpenGL depth buffer, false (faster) if csZBuffer contains (negative) "linear" camera space z values. Const so that the compiler can evaluate the branch based on it at compile time
clipInfoSee G3D::Camera documentation
nearPlaneZNegative number. Doesn't have to be THE actual near plane, just a reasonable value for clipping rays headed towards the camera
strideStep in horizontal or vertical pixels between samples. This is a float because integer math is slow on GPUs, but should be set to an integer >= 1
jitterFractionNumber between 0 and 1 for how far to bump the ray in stride units to conceal banding artifacts, plus the stride ray offset. It is recommended to set this to at least 1.0 to avoid self-intersection artifacts. Using 1 + float((int(gl_FragCoord.x) + int(gl_FragCoord.y.y)) & 1) * 0.5 gives a nice dither pattern when stride is > 1.0;
maxStepsMaximum number of iterations. Higher gives better images but may be slow
maxRayTraceDistanceMaximum camera-space distance to trace before returning a miss
hitPixelPixel coordinates of the first intersection with the scene
csHitPointCamera space location of the ray hit

Single-layer


documentation generated on Wed Nov 24 2021 08:02:04 using doxygen 1.8.15