candlewick 0.1.0
A renderer
Loading...
Searching...
No Matches
Depth Pre-Pass and Shadow Mapping Systems

Classes

class  candlewick::DepthPass
 Helper struct for depth or light pre-passes. More...
 
class  candlewick::ShadowMapPass
 Helper struct for shadow mapping pass. More...
 
void candlewick::renderShadowPassFromAABB (CommandBuffer &cmdBuf, ShadowMapPass &passInfo, const DirectionalLight &dirLight, std::span< const OpaqueCastable > castables, const AABB &worldSceneBounds)
 Render shadow pass, using provided scene bounds.
 
void candlewick::renderShadowPassFromFrustum (CommandBuffer &cmdBuf, ShadowMapPass &passInfo, const DirectionalLight &dirLight, std::span< const OpaqueCastable > castables, const FrustumCornersType &worldSpaceCorners)
 Render shadow pass, using a provided world-space frustum.
 
Mat4f candlewick::shadowOrthographicMatrix (const Float2 &sizes, float zMin, float zMax)
 Orthographic matrix which maps to the negative-Z half-volume of the NDC cube, for depth-testing/shadow mapping purposes.
 

Detailed Description

Requirements for consistent depth testing between

passes.

When using a depth pre-pass with EQUAL depth comparison in the main pass, ensure identical vertex transformations between passes by:

  1. Computing the MVP matrix on CPU side
  2. Using the same MVP matrix in both pre-pass and main pass shaders
  3. Avoiding shader-side matrix multiplication that might cause precision differences.

Failing to do this can result in z-fighting/Moiré patterns due to floating-point precision differences between CPU and GPU matrix calculations.

Rendering the depth buffer after early pass

Depth testing in modern APIs

SDL GPU is based on modern graphics APIs like Vulkan, which tests depths for objects located in the \(z \in [-1,0]\) half-volume of the NDC cube. This means that to get your geometry rendered to a shadow map, the light space projection matrix needs to map everything to this half-volume.

See also
shadowOrthographicMatrix()

Function Documentation

◆ renderShadowPassFromAABB()

void candlewick::renderShadowPassFromAABB ( CommandBuffer & cmdBuf,
ShadowMapPass & passInfo,
const DirectionalLight & dirLight,
std::span< const OpaqueCastable > castables,
const AABB & worldSceneBounds )

Render shadow pass, using provided scene bounds.

The scene bounds are in world-space.

◆ renderShadowPassFromFrustum()

void candlewick::renderShadowPassFromFrustum ( CommandBuffer & cmdBuf,
ShadowMapPass & passInfo,
const DirectionalLight & dirLight,
std::span< const OpaqueCastable > castables,
const FrustumCornersType & worldSpaceCorners )

Render shadow pass, using a provided world-space frustum.

This routine creates a bounding sphere around the frustum, and compute light-space view and projection matrices which will enclose this bounding sphere within the light volume. The frustum can be obtained from the world-space camera.

See also
frustumFromCameraProjection()

◆ shadowOrthographicMatrix()

Mat4f candlewick::shadowOrthographicMatrix ( const Float2 & sizes,
float zMin,
float zMax )
inline

Orthographic matrix which maps to the negative-Z half-volume of the NDC cube, for depth-testing/shadow mapping purposes.

This matrix maps a rectangular cuboid centered on the xy-plane and spanning from zMin to zMax in Z-direction, to the negative-Z half-volume of the NDC cube. This is useful for mapping an axis-aligned bounding-box (AABB) to an orthographic projection where the entire box is in front of the camera.

https://en.wikipedia.org/wiki/Rectangular_cuboid

Parameters
sizesxy-plane dimensions of the cuboid/bounding box.
zMinview-space Z-coordinate the box starts at, equivalent to the near argument in other routines.
zMaxview-space Z-coordinate the box ends at, equivalent to far in other routines.