QtCraft API C++ classes QML types Handbook

QcShadowCascades Namespace

The pure parts of the sun shadows (decision E-903): which light casts them, how far each cascade reaches, the light's axes and a box per cascade whose texels stay on a fixed grid of the world (texel snapping), so shadow edges do not crawl while the camera moves. More...

Header: #include <clientcore/light/QcShadowCascades.h>

Classes

struct Basis

Types

Radii

Variables

const float casterReach
const float forwardShift
const int lightSteps
const float moonShare
const QVector3D moonTint
const float splitRatio
const int tiltSteps

Functions

std::optional<QcShadowCascades::Basis> basis(QVector3D toLight)
QcShadowCascade fit(const QcShadowCascades::Basis &axes, const QcVec3 &camera, QVector3D forward, float radius, int resolution)
QcShadowLight light(const QcSkyState &sky)
QcShadowCascades::Radii radii(int count, float distance)
double snapped(double value, double step)
QVector3D stepped(QVector3D toLight)
QMatrix4x4 textureMatrix(bool mirrorY, bool depthZeroToOne)

Detailed Description

Classes

class Basis

The light's axes: right and up span the shadow map, toLight points to the light. More...

Type Documentation

[alias] QcShadowCascades::Radii

The radii of the cascades in blocks, nearest first; unused entries are 0.

Variable Documentation

const float QcShadowCascades::casterReach

Blocks beyond a box towards the light that still cast into it (trees and cliffs above the box).

const float QcShadowCascades::forwardShift

The box's middle lies this share of its radius ahead of the camera: more of the map covers what the camera looks at, and the box still reaches behind it.

const int QcShadowCascades::lightSteps

The shadows turn with the sun and the moon in this many steps per turn (a tenth of a degree, every 0.17 s of a 600 s day, decision E-960): between two steps the shadow map stays the same, so its edges stand still instead of being rasterised anew at a slightly different angle every frame, and a step moves them little.

const float QcShadowCascades::moonShare

The moon's shadows have this share of the sun's strength.

const QVector3D QcShadowCascades::moonTint

The colour of the moonlight on lit surfaces.

const float QcShadowCascades::splitRatio

Each cascade reaches this share of the next one's radius.

const int QcShadowCascades::tiltSteps

The tilt of the light towards z is rounded to this many steps per unit, so that every direction within one step gives the same vector bit for bit.

Function Documentation

std::optional<QcShadowCascades::Basis> QcShadowCascades::basis(QVector3D toLight)

Returns the light's axes for the direction toLight; nothing for a zero, NaN or infinite direction.

QcShadowCascade QcShadowCascades::fit(const QcShadowCascades::Basis &axes, const QcVec3 &camera, QVector3D forward, float radius, int resolution)

Returns the cascade of radius along the light's axes for a camera at camera (world) looking along forward, rendered into a tile of resolution texels: its middle is moved onto the texel grid of the world along all three axes, in double precision (the camera may be far out, decision E-883), so a point of the world keeps its texel and its depth in the map while the camera moves (decision E-960).

QcShadowLight QcShadowCascades::light(const QcSkyState &sky)

Returns the light of the moment sky: the sun while it stands above the horizon, else the moon, its direction stepped(); the strength and the tint follow the light's height without steps.

QcShadowCascades::Radii QcShadowCascades::radii(int count, float distance)

Returns the radius of each of count cascades, nearest first, the last one distance, in the first count entries (the others 0); all 0 for a count outside 1..maxShadowCascades or a distance that is not positive and finite.

double QcShadowCascades::snapped(double value, double step)

Returns value rounded to the nearest multiple of step (step > 0).

QVector3D QcShadowCascades::stepped(QVector3D toLight)

Returns the unit direction of toLight turned about the z axis (the axis of the sun's and the moon's path) to the nearest of the lightSteps steps, its z rounded to tiltSteps: every direction within one step gives the same vector bit for bit. Returns toLight itself when it is zero or not finite.

QMatrix4x4 QcShadowCascades::textureMatrix(bool mirrorY, bool depthZeroToOne)

Returns the matrix that maps the backend's clip space of a shadow pass (after QRhi::clipSpaceCorrMatrix()) to texture coordinates of its depth texture: x, y in 0..1 over the tile, z the stored depth. mirrorY when the texture's v runs against clip y (QRhi::isYUpInFramebuffer() != QRhi::isYUpInNDC(): Metal, Direct3D); depthZeroToOne when the clip depth runs from 0 to 1.