Skip to main content

LitShader

Struct LitShader 

Source
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 world there, 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 color there, 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

Source

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.

Source

pub fn label(&self) -> &str

The name this shader is reported under.

Source

pub fn module(&self) -> &str

The WESL declarations spliced in at module scope.

Source

pub fn vertex(&self) -> &str

The WESL statements spliced into the vertex stage.

Source

pub fn fragment(&self) -> &str

The WESL statements spliced into the fragment stage.

Trait Implementations§

Source§

impl Clone for LitShader

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LitShader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Prints the label and each snippet’s length rather than the snippets themselves, so an LitOptions dump stays readable.

Source§

impl Eq for LitShader

Source§

impl Hash for LitShader

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for LitShader

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LitShader

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AsId for T
where T: Hash + Debug,

§

impl<T> AsIdSalt for T
where T: Hash + Debug,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more