QtCraft API C++ classes QML types Handbook

QcAlphaCoverage Namespace

Keeps cut-out textures (leaves, plants, torches) the same density in every mip level (decision E-300). More...

Header: #include <clientcore/textures/QcAlphaCoverage.h>

Variables

const int cutoff

Functions

void fillTransparentColour(QImage &tile)
bool hasTexelBelowCutoff(const QImage &tile)
void keep(QImage &level, QcAtlasLayout layout, const QList<double> &coverage, int tileSize)
QList<double> measure(const QImage &level, QcAtlasLayout layout, qsizetype tiles, int tileSize)

Detailed Description

Averaging alpha makes thin shapes fade below the shader's cut-off (they vanish in the distance). Per tile and level, the alpha is raised so that the share of texels the shader draws comes back to that of level 0 (coverage scaling as in CastaƱo's "Computing alpha mipmaps", only upwards, so holes filled by averaging stay: leaves get a little denser, thin shapes do not vanish). Translucent tiles (glass, water) are left alone.

Variable Documentation

const int QcAlphaCoverage::cutoff

The shader discards texels with alpha below 0.1.

Function Documentation

void QcAlphaCoverage::fillTransparentColour(QImage &tile)

Gives every fully transparent texel of tile (RGBA8888) the colour of the nearest drawn one, alpha staying 0 (decision E-332). The GPU blends neighbouring mip levels without regard to alpha: a transparent black texel next to a leaf or a blade of grass darkened its edge in the distance. A tile without any drawn texel stays as it is. Deterministic: at equal distance the colour that spreads first wins, and spreading starts from the drawn texels in reading order (row by row), so a texel right between two drawn ones takes the colour of the one above or to the left.

bool QcAlphaCoverage::hasTexelBelowCutoff(const QImage &tile)

Returns true when tile (RGBA8888) has a texel the shader would discard (alpha below the cut-off): such a texture must not be used by a block of the opaque layer, which is drawn without alpha test (decision E-756).

void QcAlphaCoverage::keep(QImage &level, QcAtlasLayout layout, const QList<double> &coverage, int tileSize)

Raises the alpha of every cut-out tile's cell (gutter included) in level, whose tiles are tileSize pixels in layout, until its share of drawn texels reaches coverage.

QList<double> QcAlphaCoverage::measure(const QImage &level, QcAtlasLayout layout, qsizetype tiles, int tileSize)

Returns per tile of level (tiles tiles of tileSize pixels in layout) the share of texels at or above the cut-off for cut-out tiles (alpha only 0 or 255, with at least one transparent texel), -1 for all others.