pub struct Shader { /* private fields */ }
Expand description
A custom shader that can be used to render with shader effects.
The shader may have a user specified vertex module, fragment module, both,
or neither. The fragment module entry point must be named fs_main
. The
vertex module entry point must be named vs_main
. The vertex module must
have an output of type
struct VertexOutput {
@builtin(position) position: vec4<f32>,
@location(0) uv: vec2<f32>,
@location(1) color: vec4<f32>,
}
if the fragment module is left unspecified (default).
Produce a Shader using ShaderBuilder
.
Adapted from the shader.rs
example:
use ggez::*;
use ggez::graphics::*;
use crevice::std140::AsStd140;
#[derive(AsStd140)]
struct Dim {
rate: f32,
}
struct MainState {}
impl event::EventHandler for MainState {
fn draw(&mut self, ctx: &mut Context) -> GameResult {
let mut canvas = graphics::Canvas::from_frame(ctx, Color::BLACK);
let dim = Dim { rate: 0.5 };
// NOTE: This is for simplicity; do not recreate your shader every frame like this!
// For more info look at the full example.
let shader = ShaderBuilder::new()
.fragment_code(include_str!("../../resources/dimmer.wgsl"))
.build(&mut ctx.gfx)?;
let mut params = ShaderParamsBuilder::new(&dim).build(ctx);
params.set_uniforms(ctx, &dim);
canvas.set_shader(&shader);
canvas.set_shader_params(¶ms);
// draw something...
canvas.finish(ctx)
}
/* ... */
}
Trait Implementations§
source§impl PartialEq<Shader> for Shader
impl PartialEq<Shader> for Shader
impl Eq for Shader
impl StructuralEq for Shader
impl StructuralPartialEq for Shader
Auto Trait Implementations§
impl !RefUnwindSafe for Shader
impl Send for Shader
impl Sync for Shader
impl Unpin for Shader
impl !UnwindSafe for Shader
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
Mutably borrows from an owned value. Read more
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
source§impl<T> HasMut<T> for T
impl<T> HasMut<T> for T
source§fn retrieve_mut(&mut self) -> &mut T
fn retrieve_mut(&mut self) -> &mut T
Method to retrieve the context type as mutable.