pub struct Material { /* private fields */ }Expand description
A user fragment shader and the parameters it takes.
fragment is WGSL: any helper functions and constants, and one function
fn material(in: MaterialInput, p: Params) -> vec4<f32> that returns the premultiplied
color of a fully covered pixel. Params is generated from the schema declared with
param; MaterialInput and the helpers (widget_color,
backdrop_blurred, …) come from the library prelude documented in
docs/content/docs/materials.mdx. Register a description with
Context::register_material and draw with
Ui::material.
use zaxis::{Material, ParamKind};
let material = Material::new("pulse", r#"
fn material(in: MaterialInput, p: Params) -> vec4<f32> {
let wave = 0.5 + 0.5 * sin(in.time * 2.0 + in.uv.x * 6.0);
return premultiply(vec4<f32>(mix(p.low.rgb, p.high.rgb, wave), 1.0));
}
"#)
.param("low", ParamKind::Color)
.param("high", ParamKind::Color)
.animated();
assert_eq!(material.label(), "pulse");A shader that loops forever hangs the GPU for as long as the driver allows; keeping loops bounded is the author’s responsibility.
Implementations§
Source§impl Material
impl Material
Sourcepub fn new(label: impl Into<Arc<str>>, fragment: impl Into<String>) -> Self
pub fn new(label: impl Into<Arc<str>>, fragment: impl Into<String>) -> Self
A material called label (shown in errors and diagnostics only) with the WGSL
fragment source. Without further calls it takes no parameters, ignores the widget
texture and the backdrop, and does not depend on time.
Sourcepub fn param(self, name: impl Into<String>, kind: ParamKind) -> Self
pub fn param(self, name: impl Into<String>, kind: ParamKind) -> Self
Declare a parameter. Declaration order is the order of Params members.
Sourcepub fn reads_texture(self) -> Self
pub fn reads_texture(self) -> Self
The material samples the widget texture (an image given to the draw).
Sourcepub fn reads_backdrop(self) -> Self
pub fn reads_backdrop(self) -> Self
The material reads what was drawn behind it with backdrop_sharp or
backdrop_blurred. Its draws go through the backdrop path of blur effects: they
cost a copy and a blur of the area behind, and are never merged with other draws.
Sourcepub fn animated(self) -> Self
pub fn animated(self) -> Self
The result depends on in.time. While a draw of it is visible the window keeps
asking for frames; without this the time inputs are zero and a still window stays
still.
pub fn label(&self) -> &str
pub fn fragment(&self) -> &str
pub fn params(&self) -> &[(String, ParamKind)]
Trait Implementations§
impl Eq for Material
impl StructuralPartialEq for Material
Auto Trait Implementations§
impl Freeze for Material
impl RefUnwindSafe for Material
impl Send for Material
impl Sync for Material
impl Unpin for Material
impl UnsafeUnpin for Material
impl UnwindSafe for Material
Blanket Implementations§
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,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.