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


Routines for reconstructing linear Z, camera-space position, and camera-space face normals from a standard or infinite OpenGL projection matrix from G3D. More...

Public Member Functions

Ray cameraRay (vec2 pixelPosition, vec4 projInfo)
 
float depthBufferValue (float csZ, vec3 clipInfo)
 
Converts a camera-space Z value to a depth buffer value. More...
 
bool castScreenSpaceRay() numLayers (vec3 csOrigin, vec3 csDirection, mat4 projectionMatrix, sampler2D csZBuffer, vec2 csZBufferSize, vec3 clipInfo, float jitterFraction, const int numSteps, out int s, float layerThickness, in float maxRayTraceDistance, out float actualRayTraceDistance, out vec2 hitTexCoord, out int which, const in bool csZBufferIsHyperbolic, float GUARD_BAND_FRACTION_X, float GUARD_BAND_FRACTION_Y)
 Ray march against thickened depth buffer surface. More...
 
vec3 reconstructCSFaceNormal (vec3 C)
 Reconstructs screen-space unit normal from screen-space position. More...
 
vec3 reconstructCSPosition (vec2 S, float z, vec4 projInfo)
 Reconstruct camera-space C.xyz from screen-space S = (x, y) in pixels and camera-space z < 0. More...
 
vec3 reconstructCSPositionFromDepth (vec2 S, float depth, vec4 projInfo, vec3 clipInfo)
 Helper for reconstructing camera-space P.xyz from screen-space S = (x, y) in pixels and hyperbolic depth. More...
 
float reconstructCSZ (float d, vec3 clipInfo)
 
vec3 reconstructNonUnitCSFaceNormal (vec3 C)
 
vec3 reconstructWSPositionFromDepth (vec2 S, float depth, vec4 projInfo, vec3 clipInfo, mat4x3 cameraToWorld)
 Helper for the common idiom of getting world-space position P.xyz from screen-space S = (x, y) in pixels and hyperbolic depth. More...
 
Ray worldRay (vec2 pixelPosition, mat4x3 cameraToWorld, vec4 projInfo, out float csRayZ)
 
More...
 
Ray worldRay (vec2 pixelPosition, mat4x3 cameraToWorld, vec4 projInfo)
 Given pixel coordinates and camera data (e.g., g3d_CameraToWorldMatrix and g3d_ProjInfo or Camera.frame and Camera.projInfo), returns the world space ray through the pixel position. More...
 

Detailed Description


Routines for reconstructing linear Z, camera-space position, and camera-space face normals from a standard or infinite OpenGL projection matrix from G3D.

Member Function Documentation

◆ cameraRay()

Ray glsl::reconstructFromDepth_glsl::cameraRay ( vec2  pixelPosition,
vec4  projInfo 
)
inline

◆ depthBufferValue()

float glsl::reconstructFromDepth_glsl::depthBufferValue ( float  csZ,
vec3  clipInfo 
)
inline


Converts a camera-space Z value to a depth buffer value.

◆ numLayers()

bool castScreenSpaceRay() glsl::reconstructFromDepth_glsl::numLayers ( vec3  csOrigin,
vec3  csDirection,
mat4  projectionMatrix,
sampler2D  csZBuffer,
vec2  csZBufferSize,
vec3  clipInfo,
float  jitterFraction,
const int  numSteps,
out int  s,
float  layerThickness,
in float  maxRayTraceDistance,
out float  actualRayTraceDistance,
out vec2  hitTexCoord,
out int  which,
const in bool  csZBufferIsHyperbolic,
float  GUARD_BAND_FRACTION_X,
float  GUARD_BAND_FRACTION_Y 
)
inline

Ray march against thickened depth buffer surface.

This is a set of four functions: castScreenSpaceRay1, castScreenSpaceRay2, castScreenSpaceRay3, castScreenSpaceRay4. The number indicates the number of depth layers in the channels of the csZBuffer.

Parameters
jitterFractionCan be used to replace banding with noise when numSteps is small. A good value is the hash function fract(sin(gl_FragCoord.x * 12237.12 + gl_FragCoord.y * 21312.12))
projectionMatrixThe g3d_ProjectionMatrix for the camera that rendered the scene (not necessarily the current projection matrix, which may be orthographic for a deferred shading pass)
clipInfoThe camera->projection().getProjectUnitMatrix() for the camera that rendered the scene (only needed if csZBufferIsHyperbolic is true)
csZBufferIsHyperbolicIf true, reconstructZ is invoked for every value read back from csZBuffer
distanceInput: maximum distance to trace. Output: distance to intersection.
layerThicknessAssumed thickness of the depth surface, in meters. Must be positive. Very large values avoid missed intersections behind objects. Very small values avoid making objects appear too thick.
numLayersNumber of layers in csZBuffer, expressed in the color channels.
sActual steps taken by the ray trace, useful for fading out results as the step count limit is approached.
IfnumLayers > 1, the index of the layer that was hit.
Deprecated:
See also
traceScreenSpaceRay1

◆ reconstructCSFaceNormal()

vec3 glsl::reconstructFromDepth_glsl::reconstructCSFaceNormal ( vec3  C)
inline

Reconstructs screen-space unit normal from screen-space position.

◆ reconstructCSPosition()

vec3 glsl::reconstructFromDepth_glsl::reconstructCSPosition ( vec2  S,
float  z,
vec4  projInfo 
)
inline

Reconstruct camera-space C.xyz from screen-space S = (x, y) in pixels and camera-space z < 0.

Assumes that the upper-left pixel center is at (0.5, 0.5) [but that need not be the location at which the sample tap was placed!]

Costs 3 MADD. Error is on the order of 10^-3 at the far plane, partly due to z precision.

In C++ (not GLSL, which transposes the matrices!), compute projInfo as

projInfo = Vector4(-2.0f / (width*P[0][0]), -2.0f / (height*P[1][1]), ( 1.0f - P[0][2]) / P[0][0], ( 1.0f - P[1][2]) / P[1][1])

where P is the projection matrix that maps camera space points to [-1, 1] x [-1, 1]. That is, Camera::getProjectUnit().

See also
G3D::Projection::reconstructFromDepthProjInfo

◆ reconstructCSPositionFromDepth()

vec3 glsl::reconstructFromDepth_glsl::reconstructCSPositionFromDepth ( vec2  S,
float  depth,
vec4  projInfo,
vec3  clipInfo 
)
inline

Helper for reconstructing camera-space P.xyz from screen-space S = (x, y) in pixels and hyperbolic depth.

See also
G3D::Projection::reconstructFromDepthClipInfo
G3D::Projection::reconstructFromDepthProjInfo

◆ reconstructCSZ()

float glsl::reconstructFromDepth_glsl::reconstructCSZ ( float  d,
vec3  clipInfo 
)
inline

◆ reconstructNonUnitCSFaceNormal()

vec3 glsl::reconstructFromDepth_glsl::reconstructNonUnitCSFaceNormal ( vec3  C)
inline

◆ reconstructWSPositionFromDepth()

vec3 glsl::reconstructFromDepth_glsl::reconstructWSPositionFromDepth ( vec2  S,
float  depth,
vec4  projInfo,
vec3  clipInfo,
mat4x3  cameraToWorld 
)
inline

Helper for the common idiom of getting world-space position P.xyz from screen-space S = (x, y) in pixels and hyperbolic depth.

◆ worldRay() [1/2]

Ray glsl::reconstructFromDepth_glsl::worldRay ( vec2  pixelPosition,
mat4x3  cameraToWorld,
vec4  projInfo,
out float  csRayZ 
)
inline


Parameters
csRayZis the z component of the camera-space ray direction. It is useful for computing a standard OpenGL depth buffer encoding of the ray hit position:
float csZ = distToHit / csEyeRayDirectionZ;
gl_FragDepth = (distToHit == inf) ? 1.0 : ((projectionMatrix22 * csZ + projectionMatrix23) / -csZ);

◆ worldRay() [2/2]

Ray glsl::reconstructFromDepth_glsl::worldRay ( vec2  pixelPosition,
mat4x3  cameraToWorld,
vec4  projInfo 
)
inline

Given pixel coordinates and camera data (e.g., g3d_CameraToWorldMatrix and g3d_ProjInfo or Camera.frame and Camera.projInfo), returns the world space ray through the pixel position.

Pixel centers are at 0.5.


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