| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- // Dual Paraboloid Reflection Probe Pass (512x512x2 Rgba16Float, 1 hemisphere/frame)
- // Renders winter sky dome + lit low-poly terrain, buildings, wrecks, and muzzle flashes!
- @group(0) @binding(0) var<uniform> u: GlobalUniforms;
- @group(0) @binding(1) var<storage, read> lights: array<GpuPointLight>;
- @group(0) @binding(2) var mat_albedo: texture_2d_array<f32>;
- @group(0) @binding(3) var mat_sampler: sampler;
- @group(0) @binding(4) var shadow_tex: texture_depth_2d;
- @group(0) @binding(5) var shadow_sampler: sampler_comparison;
- @group(0) @binding(6) var cloud_shadow_tex: texture_2d<f32>;
- @group(0) @binding(7) var linear_clamp_sampler: sampler;
- struct SkyOut {
- @builtin(position) position: vec4<f32>,
- @location(0) uv: vec2<f32>,
- };
- @vertex
- fn vs_sky(@builtin(vertex_index) vid: u32) -> SkyOut {
- var out: SkyOut;
- let x = f32(i32(vid & 1u) * 4 - 1);
- let y = f32(i32(vid >> 1u) * 4 - 1);
- out.position = vec4<f32>(x, y, 0.9999, 1.0);
- out.uv = vec2<f32>(x, y);
- return out;
- }
- @fragment
- fn fs_sky(in: SkyOut) -> @location(0) vec4<f32> {
- // Reconstruct parabolic hemisphere ray direction from NDC xy
- let p2 = dot(in.uv, in.uv);
- if (p2 > 1.25) {
- return vec4<f32>(0.25, 0.30, 0.36, 1.0);
- }
- let denom = 1.0 + p2;
- let hemi = u.dp_origin.w;
- let dir = normalize(vec3<f32>(2.0 * in.uv.x / denom, 2.0 * in.uv.y / denom, hemi * (1.0 - p2) / denom));
- var col = eval_winter_sky(dir, normalize(u.sun_dir.xyz), u.sun_dir.w);
- // Subtle cloud bands in DPR sky dome
- if (dir.y > 0.04) {
- let sky_uv = dir.xz / (dir.y + 0.15) * 0.25 + u.cloud_wind.xy * 0.0005;
- let band = 0.5 + 0.5 * sin(sky_uv.x * 7.0 + sin(sky_uv.y * 5.0));
- let cloud_tint = mix(vec3<f32>(0.26, 0.29, 0.34), vec3<f32>(0.78, 0.80, 0.84), band);
- col = mix(col, cloud_tint, smoothstep(0.3, 0.85, u.sun_dir.w) * 0.55 * smoothstep(0.04, 0.25, dir.y));
- }
- return vec4<f32>(col, 1.0);
- }
- struct StaticIn {
- @location(0) position: vec3<f32>,
- @location(1) normal: vec3<f32>,
- @location(2) uv: vec2<f32>,
- @location(3) params: vec4<f32>,
- };
- struct DpOut {
- @builtin(position) position: vec4<f32>,
- @location(0) world_pos: vec3<f32>,
- @location(1) normal: vec3<f32>,
- @location(2) uv: vec2<f32>,
- @location(3) params: vec4<f32>,
- @location(4) clip_z: f32,
- };
- @vertex
- fn vs_static(v: StaticIn) -> DpOut {
- var out: DpOut;
- let rel = v.position - u.dp_origin.xyz;
- let hemi = u.dp_origin.w;
- let p = vec3<f32>(rel.x, rel.y, rel.z * hemi);
- let dist = length(p);
- let dir = p / max(dist, 0.0001);
- let denom = max(dir.z + 1.0, 0.06);
- let depth = clamp((dist - 0.4) / 480.0, 0.0, 0.999);
- out.clip_z = dir.z;
- out.position = vec4<f32>(dir.x / denom, dir.y / denom, depth, 1.0);
- out.world_pos = v.position;
- out.normal = v.normal;
- out.uv = v.uv;
- out.params = v.params;
- return out;
- }
- @fragment
- fn fs_static(in: DpOut) -> @location(0) vec4<f32> {
- // 5% seam overlap eliminates equator cracks between Front (+Z) & Back (-Z) hemispheres
- if (in.clip_z < -0.05) {
- discard;
- }
- let layer = i32(clamp(in.params.x + 0.5, 0.0, 20.0));
- let albedo = textureSample(mat_albedo, mat_sampler, in.uv, layer).rgb * in.params.w;
- let N = normalize(in.normal);
- let sun_d = normalize(u.sun_dir.xyz);
- let ndl = max(dot(N, sun_d), 0.0);
- let sun_vis = sample_sun_shadow_vogel(
- shadow_tex, shadow_sampler, u.sun_view_proj,
- in.world_pos, N, sun_d, in.position.xy, 4u
- );
- let cloud_vis = sample_cloud_shadow(cloud_shadow_tex, linear_clamp_sampler, in.world_pos, u.cloud_shadow_bounds);
- let hemi_amb = mix(vec3<f32>(0.12, 0.14, 0.17), vec3<f32>(0.34, 0.40, 0.48), N.y * 0.5 + 0.5);
- var color = albedo * (hemi_amb * in.params.z + u.sun_color.rgb * ndl * sun_vis * cloud_vis);
- // Dynamic muzzle flashes & explosions reflected in Dual Paraboloid!
- let lcount = min(u.flags.x, 64u);
- for (var i = 0u; i < lcount; i = i + 1u) {
- let lp = lights[i].pos_radius;
- let to_l = lp.xyz - in.world_pos;
- let d = length(to_l);
- if (d < lp.w) {
- let atten = pow(1.0 - d / lp.w, 2.0);
- let l_ndl = max(dot(N, to_l / max(d, 0.01)), 0.0);
- color += albedo * lights[i].color_intensity.rgb * lights[i].color_intensity.w * atten * l_ndl;
- }
- }
- let dist = length(in.world_pos - u.dp_origin.xyz);
- let fog = 1.0 - exp(-dist * 0.0022);
- let fog_col = eval_winter_sky(normalize(in.world_pos - u.dp_origin.xyz), sun_d, u.sun_dir.w);
- color = mix(color, fog_col, clamp(fog, 0.0, 0.85));
- return vec4<f32>(color, 1.0);
- }
|