[Bf-blender-cvs] [3e9947c] master: Depth of field high quality:

Antony Riakiotakis noreply at git.blender.org
Thu Mar 19 15:18:29 CET 2015


Commit: 3e9947c4d4714a4752c768bb78fe6d227fc6be97
Author: Antony Riakiotakis
Date:   Tue Mar 3 17:47:31 2015 +0100
Branches: master
https://developer.blender.org/rB3e9947c4d4714a4752c768bb78fe6d227fc6be97

Depth of field high quality:

A new checkbox "High quality" is provided in camera settings to enable
this. This creates a depth of field that is much closer to the rendered
result and even supports aperture blades in the effect, but it's more
expensive too. There are optimizations to do here since the technique is
very fill rate heavy.

People, be careful, this -can- lock up your screen if depth of field
blurring is too extreme.

Technical details:

This uses geometry shaders + instancing and is an adaptation of
techniques gathered from

http://bartwronski.com/2014/04/07/bokeh-depth-of-field-going-insane-

 http://advances.realtimerendering.com/s2011/SousaSchulzKazyan%20-
%20in%20Real-Time%20Rendering%20Course).ppt

TODOs:

* Support dithering to minimize banding.
* Optimize fill rate in geometry shader.

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

M	intern/cycles/blender/addon/ui.py
M	release/scripts/startup/bl_ui/properties_data_camera.py
M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/GPU_compositing.h
M	source/blender/gpu/GPU_extensions.h
M	source/blender/gpu/intern/gpu_codegen.c
M	source/blender/gpu/intern/gpu_compositing.c
M	source/blender/gpu/intern/gpu_extensions.c
M	source/blender/gpu/intern/gpu_simple_shader.c
A	source/blender/gpu/shaders/gpu_shader_fx_dof_hq_frag.glsl
A	source/blender/gpu/shaders/gpu_shader_fx_dof_hq_geo.glsl
A	source/blender/gpu/shaders/gpu_shader_fx_dof_hq_vert.glsl
M	source/blender/makesdna/DNA_gpu_types.h
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py
index 63518d7..b0337a6 100644
--- a/intern/cycles/blender/addon/ui.py
+++ b/intern/cycles/blender/addon/ui.py
@@ -457,7 +457,10 @@ class CyclesCamera_PT_dof(CyclesButtonsPanel, Panel):
         sub.active = cam.dof_object is None
         sub.prop(cam, "dof_distance", text="Distance")
         col.prop(dof_options, "fstop")
-
+        col.prop(dof_options, "high_quality")
+        if dof_options.high_quality:
+            col.prop(dof_options, "num_blades")
+ 
         col = split.column()
 
         col.label("Aperture:")
diff --git a/release/scripts/startup/bl_ui/properties_data_camera.py b/release/scripts/startup/bl_ui/properties_data_camera.py
index 106e31e..2097e82 100644
--- a/release/scripts/startup/bl_ui/properties_data_camera.py
+++ b/release/scripts/startup/bl_ui/properties_data_camera.py
@@ -187,6 +187,9 @@ class DATA_PT_camera_dof(CameraButtonsPanel, Panel):
 
         col = split.column()
         col.prop(dof_options, "fstop")
+        col.prop(dof_options, "high_quality")
+        if dof_options.high_quality:
+            col.prop(dof_options, "num_blades")
         sub = col.column()
         sub.active = cam.dof_object is None
         sub.prop(cam, "dof_distance", text="Distance")
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index b5d9028..97b0e7e 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -61,6 +61,9 @@ 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_hq_frag.glsl
+	shaders/gpu_shader_fx_dof_hq_vert.glsl
+	shaders/gpu_shader_fx_dof_hq_geo.glsl
 	shaders/gpu_shader_fx_vert.glsl
 	shaders/gpu_shader_material.glsl
 	shaders/gpu_shader_sep_gaussian_blur_frag.glsl
@@ -99,6 +102,9 @@ 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_hq_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_fx_dof_hq_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_fx_dof_hq_geo.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_fx_depth_resolve.glsl SRC)
 data_to_c_simple(shaders/gpu_shader_fx_lib.glsl SRC)
 
diff --git a/source/blender/gpu/GPU_compositing.h b/source/blender/gpu/GPU_compositing.h
index 93f1bc6..5589084 100644
--- a/source/blender/gpu/GPU_compositing.h
+++ b/source/blender/gpu/GPU_compositing.h
@@ -61,11 +61,16 @@ typedef enum GPUFXShaderEffect {
 	GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_FOUR = 5,
 	GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_FIVE = 6,
 
-	GPU_SHADER_FX_DEPTH_RESOLVE = 7,
+	/* high quality */
+	GPU_SHADER_FX_DEPTH_OF_FIELD_HQ_PASS_ONE = 7,
+	GPU_SHADER_FX_DEPTH_OF_FIELD_HQ_PASS_TWO = 8,
+	GPU_SHADER_FX_DEPTH_OF_FIELD_HQ_PASS_THREE = 9,
+
+	GPU_SHADER_FX_DEPTH_RESOLVE = 10,
 } GPUFXShaderEffect;
 
 /* keep in synch with enum above! */
-#define MAX_FX_SHADERS 8
+#define MAX_FX_SHADERS 11
 
 /* generate a new FX compositor */
 GPUFX *GPU_fx_compositor_create(void);
diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h
index 985cebc..aed1a88 100644
--- a/source/blender/gpu/GPU_extensions.h
+++ b/source/blender/gpu/GPU_extensions.h
@@ -61,13 +61,14 @@ bool GPU_non_power_of_two_support(void);
 bool GPU_vertex_buffer_support(void);
 bool GPU_display_list_support(void);
 bool GPU_bicubic_bump_support(void);
+bool GPU_geometry_shader_support(void);
+bool GPU_instanced_drawing_support(void);
 
 int GPU_max_texture_size(void);
 int GPU_color_depth(void);
 
 void GPU_code_generate_glsl_lib(void);
 
-
 /* GPU Types */
 
 typedef enum GPUDeviceType {
@@ -120,7 +121,7 @@ GPUTexture *GPU_texture_create_2D(int w, int h, const float *pixels, GPUHDRType
 GPUTexture *GPU_texture_create_3D(int w, int h, int depth, int channels, const float *fpixels);
 GPUTexture *GPU_texture_create_depth(int w, int h, char err_out[256]);
 GPUTexture *GPU_texture_create_vsm_shadow_map(int size, char err_out[256]);
-GPUTexture *GPU_texture_create_2D_procedural(int w, int h, const float *pixels, char err_out[256]);
+GPUTexture *GPU_texture_create_2D_procedural(int w, int h, const float *pixels, bool repeat, char err_out[256]);
 GPUTexture *GPU_texture_create_1D_procedural(int w, const float *pixels, char err_out[256]);
 GPUTexture *GPU_texture_from_blender(struct Image *ima,
 	struct ImageUser *iuser, bool is_data, double time, int mipmap);
@@ -136,7 +137,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, bool use_filter);
+void GPU_texture_filter_mode(GPUTexture *tex, bool compare, bool use_filter);
 
 GPUFrameBuffer *GPU_texture_framebuffer(GPUTexture *tex);
 
@@ -183,7 +184,7 @@ int GPU_offscreen_height(const GPUOffScreen *ofs);
  * - only for fragment shaders now
  * - must call texture bind before setting a texture as uniform! */
 
-GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const char *libcode, const char *defines);
+GPUShader *GPU_shader_create(const char *vertexcode, const char *fragcode, const char *geocode, const char *libcode, const char *defines);
 void GPU_shader_free(GPUShader *shader);
 
 void GPU_shader_bind(GPUShader *shader);
@@ -192,8 +193,12 @@ void GPU_shader_unbind(void);
 int GPU_shader_get_uniform(GPUShader *shader, const char *name);
 void GPU_shader_uniform_vector(GPUShader *shader, int location, int length,
 	int arraysize, const float *value);
+void GPU_shader_uniform_vector_int(GPUShader *shader, int location, int length,
+	int arraysize, const int *value);
+
 void GPU_shader_uniform_texture(GPUShader *shader, int location, GPUTexture *tex);
 void GPU_shader_uniform_int(GPUShader *shader, int location, int value);
+void GPU_shader_geometry_stage_primitive_io(GPUShader *shader, int input, int output, int number);
 
 int GPU_shader_get_attribute(GPUShader *shader, const char *name);
 
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index 40c9ec0..fcfb68d 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -1419,7 +1419,7 @@ GPUPass *GPU_generate_pass(ListBase *nodes, GPUNodeLink *outlink,
 	/* generate code and compile with opengl */
 	fragmentcode = code_generate_fragment(nodes, outlink->output);
 	vertexcode = code_generate_vertex(nodes, type);
-	shader = GPU_shader_create(vertexcode, fragmentcode, glsl_material_library, NULL);
+	shader = GPU_shader_create(vertexcode, fragmentcode, NULL, glsl_material_library, NULL);
 
 	/* failed? */
 	if (!shader) {
diff --git a/source/blender/gpu/intern/gpu_compositing.c b/source/blender/gpu/intern/gpu_compositing.c
index 511167b..bfa938d 100644
--- a/source/blender/gpu/intern/gpu_compositing.c
+++ b/source/blender/gpu/intern/gpu_compositing.c
@@ -62,11 +62,20 @@ struct GPUFX {
 	 * depth/color framebuffer. Could be extended later though */
 	GPUFrameBuffer *gbuffer;
 
+	/* dimensions of the gbuffer */
+	int gbuffer_dim[2];
+
 	/* texture bound to the first color attachment of the gbuffer */
 	GPUTexture *color_buffer;
 
 	/* second texture used for ping-pong compositing */
 	GPUTexture *color_buffer_sec;
+	/* texture bound to the depth attachment of the gbuffer */
+	GPUTexture *depth_buffer;
+	GPUTexture *depth_buffer_xray;
+
+	/* texture used for jittering for various effects */
+	GPUTexture *jitter_buffer;
 
 	/* all those buffers below have to coexist. Fortunately they are all quarter sized (1/16th of memory) of original framebuffer */
 	int dof_downsampled_w;
@@ -80,26 +89,20 @@ struct GPUFX {
 	GPUTexture *dof_near_coc_final_buffer;
 
 	/* half size blur buffer */
-	GPUTexture *dof_half_downsampled;
-	/* high quality dof texture downsamplers. 6 levels means 64 pixels wide */
-	GPUTexture *dof_nearfar_coc[6];
+	GPUTexture *dof_half_downsampled_near;
+	GPUTexture *dof_half_downsampled_far;
+	/* high quality dof texture downsamplers. 6 levels means 64 pixels wide - should be enough */
+	GPUTexture *dof_nearfar_coc;
 	GPUTexture *dof_near_blur;
 	GPUTexture *dof_far_blur;
-	GPUTexture *dof_concentric_samples_tex;
-
-	/* texture bound to the depth attachment of the gbuffer */
-	GPUTexture *depth_buffer;
-	GPUTexture *depth_buffer_xray;
 
-	/* texture used for jittering for various effects */
-	GPUTexture *jitter_buffer;
+	/* for high quality we use again a spiral texture with radius adapted */
+	bool dof_high_quality;
 
 	/* texture used for ssao */
-	int ssao_sample_count;
-	GPUTexture *ssao_concentric_samples_tex;
+	int ssao_sample_count_cache;
+	GPUTexture *ssao_spiral_samples_tex;
 
-	/* dimensions of the gbuffer */
-	int gbuffer_dim[2];
 
 	GPUFXSettings settings;
 
@@ -192,16 +195,17 @@ static void cleanup_fx_dof_buffers(GPUFX *fx)
 		fx->dof_near_coc_final_buffer = NULL;
 	}
 
-	if (fx->dof_half_downsampled) {
-		GPU_texture_free(fx->dof_half_downsampled);
-		fx->dof_half_downsampled = NULL;
+	if (fx->dof_half_downsampled_near) {
+		GPU_texture_free(fx->dof_half_downsampled_near);
+		fx->dof_half_downsampled_near = NULL;
 	}
-	if (fx->dof_nearfar_coc[0]) {
-		int i;
-		for (i = 0; i < 6; i++) {
-			GPU_texture_free(fx->dof_nearfar_coc[i]);
-			fx->dof_nearfar_coc[i] = NULL;
-		}
+	if (fx->dof_half_downsampled_far) {
+		GPU_texture_free(fx->dof_half_downsampled_far);
+		fx->dof_half_downsampled_far = NULL;
+	}
+	if (fx->dof_nearfar_coc) {
+		GPU_texture_free(fx->dof_nearfar_coc);
+		fx->dof_nearfar_coc = NULL;
 	}
 	if (fx->dof_near_blur) {
 		GPU_texture_free(fx->dof_near_blur);
@@ -211,10 +215,6 @@ static void cleanup_fx_dof_buffers(GPUFX *fx)
 		GPU_texture_free(fx->dof_far_blur);
 		fx->dof_far_blur = NULL;
 	}
-	if (fx->dof_concentric_samples_tex) {
-		GPU_texture_free(fx->dof_concentric_samples_tex);
-		fx->dof_concentric_samples_tex = NULL;
-	}
 }
 
 static void cleanup_fx_gl_data(GPUFX *fx, bool do_fbo)
@@ -245,9 +245,9 @@ static void cleanup_fx_gl_data(GPUFX *fx, bool do_fbo)
 
 	cleanup_fx_dof_buffers

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list