Yotsuba Shader
Documentation

Tutorial

Vectors, matrices and arrays

Use scalars, vectors, matrices, structs and arrays in a shader, and learn how each C# type becomes a GPU type.

Scalars and vectors#

The current storage processor recognizes bool, int, uint, float, and double, plus types carrying vector mapping attributes. Vector components can be float, int, or uint; all components must have the same type.

Types.cs
using YotsubaShader.Language.Native.Types.Matrix;
using YotsubaShader.Language.Native.Types.Vector;

// Your project's own types, mapped to native GPU types with attributes.
// The same structs can be used by your CPU code and by your shaders.

[Vector]
public struct Vector2
{
    [VectorComponent(0)] public float X;
    [VectorComponent(1)] public float Y;

    public Vector2(float x, float y) { X = x; Y = y; }
}

[Vector]
public struct Vector3
{
    [VectorComponent(0)] public float X;
    [VectorComponent(1)] public float Y;
    [VectorComponent(2)] public float Z;

    public Vector3(float x, float y, float z) { X = x; Y = y; Z = z; }
}

[Vector]
public struct Vector4
{
    [VectorComponent(0)] public float X;
    [VectorComponent(1)] public float Y;
    [VectorComponent(2)] public float Z;
    [VectorComponent(3)] public float W;

    public Vector4(float x, float y, float z, float w) { X = x; Y = y; Z = z; W = w; }
}

[Vector]
public struct UInt3
{
    [VectorComponent(0)] public uint X;
    [VectorComponent(1)] public uint Y;
    [VectorComponent(2)] public uint Z;
}

[Matrix]
public struct Matrix4
{
    [MatrixColumn(0)] public Vector4 Column0;
    [MatrixColumn(1)] public Vector4 Column1;
    [MatrixColumn(2)] public Vector4 Column2;
    [MatrixColumn(3)] public Vector4 Column3;
}

Matrices and arrays#

MatrixAttribute, MatrixColumnAttribute, and the IR matrix and array records exist. Matrix annotations describe column vectors. The current Roslyn storage path does not implement a complete native matrix or array mapping; documentation comments on IR array shapes are design intent, not a support list.

Unannotated structs are inspected recursively, skipping static members, implicitly declared members, and indexers. This type inspection does not implement arbitrary C# methods, operators, allocations, or managed collections on the GPU.

Copyright © 2026 Yotsuba Shader contributors · Licensing · GitHub