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// Most of these attributes are not used in the default prepass fragment shader, but they are still needed so we can
2// pass them to custom prepass shaders like pbr_prepass.wesl.
3struct UncompressedVertex {
4 @builtin(instance_index) instance_index: u32,
5 @location(0) position: vec3<f32>,
7 @if(VERTEX_UVS_A)
8 @location(1) uv: vec2<f32>,
10 @if(VERTEX_UVS_B)
11 @location(2) uv_b: vec2<f32>,
13 @if(NORMAL_PREPASS_OR_DEFERRED_PREPASS && VERTEX_NORMALS)
14 @location(3) normal: vec3<f32>,
15 @if(NORMAL_PREPASS_OR_DEFERRED_PREPASS && VERTEX_TANGENTS)
16 @location(4) tangent: vec4<f32>,
18 @if(SKINNED)
19 @location(5) joint_indices: vec4<u32>,
20 @if(SKINNED)
21 @location(6) joint_weights: vec4<f32>,
23 @if(VERTEX_COLORS)
24 @location(7) color: vec4<f32>,
26 @if(MORPH_TARGETS)
27 @builtin(vertex_index) index: u32,
28};
30struct Vertex {
31 @builtin(instance_index) instance_index: u32,
32 @if(VERTEX_POSITIONS_COMPRESSED)
33 @location(0) compressed_position: vec4<f32>,
34 @else
35 @location(0) position: vec3<f32>,
36 @if(VERTEX_UVS_A && VERTEX_UVS_A_COMPRESSED)
37 @location(1) compressed_uv: vec2<f32>,
38 @if(VERTEX_UVS_A && !VERTEX_UVS_A_COMPRESSED)
39 @location(1) uv: vec2<f32>,
40 @if(VERTEX_UVS_B && VERTEX_UVS_B_COMPRESSED)
41 @location(2) compressed_uv_b: vec2<f32>,
42 @if(VERTEX_UVS_B && !VERTEX_UVS_B_COMPRESSED)
43 @location(2) uv_b: vec2<f32>,
45 @if(NORMAL_PREPASS_OR_DEFERRED_PREPASS && VERTEX_NORMALS && VERTEX_NORMALS_COMPRESSED)
46 @location(3) compressed_normal: vec2<f32>,
47 @if(NORMAL_PREPASS_OR_DEFERRED_PREPASS && VERTEX_NORMALS && !VERTEX_NORMALS_COMPRESSED)
48 @location(3) normal: vec3<f32>,
49 @if(NORMAL_PREPASS_OR_DEFERRED_PREPASS && VERTEX_TANGENTS && VERTEX_TANGENTS_COMPRESSED)
50 @location(4) compressed_tangent: vec2<f32>,
51 @if(NORMAL_PREPASS_OR_DEFERRED_PREPASS && VERTEX_TANGENTS && !VERTEX_TANGENTS_COMPRESSED)
52 @location(4) tangent: vec4<f32>,
54 @if(SKINNED)
55 @location(5) joint_indices: vec4<u32>,
56 @if(SKINNED)
57 @location(6) joint_weights: vec4<f32>,
59 @if(VERTEX_COLORS)
60 @location(7) color: vec4<f32>,
62 @if(MORPH_TARGETS)
63 @builtin(vertex_index) index: u32,
66// The instance_index parameter must match vertex_in.instance_index. This is a work around for a wgpu dx12 bug.
67// See https://github.com/gfx-rs/naga/issues/2416
68fn decompress_vertex(vertex_in: Vertex, instance_index: u32) -> UncompressedVertex {
69 let mesh_metadata = package::render::mesh_functions::get_metadata(instance_index);
70 var uncompressed_vertex: UncompressedVertex;
71 uncompressed_vertex.instance_index = instance_index;
72@if(VERTEX_POSITIONS_COMPRESSED)
73 uncompressed_vertex.position = bevy_render::utils::decompress_vertex_position(vertex_in.compressed_position, mesh_metadata.aabb_center, mesh_metadata.aabb_half_extents);
74@else
75 uncompressed_vertex.position = vertex_in.position;
76@if(NORMAL_PREPASS_OR_DEFERRED_PREPASS && VERTEX_NORMALS && VERTEX_NORMALS_COMPRESSED)
77 uncompressed_vertex.normal = bevy_render::utils::decompress_vertex_normal(vertex_in.compressed_normal);
78@if(NORMAL_PREPASS_OR_DEFERRED_PREPASS && VERTEX_NORMALS && !VERTEX_NORMALS_COMPRESSED)
79 uncompressed_vertex.normal = vertex_in.normal;
80@if(NORMAL_PREPASS_OR_DEFERRED_PREPASS && VERTEX_TANGENTS && VERTEX_TANGENTS_COMPRESSED)
81 uncompressed_vertex.tangent = bevy_render::utils::decompress_vertex_tangent(vertex_in.compressed_tangent);
82@if(NORMAL_PREPASS_OR_DEFERRED_PREPASS && VERTEX_TANGENTS && !VERTEX_TANGENTS_COMPRESSED)
83 uncompressed_vertex.tangent = vertex_in.tangent;
84@if(VERTEX_UVS_A && VERTEX_UVS_A_COMPRESSED) {
85 let uv_min_and_extents_a = mesh_metadata.uv_channels_min_and_extents[0];
86 uncompressed_vertex.uv = bevy_render::utils::decompress_vertex_uv(vertex_in.compressed_uv, uv_min_and_extents_a);
88@if(VERTEX_UVS_A && !VERTEX_UVS_A_COMPRESSED)
89 uncompressed_vertex.uv = vertex_in.uv;
90@if(VERTEX_UVS_B && VERTEX_UVS_B_COMPRESSED) {
91 let uv_min_and_extents_b = mesh_metadata.uv_channels_min_and_extents[1];
92 uncompressed_vertex.uv_b = bevy_render::utils::decompress_vertex_uv(vertex_in.compressed_uv_b, uv_min_and_extents_b);
94@if(VERTEX_UVS_B && !VERTEX_UVS_B_COMPRESSED)
95 uncompressed_vertex.uv_b = vertex_in.uv_b;
96@if(VERTEX_COLORS)
97 uncompressed_vertex.color = vertex_in.color;
98@if(SKINNED) {
99 uncompressed_vertex.joint_indices = vertex_in.joint_indices;
100 uncompressed_vertex.joint_weights = vertex_in.joint_weights;
102@if(MORPH_TARGETS)
103 uncompressed_vertex.index = vertex_in.index;
104 return uncompressed_vertex;
107struct VertexOutput {
108 /// This is `clip position` when the struct is used as a vertex stage output
109 /// and `frag coord` when used as a fragment stage input
110 @builtin(position) position: vec4<f32>,
112 @if(VERTEX_UVS_A)
113 @location(0) uv: vec2<f32>,
115 @if(VERTEX_UVS_B)
116 @location(1) uv_b: vec2<f32>,
118 @if(NORMAL_PREPASS_OR_DEFERRED_PREPASS)
119 @location(2) world_normal: vec3<f32>,
120 @if(NORMAL_PREPASS_OR_DEFERRED_PREPASS && VERTEX_TANGENTS)
121 @location(3) world_tangent: vec4<f32>,
123 @location(4) world_position: vec4<f32>,
124 @if(MOTION_VECTOR_PREPASS)
125 @location(5) previous_world_position: vec4<f32>,
127 @if(UNCLIPPED_DEPTH_ORTHO_EMULATION)
128 @location(6) unclipped_depth: f32,
129 @if(VERTEX_OUTPUT_INSTANCE_INDEX)
130 @location(7) @interpolate(flat) instance_index: u32,
132 @if(VERTEX_COLORS)
133 @location(8) color: vec4<f32>,
135 @if(VISIBILITY_RANGE_DITHER)
136 @location(9) @interpolate(flat) visibility_range_dither: i32,
139@if(PREPASS_FRAGMENT)
140struct FragmentOutput {
141 @if(NORMAL_PREPASS)
142 @location(0) normal: vec4<f32>,
144 @if(MOTION_VECTOR_PREPASS)
145 @location(1) motion_vector: vec2<f32>,
147 @if(DEFERRED_PREPASS)
148 @location(2) deferred: vec4<u32>,
149 @if(DEFERRED_PREPASS)
150 @location(3) deferred_lighting_pass_id: u32,
152 @if(UNCLIPPED_DEPTH_ORTHO_EMULATION)
153 @builtin(frag_depth) frag_depth: f32,
Contents