Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Render Phase Example #9126

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,17 @@ description = "A compute shader that simulates Conway's Game of Life"
category = "Shaders"
wasm = false

[[example]]
name = "custom_render_phase"
path = "examples/shader/custom_render_phase.rs"

[package.metadata.example.custom_render_phase]
name = "Custom Render Phase"
description = "An example showcasing how to set up a custom render phase and draw command"
category = "Shaders"
wasm = false


[[example]]
name = "array_texture"
path = "examples/shader/array_texture.rs"
Expand Down
33 changes: 33 additions & 0 deletions assets/shaders/custom_draw.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#import bevy_pbr::mesh_functions as mesh_functions
#import bevy_pbr::{
mesh_types::Mesh,
view_transformations,
forward_io::Vertex,
}
#import bevy_render::view::View

@group(0) @binding(0) var<uniform> view: View;
@group(1) @binding(0) var<uniform> mesh: Mesh;

struct CustomMaterial {
color: vec4<f32>,
};
@group(2) @binding(0) var<uniform> material: CustomMaterial;

struct VertexOutput {
@builtin(position) position: vec4<f32>,
}

@vertex
fn vertex(vertex: Vertex) -> VertexOutput {
var out: VertexOutput;
let model = mesh_functions::get_model_matrix(vertex.instance_index);
let world_position = mesh_functions::mesh_position_local_to_world(model, vec4<f32>(vertex.position, 1.0));
out.position = view_transformations::position_world_to_clip(world_position.xyz);
return out;
}

@fragment
fn fragment() -> @location(0) vec4<f32> {
return material.color;
}
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ Example | Description
[Animated](../examples/shader/animate_shader.rs) | A shader that uses dynamic data like the time since startup
[Array Texture](../examples/shader/array_texture.rs) | A shader that shows how to reuse the core bevy PBR shading functionality in a custom material that obtains the base color from an array texture.
[Compute - Game of Life](../examples/shader/compute_shader_game_of_life.rs) | A compute shader that simulates Conway's Game of Life
[Custom Render Phase](../examples/shader/custom_render_phase.rs) | An example showcasing how to set up a custom render phase and draw command
[Custom Vertex Attribute](../examples/shader/custom_vertex_attribute.rs) | A shader that reads a mesh's custom vertex attribute
[Extended Material](../examples/shader/extended_material.rs) | A custom shader that builds on the standard material
[Instancing](../examples/shader/shader_instancing.rs) | A shader that renders a mesh multiple times in one draw call
Expand Down
Loading