summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/src/scene_prepare.rs2
-rw-r--r--client/src/scene_render.rs147
-rw-r--r--shared/src/resources.rs3
3 files changed, 86 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(..));
diff --git a/shared/src/resources.rs b/shared/src/resources.rs
index 5c207a9..b2708cb 100644
--- a/shared/src/resources.rs
+++ b/shared/src/resources.rs
@@ -237,6 +237,7 @@ impl ReadWrite for MeshPart {
write_kv_opt(w, b"g_alpha", &self.g_alpha)?;
write_kv_opt(w, b"g_emission", &self.g_emission)?;
write_kv_opt(w, b"g_unlit", &self.g_unlit)?;
+ write_kv_opt(w, b"g_double_sided", &self.g_double_sided)?;
write_kv_opt(w, b"va_position", &self.va_position)?;
write_kv_opt(w, b"va_normal", &self.va_normal)?;
write_kv_opt(w, b"va_texcoord", &self.va_texcoord)?;
@@ -267,6 +268,8 @@ impl ReadWrite for MeshPart {
b"g_transmission" => Ok(s.g_transmission = Some(read_slice(v)?)),
b"g_alpha" => Ok(s.g_alpha = Some(read_slice(v)?)),
b"g_emission" => Ok(s.g_emission = Some(read_slice(v)?)),
+ b"g_unlit" => Ok(s.g_unlit = Some(read_slice(v)?)),
+ b"g_double_sided" => Ok(s.g_double_sided = Some(read_slice(v)?)),
b"va_position" => Ok(s.va_position = Some(read_slice(v)?)),
b"va_normal" => Ok(s.va_normal = Some(read_slice(v)?)),
b"va_texcoord" => Ok(s.va_texcoord = Some(read_slice(v)?)),