mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-20 04:35:57 +00:00
Contact shadows take the in-image neighbour on the screen border when they find the surface normal
On the border the clamped neighbour is the pixel itself, so the nearer-in-depth pick took a zero difference and normalize() returned NaN; `lit <= 0.0` is false for NaN, so whether those pixels were marched and what they wrote depended on how the driver clamps NaN. The border now uses the side inside the image, and a NaN gate skips the march. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f76a24a7cf
commit
6ff98e2d61
2 files changed
+237
-216
No files matched your search
@@ -35,12 +35,17 @@ vec3 pos_at(ivec2 q) { // the view-space position of a pixel, clamped to the i
|
||||
}
|
||||
|
||||
// The surface normal from the linear depth: on each axis the neighbour nearer in depth, so an edge pixel takes the
|
||||
// slope of its own surface rather than the step to what lies behind it. Turned toward the camera.
|
||||
// slope of its own surface rather than the step to what lies behind it. Turned toward the camera. On the image border
|
||||
// the clamped neighbour is the pixel itself, a zero difference that would make the normal NaN, so the side inside the
|
||||
// image is taken there.
|
||||
vec3 normal_at(ivec2 px, vec3 p) {
|
||||
ivec2 last = ivec2(pc.size.xy) - 1;
|
||||
vec3 l = pos_at(px - ivec2(1, 0)), r = pos_at(px + ivec2(1, 0));
|
||||
vec3 d = pos_at(px - ivec2(0, 1)), u = pos_at(px + ivec2(0, 1));
|
||||
vec3 dx = abs(r.z - p.z) < abs(p.z - l.z) ? r - p : p - l;
|
||||
vec3 dy = abs(u.z - p.z) < abs(p.z - d.z) ? u - p : p - d;
|
||||
bool take_r = px.x == 0 || (px.x < last.x && abs(r.z - p.z) < abs(p.z - l.z));
|
||||
bool take_u = px.y == 0 || (px.y < last.y && abs(u.z - p.z) < abs(p.z - d.z));
|
||||
vec3 dx = take_r ? r - p : p - l;
|
||||
vec3 dy = take_u ? u - p : p - d;
|
||||
vec3 n = normalize(cross(dx, dy));
|
||||
return dot(n, p) > 0.0 ? -n : n;
|
||||
}
|
||||
@@ -59,7 +64,7 @@ void main() {
|
||||
// already put on it (dark silhouettes of rock faces in the Gerudo sandstorm haze). Faces at a grazing angle to the
|
||||
// sun get a share that grows with that angle.
|
||||
float lit = smoothstep(0.0, 0.3, dot(normal_at(px, p), pc.light.xyz));
|
||||
if (lit <= 0.0) return;
|
||||
if (!(lit > 0.0)) return; // also a NaN normal: the march is skipped rather than writing NaN into the colour
|
||||
// the march grows with distance, as one pixel covers more ground; thickness keeps thin blades from hiding the sky
|
||||
float len = pc.light.w * clamp(z / 10.0, 0.4, 3.0);
|
||||
float thick = 0.15 + z * 0.01;
|
||||
|
||||
Reference in new issue
Block a user