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.
1import package::render::{
2 mesh_bindings::mesh,
3 mesh_functions,
4 skinning,
5 morph::{morph_position, morph_normal, morph_tangent},
6 forward_io::{Vertex, UncompressedVertex, VertexOutput, decompress_vertex},
7 view_transformations::position_world_to_clip,
8};
10@if(MORPH_TARGETS)
11/// The instance_index parameter must match vertex_in.instance_index. This is a work around for a wgpu dx12 bug.
12/// See https://github.com/gfx-rs/naga/issues/2416
13fn morph_vertex(vertex_in: UncompressedVertex, instance_index: u32) -> UncompressedVertex {
14 var vertex = vertex_in;
15 let first_vertex = mesh[instance_index].first_vertex_index;
16 let vertex_index = vertex.index - first_vertex;
17 let morph_descriptor_index = mesh[instance_index].morph_descriptor_index;
19 let weight_count = package::render::morph::layer_count(morph_descriptor_index);
20 for (var i: u32 = 0u; i < weight_count; i ++) {
21 let weight = package::render::morph::weight_at(i, morph_descriptor_index);
22 if weight == 0.0 {
23 continue;
24 }
25 vertex.position += weight * morph_position(vertex_index, i, morph_descriptor_index);
26 @if(VERTEX_NORMALS)
27 vertex.normal += weight * morph_normal(vertex_index, i, morph_descriptor_index);
28 @if(VERTEX_TANGENTS)
29 vertex.tangent += vec4(weight * morph_tangent(vertex_index, i, morph_descriptor_index), 0.0);
30 }
31 return vertex;
34@vertex
35fn vertex(vertex_no_morph: Vertex) -> VertexOutput {
36 var out: VertexOutput;
37 let uncompressed_vertex_no_morph = decompress_vertex(vertex_no_morph, vertex_no_morph.instance_index);
38@if(MORPH_TARGETS)
39 var vertex = morph_vertex(uncompressed_vertex_no_morph, vertex_no_morph.instance_index);
40@else
41 var vertex = uncompressed_vertex_no_morph;
43 let mesh_world_from_local = mesh_functions::get_world_from_local(vertex_no_morph.instance_index);
45@if(SKINNED)
46 // Use vertex_no_morph.instance_index instead of vertex.instance_index to work around a wgpu dx12 bug.
47 // See https://github.com/gfx-rs/naga/issues/2416 .
48 var world_from_local = skinning::skin_model(
49 vertex.joint_indices,
50 vertex.joint_weights,
51 vertex_no_morph.instance_index
52 );
53@else
54 var world_from_local = mesh_world_from_local;
56@if(VERTEX_NORMALS && SKINNED)
57 out.world_normal = skinning::skin_normals(world_from_local, vertex.normal);
58@if(VERTEX_NORMALS && !SKINNED)
59 out.world_normal = mesh_functions::mesh_normal_local_to_world(
60 vertex.normal,
61 // Use vertex_no_morph.instance_index instead of vertex.instance_index to work around a wgpu dx12 bug.
62 // See https://github.com/gfx-rs/naga/issues/2416
63 vertex_no_morph.instance_index
64 );
66@if(VERTEX_POSITIONS)
67 out.world_position = mesh_functions::mesh_position_local_to_world(world_from_local, vec4<f32>(vertex.position, 1.0));
68@if(VERTEX_POSITIONS)
69 out.position = position_world_to_clip(out.world_position.xyz);
71@if(VERTEX_UVS_A)
72 out.uv = vertex.uv;
73@if(VERTEX_UVS_B)
74 out.uv_b = vertex.uv_b;
76@if(VERTEX_TANGENTS)
77 out.world_tangent = mesh_functions::mesh_tangent_local_to_world(
78 world_from_local,
79 vertex.tangent,
80 // Use vertex_no_morph.instance_index instead of vertex.instance_index to work around a wgpu dx12 bug.
81 // See https://github.com/gfx-rs/naga/issues/2416
82 vertex_no_morph.instance_index
83 );
85@if(VERTEX_COLORS)
86 out.color = vertex.color;
88@if(VERTEX_OUTPUT_INSTANCE_INDEX)
89 // Use vertex_no_morph.instance_index instead of vertex.instance_index to work around a wgpu dx12 bug.
90 // See https://github.com/gfx-rs/naga/issues/2416
91 out.instance_index = vertex_no_morph.instance_index;
93@if(VISIBILITY_RANGE_DITHER)
94 out.visibility_range_dither = mesh_functions::get_visibility_range_dither_level(
95 vertex_no_morph.instance_index, mesh_world_from_local[3]);
97 return out;
100@fragment
101fn fragment(
102 mesh: VertexOutput,
103) -> @location(0) vec4<f32> {
104@if(VERTEX_COLORS)
105 return mesh.color;
106@else
107 return vec4<f32>(1.0, 0.0, 1.0, 1.0);
Contents