Skip to content

Commit

Permalink
WIP: xmas stuff
Browse files Browse the repository at this point in the history
Signed-off-by: Torstein Grindvik <torstein.grindvik@nordicsemi.no>
  • Loading branch information
torsteingrindvik committed Jan 3, 2023
1 parent 53837af commit 9779d69
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
15 changes: 15 additions & 0 deletions PR-TODO.md
Original file line number Diff line number Diff line change
@@ -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<ComponentUniforms<SpriteUniform>>
- 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
2 changes: 0 additions & 2 deletions crates/bevy_pbr/src/render/pbr.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ fn fragment(in: FragmentInput) -> FragmentOutput {
output_color = vec4(output_rgb, output_color.a);
#endif

let location = vec2<i32>(i32(in.frag_coord.x), i32(in.frag_coord.y));

var out: FragmentOutput;

out.color = output_color;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_sprite/src/mesh2d/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ impl SpecializedMeshPipeline for Mesh2dPipeline {
format: TextureFormat::R32Uint,
blend: None,
write_mask: ColorWrites::ALL,
}))
}));
}

Ok(RenderPipelineDescriptor {
Expand Down
11 changes: 8 additions & 3 deletions crates/bevy_sprite/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,25 @@ 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) {
// color
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);

Expand Down Expand Up @@ -246,7 +251,7 @@ impl SpecializedRenderPipeline for SpritePipeline {
format: TextureFormat::R32Uint,
blend: None,
write_mask: ColorWrites::ALL,
}))
}));
}

RenderPipelineDescriptor {
Expand Down
18 changes: 9 additions & 9 deletions crates/bevy_sprite/src/render/sprite.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ struct View {
var<uniform> view: View;

struct VertexOutput {
@builtin(position) position: vec4<f32>,
@location(0) uv: vec2<f32>,
#ifdef PICKING
@location(1) entity_index: u32,
#endif
#ifdef COLORED
@location(2) color: vec4<f32>,
@location(1) color: vec4<f32>,
#endif
#ifdef PICKING
@location(2) entity_index: u32,
#endif
@builtin(position) position: vec4<f32>,
};

@vertex
fn vertex(
@location(0) vertex_position: vec3<f32>,
@location(1) vertex_uv: vec2<f32>,
#ifdef PICKING
@location(2) entity_index: u32,
#endif
#ifdef COLORED
@location(3) vertex_color: vec4<f32>,
@location(2) vertex_color: vec4<f32>,
#endif
#ifdef PICKING
@location(3) entity_index: u32,
#endif
) -> VertexOutput {
var out: VertexOutput;
Expand Down

0 comments on commit 9779d69

Please sign in to comment.