diff options
Diffstat (limited to 'client/src/render/scene')
-rw-r--r-- | client/src/render/scene/draw.rs | 33 | ||||
-rw-r--r-- | client/src/render/scene/pipelines.rs | 20 |
2 files changed, 20 insertions, 33 deletions
diff --git a/client/src/render/scene/draw.rs b/client/src/render/scene/draw.rs index 672d7ef..bdbcb50 100644 --- a/client/src/render/scene/draw.rs +++ b/client/src/render/scene/draw.rs @@ -15,7 +15,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ use super::{DemandMap, RPrefab}; -use glam::{EulerRot, Mat3, Mat4, Vec3}; +use glam::{EulerRot, Mat3, Mat4}; use std::sync::Arc; use weareshared::{packets::Resource, resources::Prefab, tree::SceneTree}; use wgpu::{ @@ -33,8 +33,8 @@ impl ScenePipeline { depth: &TextureView, scene: &SceneTree, prefabs: &DemandMap<Resource<Prefab>, Arc<RPrefab>>, - projection: Mat4, - camera_position: Vec3, + view: Mat4, + project: Mat4, ) { let mut rpass = commands.begin_render_pass(&RenderPassDescriptor { label: None, @@ -63,7 +63,7 @@ impl ScenePipeline { }); for ob in scene.objects.values() { - let prefab_projection = projection + let prefab_modelview = view * Mat4::from_translation(ob.pos.into()) * Mat4::from_mat3(Mat3::from_euler( EulerRot::YXZ, @@ -73,28 +73,23 @@ impl ScenePipeline { )); if let Some(prefab) = prefabs.try_get(ob.res.clone()) { for (affine, part) in &prefab.0 { - let part_projection = prefab_projection + let modelview = prefab_modelview * 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 cp = &[camera_position.x, camera_position.y, camera_position.z, 0.]; - let camera_position = bytemuck::cast_slice(cp); + let modelviewp = project * modelview; + // let light = modelview * vec4(5., 5., 5., 1.); + + // let light = light.to_array().map(|v| v.to_le_bytes()); + let modelview = modelview.to_cols_array().map(|v| v.to_le_bytes()); + let modelviewp = modelviewp.to_cols_array().map(|v| v.to_le_bytes()); rpass.set_pipeline(&part.pipeline); rpass.set_bind_group(0, &*part.tex_albedo, &[]); rpass.set_bind_group(1, &*part.tex_normal, &[]); rpass.set_bind_group(2, &*part.material, &[]); - rpass.set_push_constants(ShaderStages::VERTEX, 0, projection.as_flattened()); - rpass.set_push_constants(ShaderStages::VERTEX, 64, model_basis); - rpass.set_push_constants(ShaderStages::VERTEX, 112, camera_position); + rpass.set_push_constants(ShaderStages::VERTEX, 0, modelviewp.as_flattened()); + rpass.set_push_constants(ShaderStages::VERTEX, 64, modelview.as_flattened()); + // rpass.set_push_constants(ShaderStages::FRAGMENT, 128, light.as_flattened()); 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(..)); diff --git a/client/src/render/scene/pipelines.rs b/client/src/render/scene/pipelines.rs index 675cfae..dfc5d19 100644 --- a/client/src/render/scene/pipelines.rs +++ b/client/src/render/scene/pipelines.rs @@ -99,20 +99,12 @@ impl PipelineSpec { let pipeline_layout = device.create_pipeline_layout(&PipelineLayoutDescriptor { label: None, bind_group_layouts: &[&layouts.texture, &layouts.texture, &layouts.material], - push_constant_ranges: &[ - PushConstantRange { - // 4x4 view projections - // 3x3(+1 pad) model basis - // 3(+1 pad) camera position - range: 0..((4 * 4 + 3 * 4) * size_of::<f32>() as u32), - stages: ShaderStages::VERTEX, - }, - PushConstantRange { - range: ((4 * 4 + 3 * 4) * size_of::<f32>() as u32) - ..(4 * 4 + 3 * 4 + 4) * size_of::<f32>() as u32, - stages: ShaderStages::FRAGMENT, - }, - ], + push_constant_ranges: &[PushConstantRange { + // 4x4 model * view * project + // 4x4 model * view + range: 0..((4 * 4 + 4 * 4) * size_of::<f32>() as u32), + stages: ShaderStages::VERTEX, + }], }); device.create_render_pipeline(&RenderPipelineDescriptor { label: None, |