Skip redundant mesh_position_local_to_world call in vertex prepass shader (#13158)

# Objective

Optimize vertex prepass shader maybe?
Make it consistent with the base vertex shader

## Solution

`mesh_position_local_to_clip` just calls `mesh_position_local_to_world`
and then `position_world_to_clip`
since `out.world_position` is getting calculated anyway a few lines
below, just move it up and use it's output to calculate `out.position`.

It is the same as in the base vertex shader (`mesh.wgsl`).

Note: I have no idea if there is a reason that it was this way. I'm not
an expert, just noticed this inconsistency while messing with custom
shaders.
This commit is contained in:
Csányi István 2024-05-14 18:31:58 +02:00 committed by GitHub
parent dcf24dfd6b
commit f91fd322b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,6 +5,7 @@
skinning,
morph,
mesh_view_bindings::view,
view_transformations::position_world_to_clip,
}
#ifdef DEFERRED_PREPASS
@ -50,7 +51,8 @@ fn vertex(vertex_no_morph: Vertex) -> VertexOutput {
var model = mesh_functions::get_model_matrix(vertex_no_morph.instance_index);
#endif // SKINNED
out.position = mesh_functions::mesh_position_local_to_clip(model, vec4(vertex.position, 1.0));
out.world_position = mesh_functions::mesh_position_local_to_world(model, vec4<f32>(vertex.position, 1.0));
out.position = position_world_to_clip(out.world_position.xyz);
#ifdef DEPTH_CLAMP_ORTHO
out.clip_position_unclamped = out.position;
out.position.z = min(out.position.z, 1.0);
@ -91,8 +93,6 @@ fn vertex(vertex_no_morph: Vertex) -> VertexOutput {
out.color = vertex.color;
#endif
out.world_position = mesh_functions::mesh_position_local_to_world(model, vec4<f32>(vertex.position, 1.0));
#ifdef MOTION_VECTOR_PREPASS
// Use vertex_no_morph.instance_index instead of vertex.instance_index to work around a wgpu dx12 bug.
// See https://github.com/gfx-rs/naga/issues/2416