// Main Forward PBR Pass for Low-Poly Terrain, Ruins, Wrecks & Articulated Soldiers // Features: // - 4-Tap Catmull-Rom Bicubic B-Spline filtering + 16x Aniso on low-res 128x128 shader textures // - Dynamic puddle wetness modulation reflecting sky, clouds, and ruins via Dual Paraboloid // - IGN-rotated Vogel Disk PCF Sun Shadows // - Real-Time 2D Projected Volumetric Cloud Shadows // - Dynamic muzzle flash & explosion point lights + winter valley mist @group(0) @binding(0) var u: GlobalUniforms; @group(0) @binding(1) var lights: array; @group(0) @binding(2) var mat_albedo: texture_2d_array; @group(0) @binding(3) var mat_normal: texture_2d_array; @group(0) @binding(4) var mat_orm: texture_2d_array; @group(0) @binding(5) var mat_sampler: sampler; @group(0) @binding(6) var shadow_tex: texture_depth_2d; @group(0) @binding(7) var shadow_sampler: sampler_comparison; @group(0) @binding(8) var cloud_shadow_tex: texture_2d; @group(0) @binding(9) var linear_clamp_sampler: sampler; @group(0) @binding(10) var dp_tex: texture_2d_array; struct SoldierAppearanceGpu { jacket_tint_mat: vec4, trouser_tint_mat: vec4, skin_hl: vec4, }; @group(1) @binding(0) var soldier_bones: array>; @group(1) @binding(1) var soldier_appearances: array; struct PbrOut { @builtin(position) position: vec4, @location(0) world_pos: vec3, @location(1) world_normal: vec3, @location(2) uv: vec2, @location(3) params: vec4, // x = mat_layer, y = puddle_mask, z = ao, w = tint @location(4) tint_hl: vec4, // rgb = actor tint, w = highlight }; struct StaticIn { @location(0) position: vec3, @location(1) normal: vec3, @location(2) uv: vec2, @location(3) params: vec4, }; @vertex fn vs_static(v: StaticIn) -> PbrOut { var out: PbrOut; out.position = u.view_proj * vec4(v.position, 1.0); out.world_pos = v.position; out.world_normal = v.normal; out.uv = v.uv; out.params = v.params; out.tint_hl = vec4(1.0, 1.0, 1.0, 0.0); return out; } struct ActorIn { @location(0) position: vec3, @location(1) normal: vec3, @location(2) uv: vec2, @location(3) mat_id: u32, @location(4) col0: vec4, @location(5) col1: vec4, @location(6) col2: vec4, @location(7) col3: vec4, @location(8) tint_hl: vec4, @location(9) extra: vec4, }; @vertex fn vs_actor(v: ActorIn) -> PbrOut { var out: PbrOut; let model = mat4x4(v.col0, v.col1, v.col2, v.col3); let wp = (model * vec4(v.position, 1.0)).xyz; let wn = normalize((model * vec4(v.normal, 0.0)).xyz); let mat_layer = select(f32(v.mat_id), v.extra.x, v.extra.x >= 0.0); out.position = u.view_proj * vec4(wp, 1.0); out.world_pos = wp; out.world_normal = wn; out.uv = v.uv; out.params = vec4(mat_layer, 0.05, 0.92, 1.0); out.tint_hl = v.tint_hl; return out; } struct SkinnedActorIn { @location(0) position: vec3, @location(1) normal: vec3, @location(2) uv: vec2, @location(3) bone_indices: vec2, @location(4) bone_weights: vec2, @location(5) region_id: u32, }; @vertex fn vs_skinned(v: SkinnedActorIn, @builtin(instance_index) inst: u32) -> PbrOut { var out: PbrOut; let base_bone = inst * 12u; let m0 = soldier_bones[base_bone + v.bone_indices.x]; let m1 = soldier_bones[base_bone + v.bone_indices.y]; let skin = m0 * v.bone_weights.x + m1 * v.bone_weights.y; let wp = (skin * vec4(v.position, 1.0)).xyz; let wn = normalize((skin * vec4(v.normal, 0.0)).xyz); let app = soldier_appearances[inst]; var mat_layer = app.jacket_tint_mat.w; var tint = app.jacket_tint_mat.rgb; if (v.region_id == 0u) { // Skin / face -> Sandbag weave toned by skin tint mat_layer = 7.0; tint = app.skin_hl.rgb; } else if (v.region_id == 2u) { // Trousers -> independent trouser camo & tint mat_layer = app.trouser_tint_mat.w; tint = app.trouser_tint_mat.rgb; } else if (v.region_id == 3u) { // Boots & cold-weather gloves -> dark Gunmetal/leather mat_layer = 11.0; tint = vec3(0.65, 0.62, 0.58); } out.position = u.view_proj * vec4(wp, 1.0); out.world_pos = wp; out.world_normal = wn; out.uv = v.uv; out.params = vec4(mat_layer, 0.04, 0.94, 1.0); out.tint_hl = vec4(tint, app.skin_hl.w); return out; } fn world_micro_grain(wp: vec3) -> f32 { let p = wp * 3.7; return 0.94 + 0.12 * fract(sin(dot(floor(p), vec3(12.9898, 78.233, 37.719))) * 43758.5453); } @fragment fn fs_main(in: PbrOut) -> @location(0) vec4 { let layer = i32(clamp(in.params.x + 0.5, 0.0, 20.0)); let use_bicubic = u.cloud_wind.w > 0.5; var albedo_s: vec4; var normal_s: vec4; var orm_s: vec4; if (use_bicubic) { albedo_s = sample_bicubic_array(mat_albedo, mat_sampler, in.uv, layer); normal_s = sample_bicubic_array(mat_normal, mat_sampler, in.uv, layer); orm_s = sample_bicubic_array(mat_orm, mat_sampler, in.uv, layer); } else { albedo_s = textureSample(mat_albedo, mat_sampler, in.uv, layer); normal_s = textureSample(mat_normal, mat_sampler, in.uv, layer); orm_s = textureSample(mat_orm, mat_sampler, in.uv, layer); } var albedo = albedo_s.rgb * in.params.w * in.tint_hl.rgb * world_micro_grain(in.world_pos); let ao = orm_s.r * in.params.z; var roughness = orm_s.g; let metallic = orm_s.b; // Perturb geometric low-poly normal with filtered procedural normal map let base_n = normalize(in.world_normal); let up_ref = select(vec3(1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), abs(base_n.y) < 0.9); let t_approx = normalize(cross(up_ref, base_n)); let b_approx = cross(base_n, t_approx); let n_ts = normal_s.xyz * 2.0 - 1.0; var N = normalize(t_approx * n_ts.x * 0.65 + b_approx * n_ts.y * 0.65 + base_n * max(n_ts.z, 0.25)); // Puddle wetness modulation -> glossy cold-water puddles reflecting DPR sky/ruins! let puddle = clamp(in.params.y * u.sun_color.w, 0.0, 1.0) * smoothstep(0.55, 0.92, base_n.y); albedo = mix(albedo, albedo * 0.48, puddle * 0.75); roughness = mix(roughness, 0.045, puddle); N = normalize(mix(N, base_n, puddle * 0.85)); let V = normalize(u.camera_pos.xyz - in.world_pos); let sun_d = normalize(u.sun_dir.xyz); // Vogel Disk PCF sun shadow * 2D Projected Cloud Shadow let pcf_taps = u32(clamp(u.cloud_wind.z, 8.0, 32.0)); let sun_vis = sample_sun_shadow_vogel( shadow_tex, shadow_sampler, u.sun_view_proj, in.world_pos, base_n, sun_d, in.position.xy, pcf_taps ); let cloud_vis = sample_cloud_shadow(cloud_shadow_tex, linear_clamp_sampler, in.world_pos, u.cloud_shadow_bounds); let direct_sun = eval_pbr_direct( N, V, sun_d, albedo, roughness, metallic, u.sun_color.rgb * sun_vis * cloud_vis ); // Dynamic muzzle flashes & explosion lights var direct_dyn = vec3(0.0); 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 = to_l / max(d, 0.001); direct_dyn += eval_pbr_direct( N, V, L, albedo, roughness, metallic, lights[i].color_intensity.rgb * lights[i].color_intensity.w * atten ); } } // Hemisphere winter sky ambient + Dual Paraboloid IBL Specular Reflections! let sky_amb = mix(vec3(0.10, 0.12, 0.14), vec3(0.34, 0.40, 0.48), N.y * 0.5 + 0.5); let diffuse_ibl = albedo * (1.0 - metallic) * sky_amb * ao * mix(0.68, 1.0, cloud_vis); let R = reflect(-V, N); let dp_env = sample_dual_paraboloid(dp_tex, linear_clamp_sampler, R, roughness); let ndv = max(dot(N, V), 0.001); let f0 = mix(vec3(0.04), albedo, metallic); let fresnel_ibl = f0 + (max(vec3(1.0 - roughness), f0) - f0) * pow(1.0 - ndv, 5.0); let spec_ibl = dp_env * fresnel_ibl * ao * mix(0.65, 1.25, puddle + metallic * 0.5); var color = direct_sun + direct_dyn + diffuse_ibl + spec_ibl; // Cold Caucasus exponential distance & valley height mist (scaled cleanly for 3 km horizons) let cam_dist = length(in.world_pos - u.camera_pos.xyz); let height_mist = exp(-max(in.world_pos.y - 1.0, 0.0) * 0.045); let fog_scale = select(1.0, 0.20, u.screen_params.w > 1500.0); let fog_amount = 1.0 - exp(-cam_dist * (0.0020 + 0.0016 * height_mist) * fog_scale); let fog_col = eval_winter_sky(normalize(in.world_pos - u.camera_pos.xyz), sun_d, u.sun_dir.w); color = mix(color, fog_col, clamp(fog_amount, 0.0, 0.90)); return vec4(color, 1.0); }