Skip to main content

Module shader_values

Module shader_values 

Source
Expand description

The values a style’s or a post effect’s WGSL reads, and the WGSL struct it reads them through.

#[derive(ShaderValues)] over a struct writes both: the WGSL that declares them, and the bytes laid out where that WGSL reads each field. The WGSL struct takes the Rust type’s own name, each field takes its own name, and the fields keep the order they were written in; what padding the shader’s own layout calls for is the derive’s, not the game’s.

RustWGSL
f32f32
u32u32
Vec2vec2<f32>
Vec3vec3<f32>
Vec4vec4<f32>
Mat4mat4x4<f32>
Colorvec4<f32>, linear red, green, blue and alpha

A field of any other type does not compile. A type with no fields reads no values and binds none.

use mirage_engine::prelude::*;

#[derive(Default, ShaderValues)]
struct Water {
    wave: f32,
    tint: Color,
}

declares struct Water { wave: f32, tint: vec4<f32> }, which a style reads as style and an effect as effect. Default is derived here because a SurfaceStyle requires it — a frame that passes a style no values draws with the default of every field — where a PostEffect does not, since an effect no frame submits never runs.

Traits§

ShaderValues
The values one style’s or one post effect’s WGSL reads. Written by ShaderValues on a struct of f32, u32, Vec2, Vec3, Vec4, Mat4 and Color fields.