Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
IceSentry committed Jan 15, 2024
1 parent aeab690 commit c98df11
Show file tree
Hide file tree
Showing 4 changed files with 512 additions and 0 deletions.
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
36 changes: 36 additions & 0 deletions assets/shaders/custom_draw.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#import bevy_pbr::mesh_functions as mesh_functions
#import bevy_render::view View
#import bevy_pbr::mesh_types Mesh

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

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

@group(2) @binding(0)
var<uniform> mesh: Mesh;

struct Vertex {
@location(0) position: vec3<f32>,
};

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

@vertex
fn vertex(vertex: Vertex) -> VertexOutput {
var out: VertexOutput;
let world_position = mesh_functions::mesh_position_local_to_world(mesh.model, vec4(vertex.position, 1.0));
out.position = mesh_functions::mesh_position_world_to_clip(world_position);
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

0 comments on commit c98df11

Please sign in to comment.