Fixing artifacts in SSR
This commit is contained in:
@@ -121,7 +121,7 @@ void main() {
|
||||
|
||||
// clip z and w advance to line advance
|
||||
vec2 line_advance = normalize(line_dir); // down to pixel
|
||||
float step_size = length(line_advance) / length(line_dir);
|
||||
float step_size = 1.0 / length(line_dir);
|
||||
float z_advance = z_dir * step_size; // adapt z advance to line advance
|
||||
float w_advance = w_dir * step_size; // adapt w advance to line advance
|
||||
|
||||
@@ -139,6 +139,14 @@ void main() {
|
||||
float depth;
|
||||
vec2 prev_pos = pos;
|
||||
|
||||
if (ivec2(pos + line_advance - 0.5) == ssC) {
|
||||
// It is possible for rounding to cause our first pixel to check to be the pixel we're reflecting.
|
||||
// Make sure we skip it
|
||||
pos += line_advance;
|
||||
z += z_advance;
|
||||
w += w_advance;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
|
||||
float steps_taken = 0.0;
|
||||
@@ -149,8 +157,8 @@ void main() {
|
||||
w += w_advance;
|
||||
|
||||
// convert to linear depth
|
||||
|
||||
depth = imageLoad(source_depth, ivec2(pos - 0.5)).r;
|
||||
ivec2 test_pos = ivec2(pos - 0.5);
|
||||
depth = imageLoad(source_depth, test_pos).r;
|
||||
if (sc_multiview) {
|
||||
depth = depth * 2.0 - 1.0;
|
||||
depth = 2.0 * params.camera_z_near * params.camera_z_far / (params.camera_z_far + params.camera_z_near - depth * (params.camera_z_far - params.camera_z_near));
|
||||
@@ -161,13 +169,21 @@ void main() {
|
||||
z_to = z / w;
|
||||
|
||||
if (depth > z_to) {
|
||||
// if depth was surpassed
|
||||
if (depth <= max(z_to, z_from) + params.depth_tolerance && -depth < params.camera_z_far * 0.95) {
|
||||
// check the depth tolerance and far clip
|
||||
// check that normal is valid
|
||||
found = true;
|
||||
// Test if our ray is hitting the "right" side of the surface, if not we're likely self reflecting and should skip.
|
||||
vec4 test_normal_roughness = imageLoad(source_normal_roughness, test_pos);
|
||||
vec3 test_normal = test_normal_roughness.xyz * 2.0 - 1.0;
|
||||
test_normal = normalize(test_normal);
|
||||
test_normal.y = -test_normal.y; //because this code reads flipped
|
||||
|
||||
if (dot(ray_dir, test_normal) < 0.001) {
|
||||
// if depth was surpassed
|
||||
if (depth <= max(z_to, z_from) + params.depth_tolerance && -depth < params.camera_z_far * 0.95) {
|
||||
// check the depth tolerance and far clip
|
||||
// check that normal is valid
|
||||
found = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
steps_taken += 1.0;
|
||||
|
||||
Reference in New Issue
Block a user