5 prepass_io::{Vertex, VertexOutput, FragmentOutput}, 8 morph::{morph_position, morph_normal, morph_tangent}, 9 mesh_view_bindings::view, 10 view_transformations::position_world_to_clip, 13#ifdef DEFERRED_PREPASS 14#import bevy_pbr::rgb9e5 20fn morph_vertex(vertex_in: Vertex, instance_index: u32) -> Vertex { 21 var vertex = vertex_in; 22 let first_vertex = mesh[instance_index].first_vertex_index; 23 let vertex_index = vertex.index - first_vertex; 25 let weight_count = morph::layer_count(instance_index); 26 for (var i: u32 = 0u; i < weight_count; i ++) { 27 let weight = morph::weight_at(i, instance_index); 31 vertex.position += weight * morph_position(vertex_index, i, instance_index); 33 vertex.normal += weight * morph_normal(vertex_index, i, instance_index); 36 vertex.tangent += vec4(weight * morph_tangent(vertex_index, i, instance_index), 0.0); 49fn morph_prev_vertex(vertex_in: Vertex, instance_index: u32) -> Vertex { 50 var vertex = vertex_in; 51 let first_vertex = mesh[instance_index].first_vertex_index; 52 let vertex_index = vertex.index - first_vertex; 53 let weight_count = morph::layer_count(instance_index); 54 for (var i: u32 = 0u; i < weight_count; i ++) { 55 let weight = morph::prev_weight_at(i, instance_index); 59 vertex.position += weight * morph_position(vertex_index, i, instance_index); 65#endif // MORPH_TARGETS 68fn vertex(vertex_no_morph: Vertex) -> VertexOutput { 69 var out: VertexOutput; 72 var vertex = morph_vertex(vertex_no_morph, vertex_no_morph.instance_index); 74 var vertex = vertex_no_morph; 77 let mesh_world_from_local = mesh_functions::get_world_from_local(vertex_no_morph.instance_index); 82 var world_from_local = skinning::skin_model( 85 vertex_no_morph.instance_index 88 var world_from_local = mesh_world_from_local; 91 out.world_position = mesh_functions::mesh_position_local_to_world(world_from_local, vec4<f32>(vertex.position, 1.0)); 92 out.position = position_world_to_clip(out.world_position.xyz); 93#ifdef UNCLIPPED_DEPTH_ORTHO_EMULATION 94 out.unclipped_depth = out.position.z; 95 out.position.z = min(out.position.z, 1.0); 96#endif // UNCLIPPED_DEPTH_ORTHO_EMULATION 100#endif // VERTEX_UVS_A 103 out.uv_b = vertex.uv_b; 104#endif // VERTEX_UVS_B 106#ifdef NORMAL_PREPASS_OR_DEFERRED_PREPASS 109 out.world_normal = skinning::skin_normals(world_from_local, vertex.normal); 111 out.world_normal = mesh_functions::mesh_normal_local_to_world( 115 vertex_no_morph.instance_index 118#endif // VERTEX_NORMALS 120#ifdef VERTEX_TANGENTS 121 out.world_tangent = mesh_functions::mesh_tangent_local_to_world( 126 vertex_no_morph.instance_index 128#endif // VERTEX_TANGENTS 129#endif // NORMAL_PREPASS_OR_DEFERRED_PREPASS 132 out.color = vertex.color; 137#ifdef MOTION_VECTOR_PREPASS 142#ifdef HAS_PREVIOUS_MORPH 143 let prev_vertex = morph_prev_vertex(vertex_no_morph, vertex_no_morph.instance_index); 144#else // HAS_PREVIOUS_MORPH 145 let prev_vertex = vertex_no_morph; 146#endif // HAS_PREVIOUS_MORPH 148#else // MORPH_TARGETS 149 let prev_vertex = vertex_no_morph; 150#endif // MORPH_TARGETS 155#ifdef HAS_PREVIOUS_SKIN 156 let prev_model = skinning::skin_prev_model( 157 prev_vertex.joint_indices, 158 prev_vertex.joint_weights, 159 vertex_no_morph.instance_index 161#else // HAS_PREVIOUS_SKIN 164 let prev_model = mesh_functions::get_previous_world_from_local(vertex_no_morph.instance_index); 165#endif // HAS_PREVIOUS_SKIN 170 let prev_model = mesh_functions::get_previous_world_from_local(vertex_no_morph.instance_index); 173 out.previous_world_position = mesh_functions::mesh_position_local_to_world( 175 vec4<f32>(prev_vertex.position, 1.0) 177#endif // MOTION_VECTOR_PREPASS 179#ifdef VERTEX_OUTPUT_INSTANCE_INDEX 182 out.instance_index = vertex_no_morph.instance_index; 185#ifdef VISIBILITY_RANGE_DITHER 186 out.visibility_range_dither = mesh_functions::get_visibility_range_dither_level( 187 vertex_no_morph.instance_index, mesh_world_from_local[3]); 188#endif // VISIBILITY_RANGE_DITHER 193#ifdef PREPASS_FRAGMENT 195fn fragment(in: VertexOutput) -> FragmentOutput { 196 var out: FragmentOutput; 199 out.normal = vec4(in.world_normal * 0.5 + vec3(0.5), 1.0); 202#ifdef UNCLIPPED_DEPTH_ORTHO_EMULATION 203 out.frag_depth = in.unclipped_depth; 204#endif // UNCLIPPED_DEPTH_ORTHO_EMULATION 206#ifdef MOTION_VECTOR_PREPASS 207 let clip_position_t = view.unjittered_clip_from_world * in.world_position; 208 let clip_position = clip_position_t.xy / clip_position_t.w; 209 let previous_clip_position_t = prepass_bindings::previous_view_uniforms.clip_from_world * in.previous_world_position; 210 let previous_clip_position = previous_clip_position_t.xy / previous_clip_position_t.w; 217 out.motion_vector = (clip_position - previous_clip_position) * vec2(0.5, -0.5); 218#endif // MOTION_VECTOR_PREPASS 220#ifdef DEFERRED_PREPASS 225 out.deferred = vec4(0u, bevy_pbr::rgb9e5::vec3_to_rgb9e5_(vec3(1.0, 0.0, 1.0)), 0u, 0u); 226 out.deferred_lighting_pass_id = 1u; 231#endif // PREPASS_FRAGMENT