TextureTile

Description

struct Tinman.Terrain.Rendering.TextureTile

Represents a texture tile in a texture atlas.

In order to get correct texture coordinates, the following steps must be performed:

  1. Provide per-vertex texture coordinates (e.g. by using VertexFormat.HeightmapCoordinates).

  2. Call TextureAtlas.TileLookup to check if a tile texture is available for the given pyramid tile coordinates.

  3. Call TextureAtlas.TileSetup to obtain the texturing coefficient vectors Offset, U and V.

  4. Render geometry separately per cubemap face.

  5. Use the following formulae to transform cubemap texture coordinates X, Y and Z to tile texture coordinates S and T:

    S := ([X, Y, Z] * U + Offset.X) + Offset.Z
    T := ([X, Y, Z] * V + Offset.Y) + Offset.W

    The Vec4F.Z and Vec4F.W components of Offset hold the float delta of Vec4F.X resp. Vec4F.Y (see VertexFormat.FloatDelta). On the CPU, tile texture coordinates can be computed by using one of the Compute methods.

  6. Clamp S and T to Bounds in order to avoid color bleeding at the tile edges:

    Bounds.X <= S <= Bounds.Y
    Bounds.Z <= T <= Bounds.W

    Clamping should be done on the GPU to avoid distortions between vertex positions and texture coordinates.

The formulae above are free of precision issues as long as the GPU is capable of handling at least 24 effective floating-point mantissa bits during vertex processing.

Public / Constants

None


public static readonly attribute None → (TextureTile)

The TextureTile value that represents a non-existent texture tile.

Public / Methods

Compute

4 overloads


[Pure]
public method Compute1 → (2)

coords in : Vec3I

Cubemap coordinates.

opt : int32 = MappingUtil.MaxSize

Maximum cubemap coordinate.

returns → Vec2F

The texture tile coordinates.

Computes texture tile coordinates S and T.


[Pure]
public method Compute2 → (4)

in : int32

Cubemap X-coordinate.

in : int32

Cubemap Y-coordinate.

in : int32

Cubemap Z-coordinate.

opt : int32 = MappingUtil.MaxSize

Maximum cubemap coordinate.

returns → Vec2F

The texture tile coordinates.

Computes texture tile coordinates S and T.


[Pure]
public method Compute3 → (1)

coords in : Vec3D

Cubemap coordinates, in the range [0..1].

returns → Vec2F

The texture tile coordinates.

Computes texture tile coordinates S and T.


[Pure]
public method Compute4 → (3)

in : float64

Cubemap X-coordinate, in the range [0..1].

in : float64

Cubemap Y-coordinate, in the range [0..1].

in : float64

Cubemap Z-coordinate, in the range [0..1].

returns → Vec2F

The texture tile coordinates.

Computes texture tile coordinates S and T.

Public / Attributes

Bounds


public readonly attribute Bounds → (Vec4F)

Output texturing coefficient vector (see remarks).

Gamma


public readonly attribute Gamma → (float32)

The gamma correction to apply on the GPU.

After sampling Texture, the following computation must be performed on the GPU:

output.rgb = pow(input.rgb, Gamma);

where input is the texture sample and output is the tuple that will be further processed by the GPU shader. Usually, Gamma will be 1, i.e. GPU texture sampling and CPU texture encoding use the same sRGB behaviour. Different behaviour will result when a texture atlas holds texture tiles that have been encoded with different sRGB behaviour flags.

Offset


public readonly attribute Offset → (Vec4F)

Output texturing coefficient vector (see remarks).

Slice


public readonly attribute Slice → (int32)

The texture slice to use or -1 if the texture for the given pyramid tile is not ready yet or does not exist.

Texture


public readonly attribute Texture → (ITexture2D)

The texture to use or null if the texture for the given pyramid tile is not ready yet or does not exist.

U


public readonly attribute U → (Vec3F)

Output texturing coefficient vector (see remarks).

V


public readonly attribute V → (Vec3F)

D Output texturing coefficient vector (see remarks).