fix tangent space lighting
This commit is contained in:
parent
a17a751fc4
commit
de50520b02
4 changed files with 99 additions and 213 deletions
|
@ -9,6 +9,7 @@ pub struct Instance {
|
|||
#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
|
||||
pub struct InstanceRaw {
|
||||
pub model: [[f32; 4]; 4],
|
||||
pub normal: [[f32; 3]; 3],
|
||||
}
|
||||
|
||||
impl Instance {
|
||||
|
@ -17,6 +18,7 @@ impl Instance {
|
|||
model: (cgmath::Matrix4::from_translation(self.position)
|
||||
* cgmath::Matrix4::from(self.rotation))
|
||||
.into(),
|
||||
normal: cgmath::Matrix3::from(self.rotation).into(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +33,7 @@ impl Vertex for InstanceRaw {
|
|||
// instance when the shader starts processing a new instance
|
||||
step_mode: wgpu::VertexStepMode::Instance,
|
||||
attributes: &[
|
||||
// model matrix
|
||||
wgpu::VertexAttribute {
|
||||
offset: 0,
|
||||
shader_location: 5,
|
||||
|
@ -51,6 +54,22 @@ impl Vertex for InstanceRaw {
|
|||
shader_location: 8,
|
||||
format: wgpu::VertexFormat::Float32x4,
|
||||
},
|
||||
// normal matrix
|
||||
wgpu::VertexAttribute {
|
||||
offset: mem::size_of::<[f32; 16]>() as wgpu::BufferAddress,
|
||||
shader_location: 9,
|
||||
format: wgpu::VertexFormat::Float32x3,
|
||||
},
|
||||
wgpu::VertexAttribute {
|
||||
offset: mem::size_of::<[f32; 19]>() as wgpu::BufferAddress,
|
||||
shader_location: 10,
|
||||
format: wgpu::VertexFormat::Float32x3,
|
||||
},
|
||||
wgpu::VertexAttribute {
|
||||
offset: mem::size_of::<[f32; 22]>() as wgpu::BufferAddress,
|
||||
shader_location: 11,
|
||||
format: wgpu::VertexFormat::Float32x3,
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue