| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- // Post-Process Composite Pass:
- // 1. Depth-Aware Bilateral Upsample of Half-Res Volumetric Clouds onto Full-Res HDR Scene
- // 2. ACES Filmic Tone Mapping + Cold Chechen Winter Grading + Subtle Vignette
- // 3. Optional F4 Render Pass PIP (Dual Paraboloid Front/Back, Sun Shadow Map, Cloud Shadow Map)
- @group(0) @binding(0) var<uniform> u: GlobalUniforms;
- @group(0) @binding(6) var shadow_tex: texture_depth_2d;
- @group(0) @binding(8) var cloud_shadow_tex: texture_2d<f32>;
- @group(0) @binding(9) var linear_clamp_sampler: sampler;
- @group(0) @binding(10) var dp_tex: texture_2d_array<f32>;
- @group(1) @binding(0) var hdr_scene_tex: texture_2d<f32>;
- @group(1) @binding(1) var half_cloud_tex: texture_2d<f32>;
- @group(1) @binding(2) var scene_depth_tex: texture_depth_2d;
- struct VsOut {
- @builtin(position) position: vec4<f32>,
- @location(0) uv: vec2<f32>,
- };
- @vertex
- fn vs_main(@builtin(vertex_index) vid: u32) -> VsOut {
- var out: VsOut;
- let x = f32(i32(vid & 1u) * 4 - 1);
- let y = f32(i32(vid >> 1u) * 4 - 1);
- out.position = vec4<f32>(x, y, 0.0, 1.0);
- out.uv = vec2<f32>(x * 0.5 + 0.5, -y * 0.5 + 0.5);
- return out;
- }
- fn aces_filmic(x: vec3<f32>) -> vec3<f32> {
- let a = 2.51;
- let b = 0.03;
- let c = 2.43;
- let d = 0.59;
- let e = 0.14;
- return clamp((x * (a * x + b)) / (x * (c * x + d) + e), vec3<f32>(0.0), vec3<f32>(1.0));
- }
- fn sample_cloud_bilateral(uv: vec2<f32>, full_depth: f32) -> vec4<f32> {
- if (full_depth < 0.999999) {
- return vec4<f32>(0.0, 0.0, 0.0, 1.0);
- }
- let half_dims = vec2<f32>(textureDimensions(half_cloud_tex));
- let depth_dims = vec2<f32>(textureDimensions(scene_depth_tex));
- let base_uv = (floor(uv * half_dims - 0.5) + 0.5) / half_dims;
- let step_uv = 1.0 / half_dims;
- var sum = vec4<f32>(0.0);
- var wsum = 0.0;
- for (var y = 0; y <= 1; y = y + 1) {
- for (var x = 0; x <= 1; x = x + 1) {
- let suv = clamp(base_uv + vec2<f32>(f32(x), f32(y)) * step_uv, vec2<f32>(0.0), vec2<f32>(1.0));
- let d_px = vec2<i32>(clamp(suv * depth_dims, vec2<f32>(0.0), depth_dims - 1.0));
- let sd = textureLoad(scene_depth_tex, d_px, 0);
- let w = select(0.001, 1.0, sd >= 0.999999);
- sum += textureSampleLevel(half_cloud_tex, linear_clamp_sampler, suv, 0.0) * w;
- wsum += w;
- }
- }
- if (wsum > 0.001) {
- return sum / wsum;
- }
- return vec4<f32>(0.0, 0.0, 0.0, 1.0);
- }
- @fragment
- fn fs_main(in: VsOut) -> @location(0) vec4<f32> {
- let supp = clamp(f32(u.flags.z) * 0.001, 0.0, 1.0);
- let dmg = clamp(f32(u.flags.w) * 0.001, 0.0, 1.0);
- let dims = vec2<f32>(textureDimensions(hdr_scene_tex));
- let aspect = dims.x / max(dims.y, 1.0);
- let centered = (in.uv - vec2<f32>(0.5, 0.5)) * vec2<f32>(aspect, 1.0);
- let rad = length(centered);
- // Dynamic Suppression Pixelated Vision (edges pixelate earlier; full frame pixelates at peak pinning)
- var sample_uv = in.uv;
- if (supp > 0.04) {
- let pix_amt = smoothstep(0.04, 1.0, supp);
- let edge_factor = mix(0.45, 1.35, smoothstep(0.18, 0.82, rad));
- let block_px = max(1.0, floor(1.0 + pix_amt * pix_amt * 11.0 * edge_factor));
- sample_uv = clamp(
- (floor(in.uv * dims / block_px) + 0.5) * block_px / dims,
- vec2<f32>(0.0005),
- vec2<f32>(0.9995),
- );
- }
- let depth_dims = vec2<f32>(textureDimensions(scene_depth_tex));
- let px = vec2<i32>(clamp(sample_uv * depth_dims, vec2<f32>(0.0), depth_dims - 1.0));
- let raw_depth = textureLoad(scene_depth_tex, px, 0);
- var hdr = textureSampleLevel(hdr_scene_tex, linear_clamp_sampler, sample_uv, 0.0).rgb;
- // Subtle peripheral chromatic split under heavy suppression
- if (supp > 0.30) {
- let ca_amt = 0.008 * smoothstep(0.30, 1.0, supp) * smoothstep(0.20, 0.85, rad);
- let ca_dir = (in.uv - vec2<f32>(0.5, 0.5)) * ca_amt;
- let r_ch = textureSampleLevel(hdr_scene_tex, linear_clamp_sampler, clamp(sample_uv + ca_dir, vec2<f32>(0.001), vec2<f32>(0.999)), 0.0).r;
- let b_ch = textureSampleLevel(hdr_scene_tex, linear_clamp_sampler, clamp(sample_uv - ca_dir, vec2<f32>(0.001), vec2<f32>(0.999)), 0.0).b;
- hdr.r = mix(hdr.r, r_ch, 0.65);
- hdr.b = mix(hdr.b, b_ch, 0.65);
- }
- // Composite volumetric clouds ONLY onto sky background with bilateral depth edge awareness
- if (raw_depth >= 0.999999) {
- let cloud = sample_cloud_bilateral(sample_uv, raw_depth);
- hdr = hdr * cloud.a + cloud.rgb;
- }
- // ACES Filmic Tone Mapping + cold winter & adrenaline suppression desaturation
- var ldr = aces_filmic(hdr * 1.08);
- let luma = dot(ldr, vec3<f32>(0.299, 0.587, 0.114));
- ldr = mix(vec3<f32>(luma), ldr, 0.86 - supp * 0.44);
- ldr = pow(ldr, vec3<f32>(1.0 / 2.2));
- // Baseline subtle vignette + pulsed radial suppression tunnel-vision vignette
- let vig_uv = in.uv * (1.0 - in.uv.yx);
- let vig_base = clamp(pow(vig_uv.x * vig_uv.y * 16.0, 0.16), 0.72, 1.0);
- let pulse = 0.5 + 0.5 * sin(u.camera_pos.w * 7.5);
- let supp_curve = smoothstep(0.02, 1.0, supp);
- let inner_r = mix(0.68, 0.16, supp_curve) - pulse * 0.03 * supp_curve;
- let outer_r = mix(1.22, 0.66, supp_curve);
- let tunnel = 1.0 - smoothstep(inner_r, outer_r, rad);
- let supp_vig = mix(1.0, mix(0.03, 1.0, tunnel), supp_curve * 0.96);
- ldr *= vig_base * supp_vig;
- // Smooth radial crimson edge flash on direct hit
- if (dmg > 0.01) {
- let dmg_edge = smoothstep(0.25, 0.92, rad) * dmg;
- ldr = mix(ldr, vec3<f32>(0.62, 0.05, 0.04), clamp(dmg_edge * 0.65, 0.0, 0.65));
- }
- // Optional F4 Render Pass PIP Inspection Overlay (Bottom-Right 4 tiles)
- if (u.flags.y != 0u) {
- let pip_w = 0.165;
- let pip_h = 0.22;
- let pad = 0.012;
- let y0 = 1.0 - pad - pip_h;
- let y1 = 1.0 - pad;
- if (in.uv.y >= y0 && in.uv.y <= y1) {
- let py = (in.uv.y - y0) / pip_h;
- // Tile 3 (rightmost): 2D Cloud Shadow Map
- let x3_0 = 1.0 - pad - pip_w;
- // Tile 2: Sun Shadow Map
- let x2_0 = x3_0 - pad - pip_w;
- // Tile 1: Dual Paraboloid Back Hemisphere
- let x1_0 = x2_0 - pad - pip_w;
- // Tile 0: Dual Paraboloid Front Hemisphere
- let x0_0 = x1_0 - pad - pip_w;
- if (in.uv.x >= x0_0 && in.uv.x <= x0_0 + pip_w) {
- let puv = vec2<f32>((in.uv.x - x0_0) / pip_w, py);
- let dp = textureSampleLevel(dp_tex, linear_clamp_sampler, puv, 0, 0.0).rgb;
- ldr = pow(aces_filmic(dp), vec3<f32>(1.0 / 2.2));
- } else if (in.uv.x >= x1_0 && in.uv.x <= x1_0 + pip_w) {
- let puv = vec2<f32>((in.uv.x - x1_0) / pip_w, py);
- let dp = textureSampleLevel(dp_tex, linear_clamp_sampler, puv, 1, 0.0).rgb;
- ldr = pow(aces_filmic(dp), vec3<f32>(1.0 / 2.2));
- } else if (in.uv.x >= x2_0 && in.uv.x <= x2_0 + pip_w) {
- let puv = vec2<f32>((in.uv.x - x2_0) / pip_w, py);
- let s_dims = vec2<f32>(textureDimensions(shadow_tex));
- let spx = vec2<i32>(clamp(puv * s_dims, vec2<f32>(0.0), s_dims - 1.0));
- let d = textureLoad(shadow_tex, spx, 0);
- ldr = vec3<f32>(d);
- } else if (in.uv.x >= x3_0 && in.uv.x <= x3_0 + pip_w) {
- let puv = vec2<f32>((in.uv.x - x3_0) / pip_w, py);
- let cs = textureSampleLevel(cloud_shadow_tex, linear_clamp_sampler, puv, 0.0).r;
- ldr = vec3<f32>(cs);
- }
- }
- }
- return vec4<f32>(ldr, 1.0);
- }
|