try one entity, convert to mat4x4
This commit is contained in:
parent
87f674238d
commit
1a1509f315
15
src/main.rs
15
src/main.rs
@ -35,8 +35,6 @@ struct Camera {
|
|||||||
walkspeed: f32,
|
walkspeed: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
const MAGIC_ENTITIES: usize = 7;
|
|
||||||
|
|
||||||
const CONTROL_MOVEFORWARD:u32 = 0b00000001;
|
const CONTROL_MOVEFORWARD:u32 = 0b00000001;
|
||||||
const CONTROL_MOVEBACK:u32 = 0b00000010;
|
const CONTROL_MOVEBACK:u32 = 0b00000010;
|
||||||
const CONTROL_MOVERIGHT:u32 = 0b00000100;
|
const CONTROL_MOVERIGHT:u32 = 0b00000100;
|
||||||
@ -148,12 +146,9 @@ impl Skybox {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_entity_uniform_data(entities:& Vec<Entity>) -> [f32; (9+3)*MAGIC_ENTITIES] {
|
fn get_entity_uniform_data(entity:&Entity) -> [f32; 4*4] {
|
||||||
let mut raw = [0f32; (9+3)*MAGIC_ENTITIES];
|
let mut raw = [0f32; 4*4];
|
||||||
for (i,entity) in entities.iter().enumerate() {
|
raw[0..16].copy_from_slice(&AsRef::<[f32; 4*4]>::as_ref(&glam::Mat4::from(entity.transform))[..]);
|
||||||
raw[i*12..(i+1)*12-3].copy_from_slice(&AsRef::<[f32; 9]>::as_ref(&glam::Mat3::from(entity.transform.matrix3))[..]);
|
|
||||||
raw[i*12+9..(i+1)*12].copy_from_slice(AsRef::<[f32; 3]>::as_ref(&glam::Vec3::from(entity.transform.translation)));
|
|
||||||
}
|
|
||||||
raw
|
raw
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,7 +279,7 @@ impl strafe_client::framework::Example for Skybox {
|
|||||||
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
||||||
});
|
});
|
||||||
|
|
||||||
let entity_uniforms = get_entity_uniform_data(&entities);
|
let entity_uniforms = get_entity_uniform_data(&entities[6]);
|
||||||
let entity_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
let entity_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
label: Some("EntityData"),
|
label: Some("EntityData"),
|
||||||
contents: bytemuck::cast_slice(&entity_uniforms),
|
contents: bytemuck::cast_slice(&entity_uniforms),
|
||||||
@ -634,7 +629,7 @@ impl strafe_client::framework::Example for Skybox {
|
|||||||
device,
|
device,
|
||||||
)
|
)
|
||||||
.copy_from_slice(bytemuck::cast_slice(&camera_uniforms));
|
.copy_from_slice(bytemuck::cast_slice(&camera_uniforms));
|
||||||
let entity_uniforms = get_entity_uniform_data(&self.entities);
|
let entity_uniforms = get_entity_uniform_data(&self.entities[6]);
|
||||||
self.staging_belt
|
self.staging_belt
|
||||||
.write_buffer(
|
.write_buffer(
|
||||||
&mut encoder,
|
&mut encoder,
|
||||||
|
@ -67,25 +67,20 @@ struct EntityOutput {
|
|||||||
@location(3) view: vec3<f32>,
|
@location(3) view: vec3<f32>,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct EntityTransform {
|
|
||||||
matrix3: mat3x3<f32>,
|
|
||||||
translation: vec3<f32>,
|
|
||||||
};
|
|
||||||
@group(1)
|
@group(1)
|
||||||
@binding(0)
|
@binding(0)
|
||||||
var<uniform> r_EntityTransform: EntityTransform;
|
var<uniform> r_EntityTransform: mat4x4<f32>;
|
||||||
|
|
||||||
@vertex
|
@vertex
|
||||||
fn vs_entity(
|
fn vs_entity(
|
||||||
@location(0) pos: vec3<f32>,
|
@location(0) pos: vec3<f32>,
|
||||||
@location(1) normal: vec3<f32>,
|
@location(1) normal: vec3<f32>,
|
||||||
) -> EntityOutput {
|
) -> EntityOutput {
|
||||||
var position: vec3<f32> = r_EntityTransform.matrix3 * pos+r_EntityTransform.translation;
|
var position: vec4<f32> = r_EntityTransform * vec4<f32>(pos, 1.0);
|
||||||
var result: EntityOutput;
|
var result: EntityOutput;
|
||||||
result.normal = r_EntityTransform.matrix3 * normal;
|
result.normal = (r_EntityTransform * vec4<f32>(normal, 0.0)).xyz;
|
||||||
result.view = position - r_data.cam_pos.xyz;
|
result.view = position.xyz - r_data.cam_pos.xyz;
|
||||||
result.position = r_data.proj * r_data.view * vec4<f32>(position, 1.0);
|
result.position = r_data.proj * r_data.view * position;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user