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::mesh2d::functions as mesh_functions;
3struct UncompressedVertex {
4 @builtin(instance_index) instance_index: u32,
5 @if(VERTEX_POSITIONS)
6 @location(0) position: vec3<f32>,
7 @if(VERTEX_NORMALS)
8 @location(1) normal: vec3<f32>,
9 @if(VERTEX_UVS)
10 @location(2) uv: vec2<f32>,
11 @if(VERTEX_TANGENTS)
12 @location(3) tangent: vec4<f32>,
13 @if(VERTEX_COLORS)
14 @location(4) color: vec4<f32>,
15};
17struct Vertex {
18 @builtin(instance_index) instance_index: u32,
19 @if(VERTEX_POSITIONS && VERTEX_POSITIONS_COMPRESSED)
20 @location(0) compressed_position: vec4<f32>,
21 @if(VERTEX_POSITIONS && !VERTEX_POSITIONS_COMPRESSED)
22 @location(0) position: vec3<f32>,
23 @if(VERTEX_NORMALS && VERTEX_NORMALS_COMPRESSED)
24 @location(1) compressed_normal: vec2<f32>,
25 @if(VERTEX_NORMALS && !VERTEX_NORMALS_COMPRESSED)
26 @location(1) normal: vec3<f32>,
27 @if(VERTEX_UVS && VERTEX_UVS_COMPRESSED)
28 @location(2) compressed_uv: vec2<f32>,
29 @if(VERTEX_UVS && !VERTEX_UVS_COMPRESSED)
30 @location(2) uv: vec2<f32>,
31 @if(VERTEX_TANGENTS && VERTEX_TANGENTS_COMPRESSED)
32 @location(3) compressed_tangent: vec2<f32>,
33 @if(VERTEX_TANGENTS && !VERTEX_TANGENTS_COMPRESSED)
34 @location(3) tangent: vec4<f32>,
35 @if(VERTEX_COLORS)
36 @location(4) color: vec4<f32>,
37};
39/// The instance_index parameter must match vertex_in.instance_index. This is a work around for a wgpu dx12 bug.
40/// See https://github.com/gfx-rs/naga/issues/2416
41fn decompress_vertex(vertex_in: Vertex, instance_index: u32) -> UncompressedVertex {
42 let mesh_metadata = mesh_functions::get_metadata(instance_index);
43 var uncompressed_vertex: UncompressedVertex;
44 uncompressed_vertex.instance_index = instance_index;
45 @if(VERTEX_POSITIONS_COMPRESSED)
46 uncompressed_vertex.position = bevy_render::utils::decompress_vertex_position(vertex_in.compressed_position, mesh_metadata.aabb_center, mesh_metadata.aabb_half_extents);
47 @else
48 uncompressed_vertex.position = vertex_in.position;
49 @if(VERTEX_NORMALS && VERTEX_NORMALS_COMPRESSED)
50 uncompressed_vertex.normal = bevy_render::utils::decompress_vertex_normal(vertex_in.compressed_normal);
51 @if(VERTEX_NORMALS && !VERTEX_NORMALS_COMPRESSED)
52 uncompressed_vertex.normal = vertex_in.normal;
53 @if(VERTEX_UVS && VERTEX_UVS_COMPRESSED)
54 let uv_min_and_extents = mesh_metadata.uv_channels_min_and_extents[0];
55 @if(VERTEX_UVS && VERTEX_UVS_COMPRESSED)
56 uncompressed_vertex.uv = bevy_render::utils::decompress_vertex_uv(vertex_in.compressed_uv, uv_min_and_extents);
57 @if(VERTEX_UVS && !VERTEX_UVS_COMPRESSED)
58 uncompressed_vertex.uv = vertex_in.uv;
59 @if(VERTEX_TANGENTS && VERTEX_TANGENTS_COMPRESSED)
60 uncompressed_vertex.tangent = bevy_render::utils::decompress_vertex_tangent(vertex_in.compressed_tangent);
61 @if(VERTEX_TANGENTS && !VERTEX_TANGENTS_COMPRESSED)
62 uncompressed_vertex.tangent = vertex_in.tangent;
63 @if(VERTEX_COLORS)
64 uncompressed_vertex.color = vertex_in.color;
65 return uncompressed_vertex;
Contents