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#import bevy_pbr::mesh_view_bindings::{view, globals}
2#import bevy_pbr::mesh_bindings::mesh
3#import bevy_pbr::mesh_functions::{get_world_from_local, get_visibility_range_dither_level}
4#import bevy_pbr::view_transformations::position_world_to_clip
5#import bevy_pbr::forward_io::Vertex
8#import bevy_feronia::forward_sss_io::VertexOutput
9#import bevy_feronia::wind::Wind
10#import bevy_feronia::types::{SampledNoise, DisplacedVertex, InstanceInfo}
11#import bevy_feronia::displace::{displace_vertex_and_calc_normal}
12#import bevy_feronia::noise::sample_noise
14#ifdef BINDLESS
15 #import bevy_feronia::bindings::{wind_indices, wind_material}
16#else
17 #import bevy_feronia::bindings::{wind, noise_texture, noise_texture_sampler}
18#endif
21@vertex
22fn vertex(vertex: Vertex) -> VertexOutput {
23 var out: VertexOutput;
25#ifdef BINDLESS
26 let slot = mesh[vertex.instance_index].material_and_lightmap_bind_group_slot & 0xffffu;
27 let wind = wind_material[wind_indices[slot].material];
28#endif
30 let world_from_local = get_world_from_local(vertex.instance_index);
32 // --- INSTANCE ---
33 var instance: InstanceInfo;
34 let camera_world_pos = view.world_position.xyz;
35 instance.world_from_local = world_from_local;
36 instance.instance_position = instance.world_from_local[3];
37 instance.wrapped_time = globals.time;
38 instance.instance_index = vertex.instance_index;
40 let noise = sample_noise(instance, vertex.position);
42 // --- DISPLACEMENT ---
43 let displaced = displace_vertex_and_calc_normal(
44 wind,
45 noise,
46 vertex.position,
47 instance,
48#ifdef VERTEX_NORMALS
49 vertex.normal,
50#endif
51#ifdef VERTEX_TANGENTS
52 vertex.tangent,
53#endif
54#ifdef VERTEX_UVS_A
55 vertex.uv
56#endif
57 );
59#ifdef VERTEX_POSITIONS
60 out.position = position_world_to_clip(displaced.world_position.xyz);
61 out.world_position = displaced.world_position;
62#endif
64#ifdef VERTEX_NORMALS
65 out.world_normal = displaced.world_normal;
66#endif
68#ifdef VERTEX_UVS_A
69 out.uv = vertex.uv;
70#endif
71#ifdef VERTEX_UVS_B
72 out.uv_b = vertex.uv_b;
73#endif
75#ifdef VERTEX_TANGENTS
76 out.world_tangent = displaced.world_tangent;
77#endif
79#ifdef VERTEX_OUTPUT_INSTANCE_INDEX
80 out.instance_index = vertex.instance_index;
81#endif
83#ifdef VISIBILITY_RANGE_DITHER
84 out.visibility_range_dither = get_visibility_range_dither_level(
85 vertex.instance_index, world_from_local[3]);
86#endif
88#ifdef SUBSURFACE_SCATTERING
89 let local_pos = vertex.position;
91 let height = wind.aabb_max.y - wind.aabb_min.y;
93 let inverse_height = 1.0 / max(height, 0.00001);
95 // TODO support thickness texture instead of `thinness_factor`
96 out.thinness_factor = saturate((local_pos.y - wind.aabb_min.y) * inverse_height);
97 #endif
99 return out;
Contents