diff options
author | metamuffin <metamuffin@disroot.org> | 2025-01-13 16:37:32 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-13 16:37:32 +0100 |
commit | 83077c23fe5f067b782c2ac25f2e9165861517d4 (patch) | |
tree | 309001e3df54697845981e4e469a60eee70b32e9 /client | |
parent | a976b24a54ae8c26759af18ddef849f336c6d4ec (diff) | |
download | weareserver-83077c23fe5f067b782c2ac25f2e9165861517d4.tar weareserver-83077c23fe5f067b782c2ac25f2e9165861517d4.tar.bz2 weareserver-83077c23fe5f067b782c2ac25f2e9165861517d4.tar.zst |
double sided meshes in client
Diffstat (limited to 'client')
-rw-r--r-- | client/src/scene_prepare.rs | 2 | ||||
-rw-r--r-- | client/src/scene_render.rs | 147 |
2 files changed, 83 insertions, 66 deletions
diff --git a/client/src/scene_prepare.rs b/client/src/scene_prepare.rs index 2b3e2e7..d26ed1c 100644 --- a/client/src/scene_prepare.rs +++ b/client/src/scene_prepare.rs @@ -97,6 +97,7 @@ pub struct RMeshPart { pub va_texcoord: Arc<Buffer>, pub tex_albedo: Arc<BindGroup>, pub tex_normal: Arc<BindGroup>, + pub double_sided: bool, } impl ScenePreparer { @@ -290,6 +291,7 @@ impl ScenePreparer { va_texcoord, tex_albedo, tex_normal, + double_sided: part.g_double_sided.is_some(), }), ); num_done += 1; diff --git a/client/src/scene_render.rs b/client/src/scene_render.rs index b588e7d..03b077c 100644 --- a/client/src/scene_render.rs +++ b/client/src/scene_render.rs @@ -33,6 +33,7 @@ use crate::scene_prepare::{DemandMap, RPrefab}; pub struct ScenePipeline { pipeline: RenderPipeline, + pipeline_no_cull: RenderPipeline, } impl ScenePipeline { @@ -68,72 +69,80 @@ impl ScenePipeline { stages: ShaderStages::VERTEX, }], }); - let pipeline = device.create_render_pipeline(&RenderPipelineDescriptor { - label: None, - layout: Some(&pipeline_layout), - fragment: Some(FragmentState { - module: &module, - entry_point: Some("fs_main"), - targets: &[Some(ColorTargetState { - blend: Some(BlendState::PREMULTIPLIED_ALPHA_BLENDING), - format, - write_mask: ColorWrites::all(), - })], - compilation_options: PipelineCompilationOptions::default(), - }), - vertex: VertexState { - module: &module, - entry_point: Some("vs_main"), - buffers: &[ - VertexBufferLayout { - step_mode: VertexStepMode::Vertex, - array_stride: 3 * size_of::<f32>() as u64, - attributes: &[VertexAttribute { - format: VertexFormat::Float32x3, - offset: 0, - shader_location: 0, - }], - }, - VertexBufferLayout { - step_mode: VertexStepMode::Vertex, - array_stride: 3 * size_of::<f32>() as u64, - attributes: &[VertexAttribute { - format: VertexFormat::Float32x3, - offset: 0, - shader_location: 1, - }], - }, - VertexBufferLayout { - step_mode: VertexStepMode::Vertex, - array_stride: 2 * size_of::<f32>() as u64, - attributes: &[VertexAttribute { - format: VertexFormat::Float32x2, - offset: 0, - shader_location: 2, - }], - }, - ], - compilation_options: PipelineCompilationOptions::default(), - }, - primitive: PrimitiveState { - topology: PrimitiveTopology::TriangleList, - front_face: FrontFace::Ccw, - cull_mode: Some(Face::Back), - polygon_mode: PolygonMode::Fill, - ..Default::default() - }, - depth_stencil: Some(DepthStencilState { - depth_write_enabled: true, - depth_compare: CompareFunction::Less, - format: TextureFormat::Depth32Float, - bias: DepthBiasState::default(), - stencil: StencilState::default(), - }), - multisample: MultisampleState::default(), - multiview: None, - cache: None, + let [pipeline, pipeline_no_cull] = [Some(Face::Back), None].map(|cull_mode| { + device.create_render_pipeline(&RenderPipelineDescriptor { + label: None, + layout: Some(&pipeline_layout), + fragment: Some(FragmentState { + module: &module, + entry_point: Some("fs_main"), + targets: &[Some(ColorTargetState { + blend: Some(BlendState::PREMULTIPLIED_ALPHA_BLENDING), + format, + write_mask: ColorWrites::all(), + })], + compilation_options: PipelineCompilationOptions::default(), + }), + vertex: VertexState { + module: &module, + entry_point: Some("vs_main"), + buffers: &[ + VertexBufferLayout { + step_mode: VertexStepMode::Vertex, + array_stride: 3 * size_of::<f32>() as u64, + attributes: &[VertexAttribute { + format: VertexFormat::Float32x3, + offset: 0, + shader_location: 0, + }], + }, + VertexBufferLayout { + step_mode: VertexStepMode::Vertex, + array_stride: 3 * size_of::<f32>() as u64, + attributes: &[VertexAttribute { + format: VertexFormat::Float32x3, + offset: 0, + shader_location: 1, + }], + }, + VertexBufferLayout { + step_mode: VertexStepMode::Vertex, + array_stride: 2 * size_of::<f32>() as u64, + attributes: &[VertexAttribute { + format: VertexFormat::Float32x2, + offset: 0, + shader_location: 2, + }], + }, + ], + compilation_options: PipelineCompilationOptions::default(), + }, + primitive: PrimitiveState { + topology: PrimitiveTopology::TriangleList, + front_face: FrontFace::Ccw, + cull_mode, + polygon_mode: PolygonMode::Fill, + ..Default::default() + }, + depth_stencil: Some(DepthStencilState { + depth_write_enabled: true, + depth_compare: CompareFunction::Less, + format: TextureFormat::Depth32Float, + bias: DepthBiasState::default(), + stencil: StencilState::default(), + }), + multisample: MultisampleState::default(), + multiview: None, + cache: None, + }) }); - (Self { pipeline }, bind_group_layout) + ( + Self { + pipeline, + pipeline_no_cull, + }, + bind_group_layout, + ) } pub fn draw( @@ -187,9 +196,15 @@ impl ScenePipeline { * Mat4::from_mat3a(affine.matrix3); let projection = part_projection.to_cols_array().map(|v| v.to_le_bytes()); + let pipeline = if part.double_sided { + &self.pipeline_no_cull + } else { + &self.pipeline + }; + + rpass.set_pipeline(pipeline); rpass.set_bind_group(0, &*part.tex_albedo, &[]); rpass.set_bind_group(1, &*part.tex_normal, &[]); - rpass.set_pipeline(&self.pipeline); rpass.set_push_constants(ShaderStages::VERTEX, 0, projection.as_flattened()); rpass.set_index_buffer(part.index.slice(..), IndexFormat::Uint32); rpass.set_vertex_buffer(0, part.va_position.slice(..)); |