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.
| Rust | WGSL |
|---|---|
f32 | f32 |
u32 | u32 |
Vec2 | vec2<f32> |
Vec3 | vec3<f32> |
Vec4 | vec4<f32> |
Mat4 | mat4x4<f32> |
Color | vec4<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§
- Shader
Values - The values one style’s or one post effect’s WGSL reads. Written by
ShaderValueson a struct off32,u32,Vec2,Vec3,Vec4,Mat4andColorfields.