Jump to content
  • Advertisement
Sign in to follow this  
BlueSpud

Screen Space Reflection Streaking

This topic is 469 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey,

Im trying to implement some very simple screen space reflections. Right now I have everything working, except there are some pretty noticeable artifacts. Here is an image of the reflection buffer with the artifact shown. I've outlined the actual geometry extents in red so that its more obvious because this is the reflection buffer only. The noise is intentional, I'm either going to blur it out later, bur right now Im concentrated on getting the reflections themselves to look right.

ODn6flH.jpg

As you can see there are "streaks" that optimally should not be there. My guess is that the ray is facing away from the camera and is actually moving behind the objects but since the ray position is then less than the depth of the object it is reflected.  If an object isn't touching the plane it is reflecting on the streaking becomes much more noticeable.  Does anyone have any ideas on what I can do to fix this? 

 

Thanks

 

EDIT:

Here is my code if there is a chance that its an issue with that 

vec2 binarySearch(vec3 last, vec3 current) {
	
	vec3 ray_min = last;
	vec3 ray_max = current;
	vec3 ray_mid;
	
	for (int i = 0; i < 10; i++) {
		
		ray_mid = mix(ray_min, ray_max, 0.5);
		float depth = texture(tex_depth, ray_mid.xy).r;
		
		if (ray_mid.z > depth)
			ray_max = ray_mid;
		else ray_min = ray_max;
		
	}
	
	return ray_mid.xy;
	
}

void main() {

	// Get the normal
	vec3 normal = texture(tex_normal, tex_coord0).rgb;
	
	// Calculate world space position
	float depth = texture(tex_depth, tex_coord0).x;
	vec4 position_p = vec4(tex_coord0 * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
	position_p = inverse_proj_view * position_p;
	vec3 position = (position_p / position_p.w).xyz;

	// Get the reflection vector
	vec3 V = normalize(position - view_position);
	vec3 reflection_vector = reflect(V, normal);
	
	vec4 reflection_pos = mat_view_proj * vec4(position + reflection_vector, 1.0);
	reflection_pos = reflection_pos / reflection_pos.w;
	vec3 reflection_pos_s = reflection_pos.xyz * 0.5 + 0.5;
	
	// Calculate a jitter to add some noise
	float c = (tex_coord0.x * 14400.0 + tex_coord0.y * 8500.0) * 0.25;
	float jitter = mod( c, 1.0);
	
	vec3 NDC = vec3(tex_coord0, depth);
	vec3 ray_direction = normalize(reflection_pos_s - NDC) * jitter;
	
	vec3 last_ray_step = NDC;
	vec3 reflection_color;
	
	for (int i = 0; i < 16; i++) {
	
		vec3 ray_step = last_ray_step + ray_direction * 0.04;
		float depth_ray = texture(tex_depth, ray_step.xy).r;
	
		if (depth_ray < ray_step.z) {
			
			reflection_color = texture(tex_albedo, binarySearch(last_ray_step, ray_step)).rgb;
			break;
			
		}
		
		last_ray_step = ray_step;
		
	}
	
	
	reflection = reflection_color * (1 - smoothstep(0.25, 0.5, dot(-V, reflection_vector)));

}

Edited by BlueSpud

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!