[Bf-blender-cvs] [3967f56] viewport_experiments: Fix irritating issue with self shadowing.

Antony Riakiotakis noreply at git.blender.org
Thu Oct 23 20:13:07 CEST 2014


Commit: 3967f5659d4f83ebdc502f02ef4bf95a5f5fcc6a
Author: Antony Riakiotakis
Date:   Thu Oct 23 20:12:39 2014 +0200
Branches: viewport_experiments
https://developer.blender.org/rB3967f5659d4f83ebdc502f02ef4bf95a5f5fcc6a

Fix irritating issue with self shadowing.

Issue here was position reconstruction could use depths from pixels off
the initial position. Using linear filtering here eliminates the issue.

Usually this is not correct however given that for depth discontinuities
we will get different depths anyway, the cases where we get smooth
interpolation of depths helps a lot in image quality.

===================================================================

M	source/blender/gpu/GPU_extensions.h
M	source/blender/gpu/intern/gpu_compositing.c
M	source/blender/gpu/intern/gpu_extensions.c
M	source/blender/gpu/shaders/gpu_shader_fx_frag.glsl
M	source/blender/makesrna/intern/rna_space.c

===================================================================

diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h
index 7e45e13..9bff739 100644
--- a/source/blender/gpu/GPU_extensions.h
+++ b/source/blender/gpu/GPU_extensions.h
@@ -127,7 +127,7 @@ void GPU_texture_ref(GPUTexture *tex);
 void GPU_texture_bind(GPUTexture *tex, int number);
 void GPU_texture_unbind(GPUTexture *tex);
 
-void GPU_depth_texture_mode(GPUTexture *tex, bool compare);
+void GPU_depth_texture_mode(GPUTexture *tex, bool compare, bool use_filter);
 
 GPUFrameBuffer *GPU_texture_framebuffer(GPUTexture *tex);
 
diff --git a/source/blender/gpu/intern/gpu_compositing.c b/source/blender/gpu/intern/gpu_compositing.c
index 5c675b9..eb42cd2 100644
--- a/source/blender/gpu/intern/gpu_compositing.c
+++ b/source/blender/gpu/intern/gpu_compositing.c
@@ -264,7 +264,7 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D *v3d, struct RegionView3D
 							   v3d->dof_focal_distance};
 		float ssao_params[4] = {v3d->ssao_distance_max, v3d->ssao_darkening, v3d->ssao_attenuation, 0.0f};
 		float screen_dim[2] = {fx->gbuffer_dim[0], fx->gbuffer_dim[1]};
-		float sample_params[4] = {fx->gbuffer_dim[0], fx->gbuffer_dim[1]};
+		float sample_params[4];
 
 		float invproj[4][4];
 
@@ -298,7 +298,7 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D *v3d, struct RegionView3D
 				break;
 			case 2:
 				sample_params[0] = 16;
-				sample_params[1] = 6;
+				sample_params[1] = 10;
 				break;
 		}
 
@@ -340,7 +340,7 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D *v3d, struct RegionView3D
 		GPU_shader_uniform_texture(fx_shader, color_uniform, fx->color_buffer);
 		
 		GPU_texture_bind(fx->depth_buffer, numslots++);
-		GPU_depth_texture_mode(fx->depth_buffer, false);
+		GPU_depth_texture_mode(fx->depth_buffer, false, true);
 		GPU_shader_uniform_texture(fx_shader, depth_uniform, fx->depth_buffer);
 
 		GPU_texture_bind(fx->jitter_buffer, numslots++);
@@ -361,7 +361,7 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, struct View3D *v3d, struct RegionView3D
 	
 	/* disable bindings */
 	GPU_texture_unbind(fx->color_buffer);
-	GPU_depth_texture_mode(fx->depth_buffer, true);
+	GPU_depth_texture_mode(fx->depth_buffer, true, false);
 	GPU_texture_unbind(fx->depth_buffer);
 
 	/* same texture may be bound to more than one slot. Use this to explicitly disable texturing everywhere */
diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c
index b85efe6..5962ce6 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -707,6 +707,8 @@ GPUTexture *GPU_texture_create_2D_procedural(int w, int h, float *pixels, char e
 		/* Now we tweak some of the settings */
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
 		glTexImage2D(GL_TEXTURE_2D, 0, GL_RG16F, w, h, 0, GL_RG, GL_FLOAT, pixels);
 
 		GPU_texture_unbind(tex);
@@ -803,7 +805,7 @@ void GPU_texture_unbind(GPUTexture *tex)
 	GPU_print_error("Post Texture Unbind");
 }
 
-void GPU_depth_texture_mode(GPUTexture *tex, bool compare)
+void GPU_depth_texture_mode(GPUTexture *tex, bool compare, bool use_filter)
 {
 	GLenum arbnumber;
 
@@ -828,7 +830,15 @@ void GPU_depth_texture_mode(GPUTexture *tex, bool compare)
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
 	else
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
-	
+
+	if (use_filter) {
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+	}
+	else {
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+	}
 	if (tex->number != 0) glActiveTextureARB(GL_TEXTURE0_ARB);
 
 	GPU_print_error("Post Texture Unbind");
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_frag.glsl b/source/blender/gpu/shaders/gpu_shader_fx_frag.glsl
index 9ee71db..c3e8363 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_frag.glsl
@@ -70,7 +70,7 @@ float calculate_ssao_factor(float depth)
 {
     /* take the normalized ray direction here */
     vec2 rotX = texture2D(jitter_tex, uvcoordsvar.xy * ssao_sample_params.zw).rg;
-    vec2 rotY = vec2(rotX.y, -rotX.x);
+    vec2 rotY = vec2(-rotX.y, rotX.x);
 
     /* occlusion is zero in full depth */
     if (depth == 1.0)
@@ -105,13 +105,13 @@ float calculate_ssao_factor(float depth)
                 float f = dot(dir, normal);
 
                 /* use minor bias here to avoid self shadowing */
-                if (f > 0.15 * len)
+                if (f > 0.01)
                     factor += f / len * 1.0/(1.0 + len * len * ssao_params.z);
             }
         }
     }
 
-    factor /= ssao_sample_params.y * ssao_sample_params.x;
+    factor /= (ssao_sample_params.y * ssao_sample_params.x);
     
     return clamp(factor * ssao_params.y, 0.0, 1.0);
 }
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 8b7714e..bf014f1 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -2211,7 +2211,7 @@ static void rna_def_space_view3d(BlenderRNA *brna)
 	prop = RNA_def_property(srna, "ssao_distance_max", PROP_FLOAT, PROP_NONE);
 	RNA_def_property_ui_text(prop, "Distance", "Distance of object that contribute to the SSAO effect");
 	RNA_def_property_range(prop, 0.0f, 100000.0f);
-	RNA_def_property_ui_range(prop, 0.01f, 100.0f, 1, 3);
+	RNA_def_property_ui_range(prop, 0.0f, 100.0f, 1, 3);
 	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
 
 	prop = RNA_def_property(srna, "ssao_attenuation", PROP_FLOAT, PROP_NONE);




More information about the Bf-blender-cvs mailing list