@@ -17,47 +17,20 @@ fn mesh_position_local_to_clip(model: mat4x4<f32>, vertex_position: vec4<f32>) -
17
17
}
18
18
19
19
fn mesh_normal_local_to_world (vertex_normal : vec3 <f32 >) -> vec3 <f32 > {
20
- // NOTE: The mikktspace method of normal mapping requires that the world normal is
21
- // re-normalized in the vertex shader to match the way mikktspace bakes vertex tangents
22
- // and normal maps so that the exact inverse process is applied when shading. Blender, Unity,
23
- // Unreal Engine, Godot, and more all use the mikktspace method. Do not change this code
24
- // unless you really know what you are doing.
25
- // http://www.mikktspace.com/
26
- return normalize (
27
- mat3x3 <f32 >(
28
- mesh . inverse_transpose_model[0 ]. xyz,
29
- mesh . inverse_transpose_model[1 ]. xyz,
30
- mesh . inverse_transpose_model[2 ]. xyz
31
- ) * vertex_normal
32
- );
33
- }
34
-
35
- // Calculates the sign of the determinant of the 3x3 model matrix based on a
36
- // mesh flag
37
- fn sign_determinant_model_3x3 () -> f32 {
38
- // bool(u32) is false if 0u else true
39
- // f32(bool) is 1.0 if true else 0.0
40
- // * 2.0 - 1.0 remaps 0.0 or 1.0 to -1.0 or 1.0 respectively
41
- return f32 (bool (mesh . flags & MESH_FLAGS_SIGN_DETERMINANT_MODEL_3X3_BIT)) * 2.0 - 1.0 ;
20
+ return mat3x3 <f32 >(
21
+ mesh . inverse_transpose_model[0 ]. xyz,
22
+ mesh . inverse_transpose_model[1 ]. xyz,
23
+ mesh . inverse_transpose_model[2 ]. xyz
24
+ ) * vertex_normal ;
42
25
}
43
26
44
27
fn mesh_tangent_local_to_world (model : mat4x4 <f32 >, vertex_tangent : vec4 <f32 >) -> vec4 <f32 > {
45
- // NOTE: The mikktspace method of normal mapping requires that the world tangent is
46
- // re-normalized in the vertex shader to match the way mikktspace bakes vertex tangents
47
- // and normal maps so that the exact inverse process is applied when shading. Blender, Unity,
48
- // Unreal Engine, Godot, and more all use the mikktspace method. Do not change this code
49
- // unless you really know what you are doing.
50
- // http://www.mikktspace.com/
51
28
return vec4 <f32 >(
52
- normalize (
53
- mat3x3 <f32 >(
54
- model [0 ]. xyz,
55
- model [1 ]. xyz,
56
- model [2 ]. xyz
57
- ) * vertex_tangent . xyz
58
- ),
59
- // NOTE: Multiplying by the sign of the determinant of the 3x3 model matrix accounts for
60
- // situations such as negative scaling.
61
- vertex_tangent . w * sign_determinant_model_3x3 ()
29
+ mat3x3 <f32 >(
30
+ model [0 ]. xyz,
31
+ model [1 ]. xyz,
32
+ model [2 ]. xyz
33
+ ) * vertex_tangent . xyz,
34
+ vertex_tangent . w
62
35
);
63
36
}
0 commit comments