From 9779d69f1f965490f89964b25dbc091d38453c73 Mon Sep 17 00:00:00 2001 From: Torstein Grindvik Date: Wed, 28 Dec 2022 16:52:51 +0100 Subject: [PATCH] WIP: xmas stuff Signed-off-by: Torstein Grindvik --- PR-TODO.md | 15 +++++++++++++++ crates/bevy_pbr/src/render/pbr.wgsl | 2 -- crates/bevy_sprite/src/mesh2d/mesh.rs | 2 +- crates/bevy_sprite/src/render/mod.rs | 11 ++++++++--- crates/bevy_sprite/src/render/sprite.wgsl | 18 +++++++++--------- 5 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 PR-TODO.md diff --git a/PR-TODO.md b/PR-TODO.md new file mode 100644 index 00000000000000..4d3a8f78aed96e --- /dev/null +++ b/PR-TODO.md @@ -0,0 +1,15 @@ +# TODO + +Just a dev todo, delete file eventually. + +* UniformComponentPlugin a sprite uniform +* In extract_sprites (see extract_meshes), add uniform as component +* SpriteUniform, component + shadertype + clone, field: entity_index: u32 +* Need to add the bind group in SpritePipeline (?) see MeshPipeline's FromWorld +* Then in queue_sprite_bind_group (?) see queue_mesh_bind_group we need Res> + - Create the bind group and clone the binding here + - Insert the resource +* Then we need something like SetMeshBindGroup +* Then update the sprite draw function + +* Lastly, remove all the vertex based sprite stuff diff --git a/crates/bevy_pbr/src/render/pbr.wgsl b/crates/bevy_pbr/src/render/pbr.wgsl index af0c44a2f9b7a5..d02b198d1ef786 100644 --- a/crates/bevy_pbr/src/render/pbr.wgsl +++ b/crates/bevy_pbr/src/render/pbr.wgsl @@ -115,8 +115,6 @@ fn fragment(in: FragmentInput) -> FragmentOutput { output_color = vec4(output_rgb, output_color.a); #endif - let location = vec2(i32(in.frag_coord.x), i32(in.frag_coord.y)); - var out: FragmentOutput; out.color = output_color; diff --git a/crates/bevy_sprite/src/mesh2d/mesh.rs b/crates/bevy_sprite/src/mesh2d/mesh.rs index 829b05c2a97d84..673febf0d258f4 100644 --- a/crates/bevy_sprite/src/mesh2d/mesh.rs +++ b/crates/bevy_sprite/src/mesh2d/mesh.rs @@ -407,7 +407,7 @@ impl SpecializedMeshPipeline for Mesh2dPipeline { format: TextureFormat::R32Uint, blend: None, write_mask: ColorWrites::ALL, - })) + })); } Ok(RenderPipelineDescriptor { diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index aa909e760499f8..26a2fa952271c2 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -197,13 +197,13 @@ impl SpecializedRenderPipeline for SpritePipeline { type Key = SpritePipelineKey; fn specialize(&self, key: Self::Key) -> RenderPipelineDescriptor { + // TODO: We have done goofed + let mut formats = vec![ // position VertexFormat::Float32x3, // uv VertexFormat::Float32x2, - // entity index - VertexFormat::Uint32, ]; if key.contains(SpritePipelineKey::COLORED) { @@ -211,6 +211,11 @@ impl SpecializedRenderPipeline for SpritePipeline { formats.push(VertexFormat::Float32x4); } + if key.contains(SpritePipelineKey::PICKING) { + // entity index + formats.push(VertexFormat::Uint32); + } + let vertex_layout = VertexBufferLayout::from_vertex_formats(VertexStepMode::Vertex, formats); @@ -246,7 +251,7 @@ impl SpecializedRenderPipeline for SpritePipeline { format: TextureFormat::R32Uint, blend: None, write_mask: ColorWrites::ALL, - })) + })); } RenderPipelineDescriptor { diff --git a/crates/bevy_sprite/src/render/sprite.wgsl b/crates/bevy_sprite/src/render/sprite.wgsl index 1540b563bc17be..4633fde81d413e 100644 --- a/crates/bevy_sprite/src/render/sprite.wgsl +++ b/crates/bevy_sprite/src/render/sprite.wgsl @@ -17,25 +17,25 @@ struct View { var view: View; struct VertexOutput { + @builtin(position) position: vec4, @location(0) uv: vec2, -#ifdef PICKING - @location(1) entity_index: u32, -#endif #ifdef COLORED - @location(2) color: vec4, + @location(1) color: vec4, +#endif +#ifdef PICKING + @location(2) entity_index: u32, #endif - @builtin(position) position: vec4, }; @vertex fn vertex( @location(0) vertex_position: vec3, @location(1) vertex_uv: vec2, -#ifdef PICKING - @location(2) entity_index: u32, -#endif #ifdef COLORED - @location(3) vertex_color: vec4, + @location(2) vertex_color: vec4, +#endif +#ifdef PICKING + @location(3) entity_index: u32, #endif ) -> VertexOutput { var out: VertexOutput;