ModelInstance

Description

struct Tinman.Engine.Models.ModelInstance

Describes a single instance when using geometry instancing.

The layout for GPU instance buffers is defined by Format and the WriteInstance can be used to output instance data in that format.

Public / Constants

Format


public static readonly attribute Format → (VertexElements)

The vertex elements to use for instance buffers.

The vertex buffer layout for instance data is defined as follows:

@0  : Float x 3 (Position)
@12 : Float x 3 (Tangent)
@24 : Float x 3 (Tangent)
@36 : UInt8_Norm_Srgb x 4 (Color)
@40 : Float x 1 (TextureCoords)
@44 : Float x 1 (TextureCoords)
@48 : - end -

To write instance data, use the WriteInstance method.

Public / Constructors

Model​Instance

2 overloads


public constructor ModelInstance1 → (4)

position in : Vec3F

See Position.

intensity opt : float32 = 1

See Intensity.

color opt : int64 = Colors.White

See Color.

scale opt : float32 = 1

See Scale.

Creates a new instance of ModelInstance.


public constructor ModelInstance2 → (6)

position in : Vec3F

See Position.

intensity in : float32

See Intensity.

color in : int64

See Color.

scale in : float32

See Scale.

tangent in : Vec3F

See Tangent.

normal in : Vec3F

See Normal.

Creates a new instance of ModelInstance.

Public / Methods

Write


public method Write → (1)

buffer in : ByteBuffer

[not-null]
The output byte buffer.

Writes instance data to the given buffer.

Write​Instance


public static method WriteInstance → (13)

buffer in : ByteBuffer

[not-null]
The output byte buffer.

positionX in : float32

X-coordinate of instance position.

positionY in : float32

Y-coordinate of instance position.

positionZ in : float32

Z-coordinate of instance position.

tangentX opt : float32 = 1

X-component of unit-length side vector.

tangentY opt : float32 = 0

Y-component of unit-length side vector.

tangentZ opt : float32 = 0

Z-component of unit-length side vector.

normalX opt : float32 = 0

X-component of unit-length up vector.

normalY opt : float32 = 1

Y-component of unit-length up vector.

normalZ opt : float32 = 0

Z-component of unit-length up vector.

scale opt : float32 = 1

Uniform instance scale factor.

color opt : int64 = Colors.White

The instance color (low-dynamic range).

intensity opt : float32 = 1

The absolute value is used as the high-dynamic range scale for color opt. The sign decides how the instance position is applied (see remarks).

Writes instance data to the given buffer.

This method will write a full instance, according to Format, including padding for alignment. The instance elements have the same order as the parameters of this method and are applied during rendering as follows:

  • scale
    The vertices in model-space are scaled by the given scale opt factor.

  • rotation
    A 3x3 orthonormal rotation matrix is applied to the scaled vertices in model-space, where the row vectors given by tangentXYZ, normalXYZ and cross(tangentXYZ,normalXYZ).

  • position
    The rotated model-space vertices are translated by the given position offsets, before (if intensity opt is negative) or after (if intensity opt is positive) transforming them from model-space to world-space.

  • color
    After applying ModelPartFlags.VertexAlphaIsOcclusion and ModelPartFlags.VertexColorIsBaseColor, the vertex color is modulated with the given color opt factor (all channels). Then, the color channels are scaled by the given intensity opt factor, to produce high-dynamic range colors.

Public / Attributes

Color


public readonly attribute Color → (int64)

The low-dynamic range color.

The default value is Colors.White.

Intensity


public readonly attribute Intensity → (float32)

The high-dynamic range scale for Color (absolute value) and interpretation of Position (value sign).

The default value is 1.

Normal


public readonly attribute Normal → (Vec3F)

Second component of rotation matrix.

The default value is (0,1,0).

Position


public readonly attribute Position → (Vec3F)

The instance position.

Scale


public readonly attribute Scale → (float32)

Uniform scale factor for geometry.

The default value is 1.

Tangent


public readonly attribute Tangent → (Vec3F)

First component of rotation matrix.

The default value is (1,0,0).