Hi, I've recently been trying to implement screen space reflections into my engine, however, it is extremely buggy. I'm using this tutorial : http://imanolfotia.com/blog/update/2017/03/11/ScreenSpaceReflections.html
The reflections look decent when I am close to the ground (first image), however when I get further away from the ground (the surface that is reflecting stuff), the reflections become blocky and strange (second image).
I have a feeling that it has something to do with the fact that the further the rays travel in view space, the more scattered they get -> therefore the reflected image is less detailed hence the blockiness. However I really am not sure about this and if this is the case, I don't know how to fix it.
It would be great if anyone had any suggestions around how to debug or sort this thing out. Thanks.
Here is the code for the ray casting
vec4 ray_cast(inout vec3 direction, inout vec3 hit_coord, out float depth_difference, out bool success)
{
vec3 original_coord = hit_coord;
direction *= 0.2;
vec4 projected_coord;
float sampled_depth;
for (int i = 0; i < 20; ++i)
{
hit_coord += direction;
projected_coord = projection_matrix * vec4(hit_coord, 1.0);
projected_coord.xy /= projected_coord.w;
projected_coord.xy = projected_coord.xy * 0.5 + 0.5;
// view_positions store the view space coordinates of the objects
sampled_depth = textureLod(view_positions, projected_coord.xy, 2).z;
if (sampled_depth > 1000.0) continue;
depth_difference = hit_coord.z - sampled_depth;
if ((direction.z - depth_difference) < 1.2)
{
if (depth_difference <= 0)
{
vec4 result;
// binary search for more detailed sample
result = vec4(binary_search(direction, hit_coord, depth_difference), 1.0);
success = true;
return result;
}
}
}
return vec4(projected_coord.xy, sampled_depth, 0.0);
}
Here is the code just before this gets called
float ddepth;
vec3 jitt = mix(vec3(0.0), vec3(hash33(view_position)), 0.5);
vec3 ray_dir = reflect(normalize(view_position), normalize(view_normal));
ray_dir = ray_dir * max(0.2, -view_position.z);
/* ray cast */
vec4 coords = ray_cast(ray_dir, view_position, ddepth);