Search across packages, versions, files, declarations, and comments. Use multiple terms to narrow results (AND), and add @vertex, @fragment, or @compute to filter by shader stage.
1#import bevy_pbr::{
2 mesh_bindings::mesh,
3 mesh_functions,
4 skinning,
5 morph::morph,
6 forward_io::{Vertex, VertexOutput},
7 view_transformations::position_world_to_clip,
8}
10#ifdef MORPH_TARGETS
11fn morph_vertex(vertex_in: Vertex) -> Vertex {
12 var vertex = vertex_in;
13 let first_vertex = mesh[vertex.instance_index].first_vertex_index;
14 let vertex_index = vertex.index - first_vertex;
16 let weight_count = bevy_pbr::morph::layer_count();
17 for (var i: u32 = 0u; i < weight_count; i ++) {
18 let weight = bevy_pbr::morph::weight_at(i);
19 if weight == 0.0 {
20 continue;
21 }
22 vertex.position += weight * morph(vertex_index, bevy_pbr::morph::position_offset, i);
23#ifdef VERTEX_NORMALS
24 vertex.normal += weight * morph(vertex_index, bevy_pbr::morph::normal_offset, i);
25#endif
26#ifdef VERTEX_TANGENTS
27 vertex.tangent += vec4(weight * morph(vertex_index, bevy_pbr::morph::tangent_offset, i), 0.0);
28#endif
29 }
30 return vertex;
32#endif
34@vertex
35fn vertex(vertex_no_morph: Vertex) -> VertexOutput {
36 var out: VertexOutput;
38#ifdef MORPH_TARGETS
39 var vertex = morph_vertex(vertex_no_morph);
40#else
41 var vertex = vertex_no_morph;
42#endif
44 let mesh_world_from_local = mesh_functions::get_world_from_local(vertex_no_morph.instance_index);
46#ifdef SKINNED
47 var world_from_local = skinning::skin_model(
48 vertex.joint_indices,
49 vertex.joint_weights,
50 vertex_no_morph.instance_index
51 );
52#else
53 // Use vertex_no_morph.instance_index instead of vertex.instance_index to work around a wgpu dx12 bug.
54 // See https://github.com/gfx-rs/naga/issues/2416 .
55 var world_from_local = mesh_world_from_local;
56#endif
58#ifdef VERTEX_NORMALS
59#ifdef SKINNED
60 out.world_normal = skinning::skin_normals(world_from_local, vertex.normal);
61#else
62 out.world_normal = mesh_functions::mesh_normal_local_to_world(
63 vertex.normal,
64 // Use vertex_no_morph.instance_index instead of vertex.instance_index to work around a wgpu dx12 bug.
65 // See https://github.com/gfx-rs/naga/issues/2416
66 vertex_no_morph.instance_index
67 );
68#endif
69#endif
71#ifdef VERTEX_POSITIONS
72 out.world_position = mesh_functions::mesh_position_local_to_world(world_from_local, vec4<f32>(vertex.position, 1.0));
73 out.position = position_world_to_clip(out.world_position.xyz);
74#endif
76#ifdef VERTEX_UVS_A
77 out.uv = vertex.uv;
78#endif
79#ifdef VERTEX_UVS_B
80 out.uv_b = vertex.uv_b;
81#endif
83#ifdef VERTEX_TANGENTS
84 out.world_tangent = mesh_functions::mesh_tangent_local_to_world(
85 world_from_local,
86 vertex.tangent,
87 // Use vertex_no_morph.instance_index instead of vertex.instance_index to work around a wgpu dx12 bug.
88 // See https://github.com/gfx-rs/naga/issues/2416
89 vertex_no_morph.instance_index
90 );
91#endif
93#ifdef VERTEX_COLORS
94 out.color = vertex.color;
95#endif
97#ifdef VERTEX_OUTPUT_INSTANCE_INDEX
98 // Use vertex_no_morph.instance_index instead of vertex.instance_index to work around a wgpu dx12 bug.
99 // See https://github.com/gfx-rs/naga/issues/2416
100 out.instance_index = vertex_no_morph.instance_index;
101#endif
103#ifdef VISIBILITY_RANGE_DITHER
104 out.visibility_range_dither = mesh_functions::get_visibility_range_dither_level(
105 vertex_no_morph.instance_index, mesh_world_from_local[3]);
106#endif
108 return out;
111@fragment
112fn fragment(
113 mesh: VertexOutput,
114) -> @location(0) vec4<f32> {
115#ifdef VERTEX_COLORS
116 return mesh.color;
117#else
118 return vec4<f32>(1.0, 0.0, 1.0, 1.0);
119#endif
Contents