-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new vertex attribute to the pipelined custom shader example
- Loading branch information
Showing
2 changed files
with
85 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,43 @@ | ||
#import bevy_pbr::mesh_view_bind_group | ||
#import bevy_pbr::mesh_struct | ||
|
||
struct Vertex { | ||
[[location(0)]] position: vec3<f32>; | ||
[[location(1)]] normal: vec3<f32>; | ||
[[location(2)]] uv: vec2<f32>; | ||
[[location(3)]] color: vec4<f32>; | ||
}; | ||
|
||
struct VertexOutput { | ||
[[builtin(position)]] clip_position: vec4<f32>; | ||
[[location(0)]] color: vec4<f32>; | ||
}; | ||
|
||
[[group(2), binding(0)]] | ||
var<uniform> mesh: Mesh; | ||
|
||
[[stage(vertex)]] | ||
fn vertex(vertex: Vertex) -> VertexOutput { | ||
let world_position = mesh.model * vec4<f32>(vertex.position, 1.0); | ||
|
||
var out: VertexOutput; | ||
out.clip_position = view.view_proj * world_position; | ||
out.color = vertex.color; | ||
return out; | ||
} | ||
|
||
[[block]] | ||
struct CustomMaterial { | ||
color: vec4<f32>; | ||
}; | ||
[[group(1), binding(0)]] | ||
var<uniform> material: CustomMaterial; | ||
|
||
struct FragmentInput { | ||
[[location(0)]] color: vec4<f32>; | ||
}; | ||
|
||
[[stage(fragment)]] | ||
fn fragment() -> [[location(0)]] vec4<f32> { | ||
return material.color; | ||
fn fragment(fragment: FragmentInput) -> [[location(0)]] vec4<f32> { | ||
return (material.color + fragment.color) / 2.0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters