3 bindings as prepass_bindings, 4 io::{Vertex, UncompressedVertex, VertexOutput, FragmentOutput, decompress_vertex}, 11 morph::{morph_position, morph_normal, morph_tangent}, 12 mesh_view_bindings::view, 13 view_transformations::position_world_to_clip, 18import package::render::rgb9e5; 23fn morph_vertex(vertex_in: UncompressedVertex, instance_index: u32) -> UncompressedVertex { 24 var vertex = vertex_in; 25 let first_vertex = mesh[instance_index].first_vertex_index; 26 let vertex_index = vertex.index - first_vertex; 27 let morph_descriptor_index = mesh[instance_index].morph_descriptor_index; 29 let weight_count = morph::layer_count(morph_descriptor_index); 30 for (var i: u32 = 0u; i < weight_count; i ++) { 31 let weight = morph::weight_at(i, morph_descriptor_index); 35 vertex.position += weight * morph_position(vertex_index, i, morph_descriptor_index); 37 vertex.normal += weight * morph_normal(vertex_index, i, morph_descriptor_index); 39 vertex.tangent += vec4(weight * morph_tangent(vertex_index, i, morph_descriptor_index), 0.0); 52fn morph_prev_vertex(vertex_in: UncompressedVertex, instance_index: u32) -> UncompressedVertex { 53 var vertex = vertex_in; 54 let first_vertex = mesh[instance_index].first_vertex_index; 55 let vertex_index = vertex.index - first_vertex; 56 let morph_descriptor_index = mesh[instance_index].morph_descriptor_index; 57 let weight_count = morph::layer_count(morph_descriptor_index); 58 for (var i: u32 = 0u; i < weight_count; i ++) { 59 let weight = morph::prev_weight_at(i, morph_descriptor_index); 63 vertex.position += weight * morph_position(vertex_index, i, morph_descriptor_index); 71fn vertex(vertex_no_morph: Vertex) -> VertexOutput { 72 var out: VertexOutput; 73 let uncompressed_vertex_no_morph = decompress_vertex(vertex_no_morph, vertex_no_morph.instance_index); 75 var vertex = morph_vertex(uncompressed_vertex_no_morph, vertex_no_morph.instance_index); 77 var vertex = uncompressed_vertex_no_morph; 79 let mesh_world_from_local = mesh_functions::get_world_from_local(vertex_no_morph.instance_index); 84 var world_from_local = skinning::skin_model( 87 vertex_no_morph.instance_index 90 var world_from_local = mesh_world_from_local; 92 out.world_position = mesh_functions::mesh_position_local_to_world(world_from_local, vec4<f32>(vertex.position, 1.0)); 93 out.position = position_world_to_clip(out.world_position.xyz); 94@if(UNCLIPPED_DEPTH_ORTHO_EMULATION) { 95 out.unclipped_depth = out.position.z; 96 out.position.z = min(out.position.z, 1.0); 103 out.uv_b = vertex.uv_b; 105@if(NORMAL_PREPASS_OR_DEFERRED_PREPASS) { 106@if(VERTEX_NORMALS && SKINNED) 107 out.world_normal = skinning::skin_normals(world_from_local, vertex.normal); 109 out.world_normal = mesh_functions::mesh_normal_local_to_world( 113 vertex_no_morph.instance_index 117 out.world_tangent = mesh_functions::mesh_tangent_local_to_world( 122 vertex_no_morph.instance_index 127 out.color = vertex.color; 131@if(MOTION_VECTOR_PREPASS) { 134@if(MORPH_TARGETS && HAS_PREVIOUS_MORPH) 135 let prev_vertex = morph_prev_vertex(uncompressed_vertex_no_morph, vertex_no_morph.instance_index); 137 let prev_vertex = uncompressed_vertex_no_morph; 139 let prev_vertex = uncompressed_vertex_no_morph; 142@if(SKINNED && HAS_PREVIOUS_SKIN) 143 let prev_model = skinning::skin_prev_model( 144 prev_vertex.joint_indices, 145 prev_vertex.joint_weights, 146 vertex_no_morph.instance_index 151 let prev_model = mesh_functions::get_previous_world_from_local(vertex_no_morph.instance_index); 155 let prev_model = mesh_functions::get_previous_world_from_local(vertex_no_morph.instance_index); 157 out.previous_world_position = mesh_functions::mesh_position_local_to_world( 159 vec4<f32>(prev_vertex.position, 1.0) 163@if(VERTEX_OUTPUT_INSTANCE_INDEX) 166 out.instance_index = vertex_no_morph.instance_index; 168@if(VISIBILITY_RANGE_DITHER) 169 out.visibility_range_dither = mesh_functions::get_visibility_range_dither_level( 170 vertex_no_morph.instance_index, mesh_world_from_local[3]); 177fn fragment(in: VertexOutput) -> FragmentOutput { 178 var out: FragmentOutput; 181 out.normal = vec4(in.world_normal * 0.5 + vec3(0.5), 1.0); 183@if(UNCLIPPED_DEPTH_ORTHO_EMULATION) 184 out.frag_depth = in.unclipped_depth; 186@if(MOTION_VECTOR_PREPASS) { 187 let clip_position_t = view.unjittered_clip_from_world * in.world_position; 188 let clip_position = clip_position_t.xy / clip_position_t.w; 189 let previous_clip_position_t = prepass_bindings::previous_view_uniforms.unjittered_clip_from_world * in.previous_world_position; 190 let previous_clip_position = previous_clip_position_t.xy / previous_clip_position_t.w; 197 out.motion_vector = (clip_position - previous_clip_position) * vec2(0.5, -0.5); 200@if(DEFERRED_PREPASS) { 205 out.deferred = vec4(0u, package::render::rgb9e5::vec3_to_rgb9e5_(vec3(1.0, 0.0, 1.0)), 0u, 0u); 206 out.deferred_lighting_pass_id = 1u;