Skip to content

Commit

Permalink
bevy_pbr2: Fix transformation of normals
Browse files Browse the repository at this point in the history
Normals should be transformed by the inverse transpose of the model matrix to correctly transform their scale.
  • Loading branch information
superdump committed Aug 23, 2021
1 parent e38590b commit bdf0634
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pipelined/bevy_pbr2/src/render/pbr.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ fn vertex(vertex: Vertex) -> VertexOutput {
out.uv = vertex.uv;
out.world_position = world_position;
out.clip_position = view.view_proj * world_position;
// FIXME: The inverse transpose of the model matrix should be used to correctly handle scaling
// of normals
out.world_normal = mat3x3<f32>(mesh.model.x.xyz, mesh.model.y.xyz, mesh.model.z.xyz) * vertex.normal;
out.world_normal = mat3x3<f32>(
mesh.inverse_transpose_model.x.xyz,
mesh.inverse_transpose_model.y.xyz,
mesh.inverse_transpose_model.z.xyz
) * vertex.normal;
return out;
}

Expand Down

0 comments on commit bdf0634

Please sign in to comment.