pub struct RuntimeShader { /* private fields */ }Expand description
A custom WGSL shader effect, analogous to Android’s RuntimeShader.
The shader source must be a complete WGSL module that declares:
@group(0) @binding(0) var input_texture: texture_2d<f32>;
@group(0) @binding(1) var input_sampler: sampler;
@group(1) @binding(0) var<uniform> u: array<vec4<f32>, 64>;Float uniforms are packed linearly into the u array. Access them in WGSL
as u[index / 4][index % 4] for individual floats, or u[index / 4].xy
for vec2, etc. User uniforms may use indices 0..248; slots 248..256
are reserved for renderer metadata.
RuntimeShader pipelines operate on premultiplied-alpha textures. Custom shaders should preserve premultiplied output semantics.
Implementations§
Source§impl RuntimeShader
impl RuntimeShader
Sourcepub const MAX_UNIFORMS: usize = 256
pub const MAX_UNIFORMS: usize = 256
Total uniform storage size in floats (64 vec4s = 256 floats).
The final slots are reserved for renderer-managed data.
Sourcepub const RESERVED_UNIFORM_START: usize = 248
pub const RESERVED_UNIFORM_START: usize = 248
First renderer-reserved uniform slot.
Sourcepub const MAX_USER_UNIFORMS: usize = Self::RESERVED_UNIFORM_START
pub const MAX_USER_UNIFORMS: usize = Self::RESERVED_UNIFORM_START
Maximum user-addressable uniform count.
Sourcepub fn new(wgsl_source: &str) -> RuntimeShader
pub fn new(wgsl_source: &str) -> RuntimeShader
Create a new RuntimeShader from WGSL source code.
Sourcepub fn set_float(&mut self, index: usize, value: f32)
pub fn set_float(&mut self, index: usize, value: f32)
Set a single float uniform at the given index.
Sourcepub fn set_float2(&mut self, index: usize, x: f32, y: f32)
pub fn set_float2(&mut self, index: usize, x: f32, y: f32)
Set a vec2 uniform at the given index (consumes indices [index, index+1]).
Sourcepub fn set_float4(&mut self, index: usize, x: f32, y: f32, z: f32, w: f32)
pub fn set_float4(&mut self, index: usize, x: f32, y: f32, z: f32, w: f32)
Set a vec4 uniform at the given index (consumes indices [index..index+4]).
Sourcepub fn uniforms_padded(&self) -> [f32; 256]
pub fn uniforms_padded(&self) -> [f32; 256]
Get the uniform data padded to full 256-float array (for GPU uniform buffer).
Sourcepub fn source_hash(&self) -> u64
pub fn source_hash(&self) -> u64
Compute a hash of the shader source for pipeline caching.
Trait Implementations§
Source§impl Clone for RuntimeShader
impl Clone for RuntimeShader
Source§fn clone(&self) -> RuntimeShader
fn clone(&self) -> RuntimeShader
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more