71 lines
2.7 KiB
Rust
71 lines
2.7 KiB
Rust
use crate::{
|
|
asset::AssetStorage,
|
|
render::{
|
|
pipeline::PipelineDescriptor,
|
|
render_graph::RenderGraphBuilder,
|
|
render_resource::resource_name,
|
|
shader::{Shader, ShaderStage},
|
|
Vertex,
|
|
},
|
|
};
|
|
pub trait ForwardPipelineBuilder {
|
|
fn add_forward_pipeline(
|
|
self,
|
|
pipeline_descriptor_storage: &mut AssetStorage<PipelineDescriptor>,
|
|
shader_storage: &mut AssetStorage<Shader>,
|
|
) -> Self;
|
|
}
|
|
|
|
impl ForwardPipelineBuilder for RenderGraphBuilder {
|
|
fn add_forward_pipeline(
|
|
self,
|
|
pipeline_descriptor_storage: &mut AssetStorage<PipelineDescriptor>,
|
|
shader_storage: &mut AssetStorage<Shader>,
|
|
) -> Self {
|
|
self.add_pipeline(
|
|
pipeline_descriptor_storage,
|
|
PipelineDescriptor::build(
|
|
shader_storage,
|
|
Shader::from_glsl(ShaderStage::Vertex, include_str!("forward.vert")),
|
|
)
|
|
.with_fragment_shader(Shader::from_glsl(
|
|
ShaderStage::Fragment,
|
|
include_str!("forward.frag"),
|
|
))
|
|
.with_rasterization_state(wgpu::RasterizationStateDescriptor {
|
|
front_face: wgpu::FrontFace::Ccw,
|
|
cull_mode: wgpu::CullMode::Back,
|
|
depth_bias: 0,
|
|
depth_bias_slope_scale: 0.0,
|
|
depth_bias_clamp: 0.0,
|
|
})
|
|
.with_depth_stencil_state(wgpu::DepthStencilStateDescriptor {
|
|
format: wgpu::TextureFormat::Depth32Float,
|
|
depth_write_enabled: true,
|
|
depth_compare: wgpu::CompareFunction::Less,
|
|
stencil_front: wgpu::StencilStateFaceDescriptor::IGNORE,
|
|
stencil_back: wgpu::StencilStateFaceDescriptor::IGNORE,
|
|
stencil_read_mask: 0,
|
|
stencil_write_mask: 0,
|
|
})
|
|
.add_color_state(wgpu::ColorStateDescriptor {
|
|
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
|
color_blend: wgpu::BlendDescriptor {
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
operation: wgpu::BlendOperation::Add,
|
|
},
|
|
alpha_blend: wgpu::BlendDescriptor {
|
|
src_factor: wgpu::BlendFactor::One,
|
|
dst_factor: wgpu::BlendFactor::One,
|
|
operation: wgpu::BlendOperation::Add,
|
|
},
|
|
write_mask: wgpu::ColorWrite::ALL,
|
|
})
|
|
.add_vertex_buffer_descriptor(Vertex::get_vertex_buffer_descriptor())
|
|
.add_draw_target(resource_name::draw_target::ASSIGNED_MESHES)
|
|
.finish(),
|
|
)
|
|
}
|
|
}
|