pub struct LitShader {
label: Arc<str>,
module: Arc<str>,
vertex: Arc<str>,
fragment: Arc<str>,
}Expand description
A caller’s own shader code, spliced into the built-in lit.wesl.
The built-in entry shader keeps three marks, each a comment naming the place it sits: one at module scope, one at the end of the vertex stage and one at the end of the fragment stage. A shader is spliced in at those marks while the module is still WESL, before anything is compiled, so each snippet is ordinary WESL: it sees every binding, flag and helper the place it lands in sees, it takes part in the conditional compilation, and its diagnostics point at the line it was written on rather than at a fragment of generated WGSL.
The marks sit where the shader still has something left to do, which is what keeps a snippet short:
- The module mark is after every built-in binding, so a snippet can declare the functions, types and constants the stages call, and read the built-in bindings from them.
- The vertex mark is after the instance transform, before the clip position
is built. The vertex is a
var worldthere, and everything downstream — the clip position, the world position the lights are addressed from, the normal and the cluster cell — follows the vertex the snippet leaves. - The fragment mark is after the base color is lit and cut off, before the
target’s encoding. The color is a
var colorthere, so a snippet can rewrite it in place, and what it leaves is what the target receives.
The layouts and the vertex streams stay the variant’s, exactly as they are for the built-in shader: a snippet changes what a stage computes, not what the variant reads. A snippet that declares a binding of its own therefore fails pipeline creation rather than drawing something else; one that declares functions, types or constants over the bindings every variant of that shape already declares works.
The label names the shader: it is the shader module’s label, and a composition error is reported under it.
Fields§
§label: Arc<str>§module: Arc<str>§vertex: Arc<str>§fragment: Arc<str>Implementations§
Source§impl LitShader
impl LitShader
Sourcepub fn new(
label: impl Into<Arc<str>>,
module: impl Into<Arc<str>>,
vertex: impl Into<Arc<str>>,
fragment: impl Into<Arc<str>>,
) -> Self
pub fn new( label: impl Into<Arc<str>>, module: impl Into<Arc<str>>, vertex: impl Into<Arc<str>>, fragment: impl Into<Arc<str>>, ) -> Self
A shader named label whose module, vertex and fragment snippets
are spliced into the built-in entry shader.
Any snippet may be empty, which leaves its place exactly as the built-in shader has it.
Trait Implementations§
impl Eq for LitShader
impl StructuralPartialEq for LitShader
Auto Trait Implementations§
impl Forget for LitShader
impl Freeze for LitShader
impl RefUnwindSafe for LitShader
impl Send for LitShader
impl Sync for LitShader
impl Unpin for LitShader
impl UnsafeUnpin for LitShader
impl UnwindSafe for LitShader
Blanket Implementations§
impl<T> AsId for T
impl<T> AsIdSalt for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more