mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-19 20:25:57 +00:00
Darken only sunlit pixels with contact shadows
The half-resolution lighting pass the composite reads keeps the sun's visibility in its first target's alpha: 1 in the sun, 0 in the shadow maps' shadow and everywhere underground. vk_contact.c finds that pass (eight targets at half the scene size, the first RGBA8) and contact_shadow.comp scales its darkening by that alpha, so a contact shadow takes away direct sunlight only and caves no longer turn flat. Without that pass in the frame the old behaviour stays. TOTK_CONTACT_DEBUG=2 shows the visibility in grey. Carried onto dev from #439: the march is now planned by the scan (vk_contact_plan) and recorded from a VkExecJob, so the lighting target travels in the job's new sun field, and the factor multiplies the facing-the-sun factor of the back-face fix. Co-Authored-By: itaskaev2 <165683571+itaskaev2@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6151ac4fbc
commit
581c1ecdef
5 files changed
+276
-215
No files matched your search
@@ -7,12 +7,13 @@ layout(local_size_x = 8, local_size_y = 8) in;
|
||||
|
||||
layout(binding = 0) uniform sampler2D lin_depth; // the game's linear depth: view distance / far
|
||||
layout(binding = 1, r11f_g11f_b10f) uniform image2D scene; // the lit scene colour, darkened in place
|
||||
layout(binding = 2) uniform sampler2D sun_vis; // half-resolution lighting: alpha is sun visibility
|
||||
|
||||
layout(push_constant) uniform Params {
|
||||
vec4 proj; // projection x scale, y scale, far plane, strength (0..1)
|
||||
vec4 light; // view-space direction toward the sun (xyz), march length in metres at 10 m (w)
|
||||
vec4 size; // width, height, 1/width, 1/height
|
||||
vec4 opt; // x: debug (1: write the shadow factor as grey)
|
||||
vec4 opt; // x: debug (1: the shadow factor as grey, 2: the sun visibility), y: 1 with sun_vis bound
|
||||
} pc;
|
||||
|
||||
vec3 view_pos(vec2 uv, float z) { // z: distance in front of the camera
|
||||
@@ -58,6 +59,14 @@ void main() {
|
||||
float z = d * pc.proj.z;
|
||||
if (z > 80.0) return;
|
||||
vec2 uv = (vec2(px) + 0.5) * pc.size.zw;
|
||||
// Direct sunlight on this pixel as the game's lighting found it: 0 in the shadow maps' shadow and underground, where
|
||||
// darkening would take away ambient light and texture detail (flat caves). Without that pass every pixel counts as lit.
|
||||
float vis = pc.opt.y > 0.5 ? textureLod(sun_vis, uv, 0.0).a : 1.0;
|
||||
if (pc.opt.x > 1.5) {
|
||||
imageStore(scene, px, vec4(vis, vis, vis, 1.0));
|
||||
return;
|
||||
}
|
||||
if (vis <= 0.0 && pc.opt.x < 0.5) return;
|
||||
vec3 p = view_pos(uv, z);
|
||||
// A contact shadow can only take away direct sunlight, and a surface turned away from the sun gets none: its march
|
||||
// runs into the surface itself at once, and darkening it would darken the ambient light and the fog the composite
|
||||
@@ -84,7 +93,7 @@ void main() {
|
||||
}
|
||||
}
|
||||
float fade = 1.0 - smoothstep(40.0, 80.0, z);
|
||||
float k = 1.0 - pc.proj.w * occ * fade * lit;
|
||||
float k = 1.0 - pc.proj.w * occ * fade * lit * vis;
|
||||
if (pc.opt.x > 0.5) {
|
||||
imageStore(scene, px, vec4(k, k, k, 1.0));
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user