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// Aqua extension of Crest OceanHelpersNew.hlsl::SampleDisplacementsNormals.
2// Crest evaluates this forward stencil per consumer. FFT caches it once after
3// cumulative ShapeCombine so vertex shading, SSS, and foam share the result.
4// Interpolating this half-float cache is an explicit Aqua approximation: it is
5// not algebraically identical to forming nonlinear normals/Jacobians per sample.
7const FFT_RESOLUTION: u32 = 256u;
8const LOD_COUNT: u32 = 5u;
9struct CascadeParams {
10 center: vec2<f32>,
11 scale: f32,
12 texture_res: f32,
13 inv_texture_res: f32,
14 texel_width: f32,
15 weight: f32,
16 max_wavelength: f32,
18struct CascadeLayout {
19 cascades: array<CascadeParams, 6>,
20 center: vec4<f32>,
21 // XY bed-map first-texel world origin, ZW inverse world extent.
22 bed_transform: vec4<f32>,
23 // X height minimum, Y height span (negative = no bed map), Z sea level.
24 bed_range: vec4<f32>,
26struct FftUniform {
27 cascade_layout: CascadeLayout,
28 params: vec4<f32>,
29 // x: active attenuation-bin count; reserved for future mode flags.
30 mode: vec4<f32>,
33@group(0) @binding(0) var displacement: texture_2d_array<f32>;
34@group(0) @binding(1) var surface_derivatives: texture_storage_2d_array<rgba16float, write>;
35@group(0) @binding(2) var<uniform> fft: FftUniform;
37@compute @workgroup_size(8, 8, 1)
38fn resolve_surface(@builtin(global_invocation_id) id: vec3<u32>) {
39 if any(id.xy >= vec2<u32>(FFT_RESOLUTION)) || id.z >= LOD_COUNT {
40 return;
41 }
42 let cascade = fft.cascade_layout.cascades[id.z];
43 let maximum = i32(FFT_RESOLUTION) - 1;
44 let center_coord = vec2<i32>(id.xy);
45 let x_coord = min(center_coord + vec2(1, 0), vec2(maximum));
46 let z_coord = min(center_coord + vec2(0, 1), vec2(maximum));
47 let center = textureLoad(displacement, center_coord, i32(id.z), 0).xyz;
48 let offset_x = textureLoad(displacement, x_coord, i32(id.z), 0).xyz;
49 let offset_z = textureLoad(displacement, z_coord, i32(id.z), 0).xyz;
50 let derivative_x = (offset_x - center) / cascade.texel_width;
51 let derivative_z = (offset_z - center) / cascade.texel_width;
52 let determinant = (1.0 + derivative_x.x) * (1.0 + derivative_z.z)
53 - derivative_x.z * derivative_z.x;
54 let tangent_x = vec3(1.0, 0.0, 0.0) + derivative_x;
55 let tangent_z = vec3(0.0, 0.0, 1.0) + derivative_z;
56 let normal_cross = cross(tangent_z, tangent_x);
57 textureStore(
58 surface_derivatives,
59 vec2<i32>(id.xy),
60 i32(id.z),
61 vec4(normal_cross, determinant),
62 );
Contents