-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ef94f4
commit be12323
Showing
8 changed files
with
156 additions
and
136 deletions.
There are no files selected for viewing
File renamed without changes.
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
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
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,89 +1,104 @@ | ||
use bevy::{ | ||
ecs::{system::Resource, world::FromWorld}, | ||
ecs::{ | ||
system::Resource, | ||
world::{FromWorld, World}, | ||
}, | ||
render::{ | ||
render_resource::{ | ||
BindGroupLayout, BlendState, ColorTargetState, ColorWrites, Face, FragmentState, | ||
FrontFace, MultisampleState, PolygonMode, PrimitiveState, PrimitiveTopology, | ||
RenderPipelineDescriptor, SpecializedRenderPipeline, TextureFormat, VertexState, | ||
RenderPipelineDescriptor, SpecializedRenderPipeline, TextureFormat, VertexBufferLayout, | ||
VertexFormat, VertexState, VertexStepMode, | ||
}, | ||
texture::BevyDefault, | ||
view::ViewTarget, | ||
}, | ||
sprite::Mesh2dPipeline, | ||
sprite::{Mesh2dPipeline, Mesh2dPipelineKey}, | ||
}; | ||
|
||
use crate::{ | ||
bindings::{TilesBindGroupLayouts, TilesVertexBufferLayouts}, | ||
TILES_FRAG, TILES_VERT, | ||
}; | ||
use crate::{TILES_FRAG, TILES_VERT}; | ||
|
||
#[derive(Resource)] | ||
pub struct TilesPipeline { | ||
vertex_layouts: TilesVertexBufferLayouts, | ||
tile_layouts: TilesBindGroupLayouts, | ||
view_layout: BindGroupLayout, | ||
mesh2d_pipeline: Mesh2dPipeline, | ||
} | ||
|
||
#[derive(PartialEq, Eq, Hash, Clone)] | ||
pub struct TilesPipelineKey; | ||
|
||
impl FromWorld for TilesPipeline { | ||
fn from_world(world: &mut bevy::prelude::World) -> Self { | ||
let mesh_2d_pipeline = world.get_resource::<Mesh2dPipeline>().unwrap(); | ||
let tile_layouts = world.get_resource::<TilesBindGroupLayouts>().unwrap(); | ||
fn from_world(world: &mut World) -> Self { | ||
Self { | ||
vertex_layouts: TilesVertexBufferLayouts::default(), | ||
view_layout: mesh_2d_pipeline.view_layout.clone(), | ||
tile_layouts: tile_layouts.clone(), | ||
mesh2d_pipeline: Mesh2dPipeline::from_world(world), | ||
} | ||
} | ||
} | ||
|
||
impl SpecializedRenderPipeline for TilesPipeline { | ||
type Key = TilesPipelineKey; | ||
type Key = Mesh2dPipelineKey; | ||
|
||
fn specialize( | ||
&self, | ||
key: Self::Key, | ||
) -> bevy::render::render_resource::RenderPipelineDescriptor { | ||
// Customize how to store the meshes' vertex attributes in the vertex buffer | ||
// Our meshes only have position and color | ||
let formats = vec![ | ||
// Position | ||
VertexFormat::Float32x3, | ||
// Color | ||
VertexFormat::Float32x2, | ||
]; | ||
|
||
let vertex_layout = | ||
VertexBufferLayout::from_vertex_formats(VertexStepMode::Vertex, formats); | ||
|
||
let format = match key.contains(Mesh2dPipelineKey::HDR) { | ||
true => ViewTarget::TEXTURE_FORMAT_HDR, | ||
false => TextureFormat::bevy_default(), | ||
}; | ||
|
||
RenderPipelineDescriptor { | ||
label: Some("tiles_pipeline".into()), | ||
layout: vec![ | ||
self.tile_layouts.transform_bind_group.clone(), | ||
//self.view_layout.clone(), | ||
], | ||
vertex: VertexState { | ||
// Use our custom shader | ||
shader: TILES_VERT, | ||
shader_defs: Vec::new(), | ||
entry_point: "vs_main".into(), | ||
buffers: vec![self.vertex_layouts.vertex_layout.clone()], | ||
shader_defs: vec![], | ||
// Use our custom vertex buffer | ||
buffers: vec![vertex_layout], | ||
}, | ||
fragment: Some(FragmentState { | ||
// Use our custom shader | ||
shader: TILES_FRAG, | ||
shader_defs: Vec::new(), | ||
shader_defs: vec![], | ||
entry_point: "fs_main".into(), | ||
targets: vec![Some(ColorTargetState { | ||
format: TextureFormat::bevy_default(), | ||
blend: Some(BlendState::PREMULTIPLIED_ALPHA_BLENDING), | ||
format, | ||
blend: Some(BlendState::ALPHA_BLENDING), | ||
write_mask: ColorWrites::ALL, | ||
})], | ||
}), | ||
// Use the two standard uniforms for 2d meshes | ||
layout: vec![ | ||
// Bind group 0 is the view uniform | ||
self.mesh2d_pipeline.view_layout.clone(), | ||
// Bind group 1 is the mesh uniform | ||
self.mesh2d_pipeline.mesh_layout.clone(), | ||
], | ||
push_constant_ranges: Vec::new(), | ||
primitive: PrimitiveState { | ||
topology: PrimitiveTopology::TriangleList, | ||
strip_index_format: None, | ||
front_face: FrontFace::Ccw, | ||
cull_mode: Some(Face::Back), | ||
unclipped_depth: false, | ||
polygon_mode: PolygonMode::Fill, | ||
conservative: false, | ||
topology: PrimitiveTopology::TriangleList, | ||
strip_index_format: None, | ||
}, | ||
depth_stencil: None, | ||
multisample: MultisampleState { | ||
// TODO: MAKE THIS SPECIALIZED | ||
count: 4, | ||
count: key.msaa_samples(), | ||
mask: !0, | ||
alpha_to_coverage_enabled: false, | ||
}, | ||
push_constant_ranges: vec![], | ||
label: Some("tiles_pipeline".into()), | ||
} | ||
} | ||
} |
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
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
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,7 +1,11 @@ | ||
#import bevy_tiles::vert::{VertOut} | ||
// The input of the fragment shader must correspond to the output of the vertex shader for all `location`s | ||
struct FragIn { | ||
// The color is interpolated between vertices by default | ||
@location(0) color: vec4<f32>, | ||
}; | ||
|
||
/// Entry point for the fragment shader | ||
@fragment | ||
fn fs_main(in: VertOut) -> @location(0) vec4<f32> { | ||
return vec4<f32>(1.0, 0.2, 0.1, 1.0); | ||
} | ||
|
||
fn fragment(in: FragIn) -> @location(0) vec4<f32> { | ||
return in.color; | ||
} |
Oops, something went wrong.