[Bf-blender-cvs] [08cc519] viewport_experiments: WIP for new dof

Antony Riakiotakis noreply at git.blender.org
Tue Jan 6 15:03:57 CET 2015


Commit: 08cc519e79607cee2569fb26ec22436be9c8fd90
Author: Antony Riakiotakis
Date:   Tue Jan 6 12:01:13 2015 +0100
Branches: viewport_experiments
https://developer.blender.org/rB08cc519e79607cee2569fb26ec22436be9c8fd90

WIP for new dof

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

M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/intern/gpu_compositing.c
M	source/blender/gpu/intern/gpu_extensions.c
A	source/blender/gpu/shaders/gpu_shader_fx_dof_high_frag.glsl
A	source/blender/gpu/shaders/gpu_shader_fx_dof_high_vert.glsl
M	source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl
M	source/blender/gpu/shaders/gpu_shader_fx_vert.glsl

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

diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index ca11a3c..bb598aa 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -61,6 +61,8 @@ set(SRC
 	shaders/gpu_shader_fx_ssao_frag.glsl
 	shaders/gpu_shader_fx_dof_frag.glsl
 	shaders/gpu_shader_fx_dof_vert.glsl
+	shaders/gpu_shader_fx_dof_high_frag.glsl
+	shaders/gpu_shader_fx_dof_high_vert.glsl
 	shaders/gpu_shader_fx_vert.glsl
 	shaders/gpu_shader_material.glsl
 	shaders/gpu_shader_sep_gaussian_blur_frag.glsl
@@ -98,6 +100,8 @@ data_to_c_simple(shaders/gpu_shader_fx_vert.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_fx_ssao_frag.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_fx_dof_frag.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_fx_dof_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_fx_dof_high_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_fx_dof_high_vert.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_fx_lib.glsl SRC)
 
 if(WITH_GAMEENGINE)
diff --git a/source/blender/gpu/intern/gpu_compositing.c b/source/blender/gpu/intern/gpu_compositing.c
index 875c354..d46cff4 100644
--- a/source/blender/gpu/intern/gpu_compositing.c
+++ b/source/blender/gpu/intern/gpu_compositing.c
@@ -880,6 +880,22 @@ bool GPU_fx_do_composite_pass(GPUFX *fx, float projmat[4][4], bool is_persp, str
 		}
 		/* high quality diffusion solver */
 		else {
+			GPUShader *dof_shader_pass1, *dof_shader_pass2, *dof_shader_pass3, *dof_shader_pass4;
+
+			/* DOF effect has many passes but most of them are performed on a texture whose dimensions are 4 times less than the original
+			 * (16 times lower than original screen resolution). Technique used is not very exact but should be fast enough and is based
+			 * on "Practical Post-Process Depth of Field" see http://http.developer.nvidia.com/GPUGems3/gpugems3_ch28.html */
+			dof_shader_pass1 = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_OF_FIELD_DOWNSAMPLE_HALF, is_persp);
+			dof_shader_pass2 = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_OF_FIELD_DOWNSAMPLE_HALF_COC, is_persp);
+			dof_shader_pass3 = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_THREE, is_persp);
+			dof_shader_pass4 = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_FOUR, is_persp);
+
+			/* error occured, restore framebuffers and return */
+			if (!dof_shader_pass1) {
+				GPU_framebuffer_texture_unbind(fx->gbuffer, NULL);
+				GPU_framebuffer_restore();
+				return false;
+			}
 
 		}
 	}
diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c
index 08a34b0..c186487 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -83,6 +83,8 @@ extern char datatoc_gpu_shader_fx_vert_glsl[];
 extern char datatoc_gpu_shader_fx_ssao_frag_glsl[];
 extern char datatoc_gpu_shader_fx_dof_frag_glsl[];
 extern char datatoc_gpu_shader_fx_dof_vert_glsl[];
+extern char datatoc_gpu_shader_fx_dof_high_frag_glsl[];
+extern char datatoc_gpu_shader_fx_dof_high_vert_glsl[];
 extern char datatoc_gpu_shader_fx_lib_glsl[];
 
 typedef struct GPUShaders {
@@ -1763,6 +1765,16 @@ GPUShader *GPU_shader_get_builtin_fx_shader(int effects, bool persp)
 				strcat(defines, "#define FIFTH_PASS\n");
 				GG.shaders.fx_shaders[offset] = GPU_shader_create(datatoc_gpu_shader_fx_dof_vert_glsl, datatoc_gpu_shader_fx_dof_frag_glsl, datatoc_gpu_shader_fx_lib_glsl, defines);
 				break;
+				
+			case GPU_SHADER_FX_DEPTH_OF_FIELD_DOWNSAMPLE_HALF:
+				strcat(defines, "#define HALF_DOWNSAMPLE_PASS\n");
+				GG.shaders.fx_shaders[offset] = GPU_shader_create(datatoc_gpu_shader_fx_dof_high_vert_glsl, datatoc_gpu_shader_fx_dof_high_frag_glsl, datatoc_gpu_shader_fx_lib_glsl, defines);
+				break;
+
+			case GPU_SHADER_FX_DEPTH_OF_FIELD_DOWNSAMPLE_HALF_COC:
+				strcat(defines, "#define HALF_DOWNSAMPLE_COC_PASS\n");
+				GG.shaders.fx_shaders[offset] = GPU_shader_create(datatoc_gpu_shader_fx_dof_high_vert_glsl, datatoc_gpu_shader_fx_dof_high_frag_glsl, datatoc_gpu_shader_fx_lib_glsl, defines);
+				break;
 		}
 	}
 	
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_dof_high_frag.glsl b/source/blender/gpu/shaders/gpu_shader_fx_dof_high_frag.glsl
new file mode 100644
index 0000000..66e2271
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_fx_dof_high_frag.glsl
@@ -0,0 +1,53 @@
+uniform vec2 invrendertargetdim;
+
+//texture coordinates for framebuffer read
+varying vec4 uvcoordsvar;
+varying vec2 depth_uv1;
+varying vec2 depth_uv2;
+varying vec2 depth_uv3;
+varying vec2 depth_uv4;
+
+// color buffer
+uniform sampler2D colorbuffer;
+// depth buffer
+uniform sampler2D depthbuffer;
+
+// this includes focal distance in x and aperture size in y
+uniform vec4 dof_params;
+
+/* coc calculation, positive is far coc, negative is near */
+float calculate_signed_coc(in float zdepth)
+{
+	float coc = dof_params.x * (1.0 - dof_params.y / zdepth);
+
+	/* multiply by 1.0 / sensor size to get the normalized size */
+	return coc * dof_params.z;
+}
+
+void half_downsample_frag()
+{
+	vec4 depthv, final_coc;
+	depthv.r = calculate_signed_coc(texture2D(depthbuffer, depth_uv1).r);
+	depthv.g = calculate_signed_coc(texture2D(depthbuffer, depth_uv2).r);
+	depthv.b = calculate_signed_coc(texture2D(depthbuffer, depth_uv3).r);
+	depthv.a = calculate_signed_coc(texture2D(depthbuffer, depth_uv4).r);
+	
+	/* near coc, keep the min here */
+	gl_FragData[1].r = min(min(depthv.r, depthv.g), min(depthv.b, depthv.a));
+	/* far coc keep the max */
+	gl_FragData[1].g = max(-min(min(depthv.r, depthv.g), min(depthv.b, depthv.a)), 0.0);
+	gl_FragData[1].b = gl_FragData[1].a = 0.0;
+	
+	/* framebuffer output 1 is bound to half size color. linear filtering should take care of averaging here */
+	gl_FragData[0] = texture2D(colorbuffer, uvcoordsvar);
+}
+
+void main(void)
+{
+#ifdef HALF_DOWNSAMPLE_PASS
+	half_downsample_frag();
+#elif defined(HALF_DOWNSAMPLE_COC_PASS)
+
+#endif
+
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_dof_high_vert.glsl b/source/blender/gpu/shaders/gpu_shader_fx_dof_high_vert.glsl
new file mode 100644
index 0000000..3231a5c
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_fx_dof_high_vert.glsl
@@ -0,0 +1,30 @@
+uniform vec2 invrendertargetdim;
+
+//texture coordinates for framebuffer read
+varying vec4 uvcoordsvar;
+varying vec2 depth_uv1;
+varying vec2 depth_uv2;
+varying vec2 depth_uv3;
+varying vec2 depth_uv4;
+
+
+void vert_half_downsample(void)
+{
+	uvcoordsvar = gl_MultiTexCoord0;
+	gl_Position = gl_Vertex;
+	
+	depth_uv1 = gl_MultiTexCoord0.xy + vec2(-0.5, -0.5) * invrendertargetdim;
+	depth_uv2 = gl_MultiTexCoord0.xy + vec2(-0.5, 0.5) * invrendertargetdim;
+	depth_uv3 = gl_MultiTexCoord0.xy + vec2(0.5, -0.5) * invrendertargetdim;
+	depth_uv4 = gl_MultiTexCoord0.xy + vec2(0.5, 0.5) * invrendertargetdim;
+}
+
+
+void main(void)
+{
+#ifdef HALF_DOWNSAMPLE_PASS
+	vert_half_downsample();
+#elif defined(HALF_DOWNSAMPLE_COC_PASS)
+	
+#endif
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl b/source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl
index 61055c7..01283d5 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl
@@ -26,10 +26,10 @@ void vert_dof_first_pass()
 	color_uv1 = gl_MultiTexCoord0.xy + vec2(-1.5, -1.5) * invrendertargetdim;
 	color_uv2 = gl_MultiTexCoord0.xy + vec2(0.5, -1.5) * invrendertargetdim;
 
-	depth_uv1 = gl_MultiTexCoord0.xy + vec2(-1.5, -1.5) * invrendertargetdim;;
-	depth_uv2 = gl_MultiTexCoord0.xy + vec2(-0.5, -1.5) * invrendertargetdim;;
-	depth_uv3 = gl_MultiTexCoord0.xy + vec2(0.5, -1.5) * invrendertargetdim;;
-	depth_uv4 = gl_MultiTexCoord0.xy + vec2(1.5, -1.5) * invrendertargetdim;;
+	depth_uv1 = gl_MultiTexCoord0.xy + vec2(-1.5, -1.5) * invrendertargetdim;
+	depth_uv2 = gl_MultiTexCoord0.xy + vec2(-0.5, -1.5) * invrendertargetdim;
+	depth_uv3 = gl_MultiTexCoord0.xy + vec2(0.5, -1.5) * invrendertargetdim;
+	depth_uv4 = gl_MultiTexCoord0.xy + vec2(1.5, -1.5) * invrendertargetdim;
 
 	gl_Position = gl_Vertex;
 }
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_vert.glsl b/source/blender/gpu/shaders/gpu_shader_fx_vert.glsl
index cd59843..5194e41 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_vert.glsl
@@ -1,6 +1,6 @@
 varying vec4 uvcoordsvar;
 
-//very simple shader for gull screen FX, just pass values on
+//very simple shader for full screen FX, just pass values on
 
 void main()
 {




More information about the Bf-blender-cvs mailing list