-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add example showing how to use SpecializedMeshPipeline #14370
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
Merged
alice-i-cecile
merged 10 commits into
bevyengine:main
from
IceSentry:specalized_mesh_pipeline_example
Jul 31, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e830abf
Add example showing how to use SpecializedMeshPipeline
IceSentry 2ea2ae3
fix typo
IceSentry 3e413a3
update examples readme
IceSentry 8d8a3ef
update queue function name
IceSentry eefe27f
update msaa doc
IceSentry 4b0c97c
Add shader doc
IceSentry 57bb538
Merge branch 'main' into specalized_mesh_pipeline_example
IceSentry 056ae15
Merge branch 'main' into specalized_mesh_pipeline_example
alice-i-cecile d32ab31
Merge remote-tracking branch 'upstream/main' into specalized_mesh_pip…
IceSentry 59e65b4
fix msaa
IceSentry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| //! Very simple shader used to demonstrate how to get the world position and pass data | ||
| //! between the vertex and fragment shader. Also shows the custom vertex layout. | ||
|
|
||
| // First we import everything we need from bevy_pbr | ||
| // A 2d shader would be vevry similar but import from bevy_sprite instead | ||
| #import bevy_pbr::{ | ||
| mesh_functions, | ||
| view_transformations::position_world_to_clip | ||
| } | ||
|
|
||
| struct Vertex { | ||
| // This is needed if you are using batching and/or gpu preprocessing | ||
| // It's a built in so you don't need to define it in the vertex layout | ||
| @builtin(instance_index) instance_index: u32, | ||
| // Like we defined for the vertex layout | ||
| // position is at location 0 | ||
| @location(0) position: vec3<f32>, | ||
| // and color at location 1 | ||
| @location(1) color: vec4<f32>, | ||
| }; | ||
|
|
||
| // This is the output of the vertex shader and we also use it as the input for the fragment shader | ||
| struct VertexOutput { | ||
| @builtin(position) clip_position: vec4<f32>, | ||
| @location(0) world_position: vec4<f32>, | ||
| @location(1) color: vec3<f32>, | ||
| }; | ||
|
|
||
| @vertex | ||
| fn vertex(vertex: Vertex) -> VertexOutput { | ||
| var out: VertexOutput; | ||
| // This is how bevy computes the world position | ||
| // The vertex.instance_index is very important. Esepecially if you are using batching and gpu preprocessing | ||
| var world_from_local = mesh_functions::get_world_from_local(vertex.instance_index); | ||
| out.world_position = mesh_functions::mesh_position_local_to_world(world_from_local, vec4(vertex.position, 1.0)); | ||
| out.clip_position = position_world_to_clip(out.world_position.xyz); | ||
|
|
||
| // We just use the raw vertex color | ||
| out.color = vertex.color.rgb; | ||
|
|
||
| return out; | ||
| } | ||
|
|
||
| @fragment | ||
| fn fragment(in: VertexOutput) -> @location(0) vec4<f32> { | ||
| // output the color directly | ||
| return vec4(in.color, 1.0); | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could this use world position? even if a bit silly like dividing the color by the position or smth
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to keep the shader as simple as possible. I think people using that level of api are able to figure that out. I could maybe rotate the camera a bit to show that it's all already correctly placed in the world.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should probably add a few comments about the world position and instance_index though.