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#ifdef SKINNED
45 var world_from_local = skinning::skin_model(vertex.joint_indices, vertex.joint_weights);
46#else
47 // Use vertex_no_morph.instance_index instead of vertex.instance_index to work around a wgpu dx12 bug.
48 // See https://github.com/gfx-rs/naga/issues/2416 .
49 var world_from_local = mesh_functions::get_world_from_local(vertex_no_morph.instance_index);
50#endif
52#ifdef VERTEX_NORMALS
53#ifdef SKINNED
54 out.world_normal = skinning::skin_normals(world_from_local, vertex.normal);
55#else
56 out.world_normal = mesh_functions::mesh_normal_local_to_world(
57 vertex.normal,
58 // Use vertex_no_morph.instance_index instead of vertex.instance_index to work around a wgpu dx12 bug.
59 // See https://github.com/gfx-rs/naga/issues/2416
60 vertex_no_morph.instance_index
61 );
62#endif
63#endif
65#ifdef VERTEX_POSITIONS
66 out.world_position = mesh_functions::mesh_position_local_to_world(world_from_local, vec4<f32>(vertex.position, 1.0));
67 out.position = position_world_to_clip(out.world_position.xyz);
68#endif
70#ifdef VERTEX_UVS_A
71 out.uv = vertex.uv;
72#endif
73#ifdef VERTEX_UVS_B
74 out.uv_b = vertex.uv_b;
75#endif
77#ifdef VERTEX_TANGENTS
78 out.world_tangent = mesh_functions::mesh_tangent_local_to_world(
79 world_from_local,
80 vertex.tangent,
81 // Use vertex_no_morph.instance_index instead of vertex.instance_index to work around a wgpu dx12 bug.
82 // See https://github.com/gfx-rs/naga/issues/2416
83 vertex_no_morph.instance_index
84 );
85#endif
87#ifdef VERTEX_COLORS
88 out.color = vertex.color;
89#endif
91#ifdef VERTEX_OUTPUT_INSTANCE_INDEX
92 // Use vertex_no_morph.instance_index instead of vertex.instance_index to work around a wgpu dx12 bug.
93 // See https://github.com/gfx-rs/naga/issues/2416
94 out.instance_index = vertex_no_morph.instance_index;
95#endif
97#ifdef VISIBILITY_RANGE_DITHER
98 out.visibility_range_dither = mesh_functions::get_visibility_range_dither_level(
99 vertex_no_morph.instance_index, world_from_local[3]);
100#endif
102 return out;
105@fragment
106fn fragment(
107 mesh: VertexOutput,
108) -> @location(0) vec4<f32> {
109#ifdef VERTEX_COLORS
110 return mesh.color;
111#else
112 return vec4<f32>(1.0, 0.0, 1.0, 1.0);
113#endif
Contents