1#import bevy_pbr::mesh_view_bindings::view 2#import bevy_pbr::mesh_functions::{ 4 get_visibility_range_dither_level, 6 mesh_tangent_local_to_world, 7 get_previous_world_from_local, 8 mesh_normal_local_to_world 10#import bevy_pbr::view_transformations::position_world_to_clip 11#import bevy_pbr::pbr_fragment::pbr_input_from_standard_material 12#import bevy_pbr::pbr_fragment::pbr_material_from_standard_material 13#import bevy_pbr::pbr_functions::alpha_discard 14#import bevy_pbr::pbr_functions::apply_pbr_lighting 15#import bevy_pbr::pbr_functions::main_pass_post_lighting_processing 16#import bevy_pbr::prepass_io::Vertex 17#import bevy_pbr::prepass_io::VertexOutput 21#import bevy_pbr::mesh_bindings::mesh 23#import bevy_feronia::wind::Wind 24#import bevy_feronia::types::{SampledNoise, DisplacedVertex, InstanceInfo} 27#import bevy_render::bindless::{bindless_samplers_filtering, bindless_textures_2d} 31#import bevy_feronia::bindings::{wind_indices, wind_material} 33#import bevy_feronia::bindings::{wind, noise_texture, noise_texture_sampler} 36#import bevy_feronia::displace::{displace_vertex_and_calc_normal} 37#import bevy_feronia::noise::sample_noise 39@group(0) @binding(1) var<uniform> globals: Globals; 42fn vertex(vertex: Vertex) -> VertexOutput { 43 var out: VertexOutput; 46 let slot = mesh[vertex.instance_index].material_and_lightmap_bind_group_slot & 0xffffu; 47 let wind = wind_material[wind_indices[slot].material]; 52 let world_from_local = get_world_from_local(vertex.instance_index); 55 var instance: InstanceInfo; 56 let camera_world_pos = view.world_position.xyz; 57 instance.world_from_local = world_from_local; 58 instance.instance_position = instance.world_from_local[3]; 59 instance.wrapped_time = globals.time; 60 instance.instance_index = vertex.instance_index; 62 let noise = sample_noise(instance, vertex.position); 64 var static_shadows = false; 67 #ifndef MOTION_VECTOR_PREPASS 68 static_shadows = true; 73 var displaced: DisplacedVertex; 75 displaced.world_position = (instance.world_from_local * vec4<f32>(vertex.position, 1.0)); 78 displaced.world_normal = mesh_normal_local_to_world(vertex.normal, instance.instance_index); 80 displaced.world_normal = vec3<f32>(0.0, 0.0, 1.0); 83 #ifdef VERTEX_TANGENTS 84 displaced.world_tangent = mesh_tangent_local_to_world(instance.world_from_local, vertex.tangent, instance.instance_index); 86 const local_fallback_tangent: vec4<f32> = vec4<f32>(1.0, 0.0, 0.0, 1.0); 87 let world_tangent_xyz = (instance.world_from_local * vec4<f32>(local_fallback_tangent.xyz, 0.0)).xyz; 89 displaced.world_tangent = vec4<f32>(normalize(world_tangent_xyz), local_fallback_tangent.w); 92 displaced = displace_vertex_and_calc_normal( 100 #ifdef VERTEX_TANGENTS 109#ifdef VERTEX_POSITIONS 110 out.position = position_world_to_clip(displaced.world_position.xyz); 111 out.world_position = displaced.world_position; 115 out.world_normal = displaced.world_normal; 122 out.uv_b = vertex.uv_b; 125#ifdef VERTEX_TANGENTS 126 out.world_tangent = displaced.world_tangent; 129#ifdef VERTEX_OUTPUT_INSTANCE_INDEX 130 out.instance_index = vertex.instance_index; 133#ifdef VISIBILITY_RANGE_DITHER 134 out.visibility_range_dither = get_visibility_range_dither_level( 135 vertex.instance_index, world_from_local[3]); 138#ifdef UNCLIPPED_DEPTH_ORTHO_EMULATION 139 out.unclipped_depth = view.projection[2][2] * out.world_position.z + view.projection[3][2]; 143#ifdef MOTION_VECTOR_PREPASS 147 var instance_prev: InstanceInfo; 150 instance_prev.world_from_local = get_previous_world_from_local(vertex.instance_index); 151 instance_prev.instance_position = instance_prev.world_from_local[3]; 152 instance_prev.wrapped_time = (globals.time - globals.delta_time); 153 instance_prev.instance_index = vertex.instance_index; 155 let noise_prev = sample_noise(instance_prev, vertex.position); 158 let displaced_prev = displace_vertex_and_calc_normal( 166#ifdef VERTEX_TANGENTS 174 out.previous_world_position = displaced_prev.world_position; 176#endif // MOTION_VECTOR_PREPASS