From 2d6f319dfccf6339ed1a3bbfb003b8b2dde82383 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 19 Jan 2025 16:44:06 +0100 Subject: client: normal maps --- client/src/scene_render.rs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'client/src/scene_render.rs') diff --git a/client/src/scene_render.rs b/client/src/scene_render.rs index 03b077c..3ec96b3 100644 --- a/client/src/scene_render.rs +++ b/client/src/scene_render.rs @@ -65,7 +65,7 @@ impl ScenePipeline { label: None, bind_group_layouts: &[&bind_group_layout, &bind_group_layout], push_constant_ranges: &[PushConstantRange { - range: 0..(4 * 4 * size_of::() as u32), + range: 0..((4 * 4 + 3 * 4) * size_of::() as u32), stages: ShaderStages::VERTEX, }], }); @@ -87,6 +87,7 @@ impl ScenePipeline { module: &module, entry_point: Some("vs_main"), buffers: &[ + // position VertexBufferLayout { step_mode: VertexStepMode::Vertex, array_stride: 3 * size_of::() as u64, @@ -96,6 +97,7 @@ impl ScenePipeline { shader_location: 0, }], }, + // normal VertexBufferLayout { step_mode: VertexStepMode::Vertex, array_stride: 3 * size_of::() as u64, @@ -105,13 +107,24 @@ impl ScenePipeline { shader_location: 1, }], }, + // tangent + VertexBufferLayout { + step_mode: VertexStepMode::Vertex, + array_stride: 3 * size_of::() as u64, + attributes: &[VertexAttribute { + format: VertexFormat::Float32x3, + offset: 0, + shader_location: 2, + }], + }, + // texcoord VertexBufferLayout { step_mode: VertexStepMode::Vertex, array_stride: 2 * size_of::() as u64, attributes: &[VertexAttribute { format: VertexFormat::Float32x2, offset: 0, - shader_location: 2, + shader_location: 3, }], }, ], @@ -195,6 +208,14 @@ impl ScenePipeline { * Mat4::from_translation(affine.translation.into()) * Mat4::from_mat3a(affine.matrix3); let projection = part_projection.to_cols_array().map(|v| v.to_le_bytes()); + let mb = affine.matrix3.to_cols_array(); // TODO apply object rotation + // add padding for gpu mat3x3 repr + let model_basis = [ + mb[0], mb[1], mb[2], 0., // + mb[3], mb[4], mb[5], 0., // + mb[6], mb[7], mb[8], 0., // + ]; + let model_basis = bytemuck::cast_slice(&model_basis); let pipeline = if part.double_sided { &self.pipeline_no_cull @@ -206,10 +227,12 @@ impl ScenePipeline { rpass.set_bind_group(0, &*part.tex_albedo, &[]); rpass.set_bind_group(1, &*part.tex_normal, &[]); rpass.set_push_constants(ShaderStages::VERTEX, 0, projection.as_flattened()); + rpass.set_push_constants(ShaderStages::VERTEX, 64, model_basis); rpass.set_index_buffer(part.index.slice(..), IndexFormat::Uint32); rpass.set_vertex_buffer(0, part.va_position.slice(..)); rpass.set_vertex_buffer(1, part.va_normal.slice(..)); - rpass.set_vertex_buffer(2, part.va_texcoord.slice(..)); + rpass.set_vertex_buffer(2, part.va_tangent.slice(..)); + rpass.set_vertex_buffer(3, part.va_texcoord.slice(..)); rpass.draw_indexed(0..part.index_count, 0, 0..1); } } -- cgit v1.2.3-70-g09d2