From d2fdb5d94bde4c25f21ed0c9a06c70e7183d6f2f Mon Sep 17 00:00:00 2001 From: Quaternions Date: Fri, 1 Sep 2023 18:21:57 -0700 Subject: [PATCH] entity_id trash --- src/main.rs | 5 ++++- src/shader.wgsl | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7627a488..f8f76c36 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ const IMAGE_SIZE: u32 = 128; struct Vertex { pos: [f32; 3], normal: [f32; 3], + entity_id: u32, } struct Entity { @@ -162,6 +163,7 @@ fn add_obj(device:&wgpu::Device,entities:& mut Vec,source:&[u8]){ for object in data.objects { for group in object.groups { vertices.clear(); + let entity_id = entities.len() as u32; for poly in group.polys { for end_index in 2..poly.0.len() { for &index in &[0, end_index - 1, end_index] { @@ -170,6 +172,7 @@ fn add_obj(device:&wgpu::Device,entities:& mut Vec,source:&[u8]){ vertices.push(Vertex { pos: data.position[position_id], normal: data.normal[normal_id.unwrap()], + entity_id, }) } } @@ -328,7 +331,7 @@ impl strafe_client::framework::Example for Skybox { buffers: &[wgpu::VertexBufferLayout { array_stride: std::mem::size_of::() as wgpu::BufferAddress, step_mode: wgpu::VertexStepMode::Vertex, - attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3], + attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3, 2 => Uint32], }], }, fragment: Some(wgpu::FragmentState { diff --git a/src/shader.wgsl b/src/shader.wgsl index e861632c..ccbfb9b9 100644 --- a/src/shader.wgsl +++ b/src/shader.wgsl @@ -80,10 +80,11 @@ var r_EntityTransforms: array; fn vs_entity( @location(0) pos: vec3, @location(1) normal: vec3, + @location(2) entity_id: u32, ) -> EntityOutput { - var position: vec3 = pos;//r_EntityTransforms[instance_index].matrix3 * pos+r_EntityTransforms[instance_index].translation; + var position: vec3 = r_EntityTransforms[entity_id].matrix3 * pos+r_EntityTransforms[entity_id].translation; var result: EntityOutput; - result.normal = normal;//r_EntityTransforms[instance_index].matrix3 * normal; + result.normal = r_EntityTransforms[entity_id].matrix3 * normal; result.view = position - r_data.cam_pos.xyz; result.position = r_data.proj * r_data.view * vec4(position, 1.0); return result;