Builtin Library
- ..
- README.md2.2 KB
- module.wgsl28.9 KB
README.md
engine_bindings
The single declaration of the renderer's group(0) interface: the per-frame camera and lighting uniforms, the instance and transform storage buffers, the shadow maps and the structs behind them.
A surface shader receives these implicitly through the engine's own scaffolding. Include it directly when a shader needs raw access to a binding the scaffolding does not surface.
#include "@builtin::shaderModules.engine_bindings"
Its layout tracks the group(0) bind group layout the renderer builds and the Rust-side GPU structs; a binding change lands here once rather than in every shader.
Half precision
zero_half, zero_half2, zero_half3 and zero_half4 are the types a shader
computes a value in when 16 bits hold it: a colour, a BRDF term, a cosine. A
device that runs 16-bit shader arithmetic for the engine (an Android GPU that
grants it) compiles them as f16, at twice the rate and in half the registers,
and every other device as f32. Code written against them compiles either
way: a value crosses into them through zero_half(...) / zero_half3(...)
and back to full precision through f32(...) / vec3<f32>(...), and a
literal takes the type it is used with.
f16 holds magnitudes up to 65504 with about three significant digits, so
positions, depths, texture coordinates, light radiance and anything else
unbounded stay f32. The compile gate checks a shader whose code names these
types, or calls a library function that takes or returns them, in both forms,
so a value handed across without its conversion is refused when the shader is
saved.
Per-instance records
The scene buffer at binding 3 carries a header, one record per render slot, and the material table's regions, read through four accessors rather than through the buffer's words directly:
zero_object_matrix(slot) -> mat4x4<f32>— the slot's world transform.zero_prev_object_matrix(slot) -> mat4x4<f32>— the world transform the slot had one frame ago.zero_normal_matrix(slot) -> mat3x3<f32>— the inverse-transpose of the slot's world 3×3.zero_instance(slot) -> ZeroInstance—node_offset,joint_offset,material_index,flags,deform_base,deform_bounds_base.