QtCraft API C++ classes QML types Handbook

QcRenderOrigin Namespace

Camera-relative rendering (decision E-883). More...

Header: #include <clientcore/camera/QcRenderOrigin.h>

Variables

const double anchorReach
const int hashPeriod

Functions

QcVec3 blockNear(const QcVec3 &position)
QVector4D entry(const QcVec3 &origin, const QcVec3 &anchor, float cell = 0.0f)
bool outOfReach(const QcVec3 &anchor, const QcVec3 &camera)
float sectionCell(QcBlockPos corner)
QcVec3 toVec3(QcBlockPos pos)

Detailed Description

Geometry is stored relative to an origin of its own (a chunk section's corner, the place an entity mesh was built around), in floats that stay small; each draw takes the origin's offset from the render anchor, a whole block near the camera, subtracted here in double, as one per-instance entry (whole numbers for sections: exact). The shaders add it to every vertex and subtract the camera's offset from the anchor (one uniform per frame), so the GPU sees positions relative to the camera, as exact far from the world's origin as near it, and the view matrix is the camera's rotation alone (QcCamera::viewRotation). The entries change only when the anchor moves (QcDrawOrigins).

Variable Documentation

const double QcRenderOrigin::anchorReach

How far the camera may move from the render anchor along any axis before the anchor follows it. Small enough that a vertex near the camera, its section's offset from the anchor plus its place in the section, stays a float of a few hundred at most (error below 2e-5 blocks); large enough that the entries are rewritten only every 128 blocks of travel.

const int QcRenderOrigin::hashPeriod

The world coordinates the shaders' hashes see (the corner shading of leaves) repeat after this many blocks: the section's corner modulo the period goes with the entry, exact in a float.

Function Documentation

QcVec3 QcRenderOrigin::blockNear(const QcVec3 &position)

Returns the whole block containing position: an origin near it for geometry built around a point.

QVector4D QcRenderOrigin::entry(const QcVec3 &origin, const QcVec3 &anchor, float cell = 0.0f)

Returns the entry of a draw: xyz the offset of origin from anchor (float, from the difference in double), w cell, the packed corner of a section for the hashes (sectionCell(), 0 for other geometry).

bool QcRenderOrigin::outOfReach(const QcVec3 &anchor, const QcVec3 &camera)

Returns whether camera has left the reach of anchor along any axis.

float QcRenderOrigin::sectionCell(QcBlockPos corner)

Returns the section's corner modulo hashPeriod, in sixteens of a block along each axis packed as x + 64 y + 4096 z (a whole number below 2^18, exact in a float); the block shader unpacks it.

[constexpr] QcVec3 QcRenderOrigin::toVec3(QcBlockPos pos)

Returns the block corner pos as a QcVec3.