[Bf-blender-cvs] [5e61319] master: Viewport compositing - first code

Antony Riakiotakis noreply at git.blender.org
Thu Feb 12 18:59:58 CET 2015


Commit: 5e613198e59124986ab3e4bdb8829f77e2284450
Author: Antony Riakiotakis
Date:   Thu Feb 12 18:54:41 2015 +0100
Branches: master
https://developer.blender.org/rB5e613198e59124986ab3e4bdb8829f77e2284450

Viewport compositing - first code

This commit introduces a few ready made effects for the 3D viewport
and OpenGL rendering.

Included effects are Depth of Field, accessible from camera view
and screen space ambient occlusion. Those effects can be turned on and
tweaked from the shading panel in the 3D viewport.

Off screen rendering will use the settings of the current camera.

WIP documentation can be found here:

http://wiki.blender.org/index.php/User:Psy-Fi/Framebuffer_Post-processing

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

M	SConstruct
M	release/scripts/startup/bl_ui/properties_data_camera.py
M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/CMakeLists.txt
M	source/blender/blenkernel/BKE_camera.h
M	source/blender/blenkernel/BKE_screen.h
M	source/blender/blenkernel/intern/camera.c
M	source/blender/blenkernel/intern/screen.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/versioning_270.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/include/ED_view3d.h
M	source/blender/editors/render/render_opengl.c
M	source/blender/editors/space_view3d/drawobject.c
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/gpu/CMakeLists.txt
A	source/blender/gpu/GPU_compositing.h
M	source/blender/gpu/GPU_extensions.h
M	source/blender/gpu/SConscript
M	source/blender/gpu/intern/gpu_codegen.c
A	source/blender/gpu/intern/gpu_compositing.c
M	source/blender/gpu/intern/gpu_extensions.c
A	source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl
A	source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl
A	source/blender/gpu/shaders/gpu_shader_fx_lib.glsl
A	source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl
A	source/blender/gpu/shaders/gpu_shader_fx_vert.glsl
M	source/blender/makesdna/DNA_camera_types.h
A	source/blender/makesdna/DNA_gpu_types.h
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesdna/DNA_view3d_types.h
M	source/blender/makesdna/intern/makesdna.c
M	source/blender/makesrna/intern/rna_camera.c
M	source/blender/makesrna/intern/rna_scene.c
M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/SConstruct b/SConstruct
index 7de9f2c..225b532 100644
--- a/SConstruct
+++ b/SConstruct
@@ -761,6 +761,11 @@ if B.targets != ['cudakernels']:
     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_vertex_world.glsl")
     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_vsm_store_frag.glsl")
     data_to_c_simple("source/blender/gpu/shaders/gpu_shader_vsm_store_vert.glsl")
+    data_to_c_simple("source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl")
+    data_to_c_simple("source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl")
+    data_to_c_simple("source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl")
+    data_to_c_simple("source/blender/gpu/shaders/gpu_shader_fx_lib.glsl")
+    data_to_c_simple("source/blender/gpu/shaders/gpu_shader_fx_vert.glsl")
     data_to_c_simple("intern/opencolorio/gpu_shader_display_transform.glsl")
 
     # --- blender ---
diff --git a/release/scripts/startup/bl_ui/properties_data_camera.py b/release/scripts/startup/bl_ui/properties_data_camera.py
index 0b0b9b6..7fc2c2e 100644
--- a/release/scripts/startup/bl_ui/properties_data_camera.py
+++ b/release/scripts/startup/bl_ui/properties_data_camera.py
@@ -177,6 +177,7 @@ class DATA_PT_camera_dof(CameraButtonsPanel, Panel):
         layout = self.layout
 
         cam = context.camera
+        dof_options = cam.gpu_dof
 
         layout.label(text="Focus:")
 
@@ -187,6 +188,7 @@ class DATA_PT_camera_dof(CameraButtonsPanel, Panel):
 
         col.active = cam.dof_object is None
         col.prop(cam, "dof_distance", text="Distance")
+        col.prop(dof_options, "fstop", text="GPU fstop")
 
 
 class DATA_PT_camera_display(CameraButtonsPanel, Panel):
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index d2c9571..b5bd137 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -2929,8 +2929,26 @@ class VIEW3D_PT_view3d_shading(Panel):
                 col.prop(view, "show_textured_shadeless")
 
         col.prop(view, "show_backface_culling")
-        if obj and obj.mode == 'EDIT' and view.viewport_shade not in {'BOUNDBOX', 'WIREFRAME'}:
-            col.prop(view, "show_occlude_wire")
+
+        if view.viewport_shade not in {'BOUNDBOX', 'WIREFRAME'}:
+            if obj and obj.mode == 'EDIT':
+                col.prop(view, "show_occlude_wire")
+
+            fx_settings = view.fx_settings
+
+            sub = col.column()
+            sub.active = view.region_3d.view_perspective == 'CAMERA'
+            sub.prop(fx_settings, "use_dof")
+
+            col.prop(fx_settings, "use_ssao", text="Ambient Occlusion")
+            if fx_settings.use_ssao:
+                ssao_settings = fx_settings.ssao
+                subcol = col.column(align=True)
+                subcol.prop(ssao_settings, "factor")
+                subcol.prop(ssao_settings, "distance_max")
+                subcol.prop(ssao_settings, "attenuation")
+                subcol.prop(ssao_settings, "samples")
+                subcol.prop(ssao_settings, "color")
 
 
 class VIEW3D_PT_view3d_motion_tracking(Panel):
diff --git a/source/blender/CMakeLists.txt b/source/blender/CMakeLists.txt
index 1cc232a..d87d5df 100644
--- a/source/blender/CMakeLists.txt
+++ b/source/blender/CMakeLists.txt
@@ -46,6 +46,7 @@ set(SRC_DNA_INC
 	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_freestyle_types.h
 	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_genfile.h
 	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_gpencil_types.h
+	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_gpu_types.h
 	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_group_types.h
 	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_image_types.h
 	${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_ipo_types.h
diff --git a/source/blender/blenkernel/BKE_camera.h b/source/blender/blenkernel/BKE_camera.h
index 26d4986..7729692 100644
--- a/source/blender/blenkernel/BKE_camera.h
+++ b/source/blender/blenkernel/BKE_camera.h
@@ -46,6 +46,7 @@ struct RenderData;
 struct Scene;
 struct rctf;
 struct View3D;
+struct GPUFXSettings;
 
 /* Camera Datablock */
 
@@ -122,6 +123,8 @@ bool BKE_camera_view_frame_fit_to_scene(struct Scene *scene, struct View3D *v3d,
 bool BKE_camera_view_frame_fit_to_coords(struct Scene *scene, float (*cos)[3], int num_cos,
                                          struct Object *camera_ob, float r_co[3], float *r_scale);
 
+void BKE_camera_to_gpu_dof(struct Object *camera, struct GPUFXSettings *r_fx_settings);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h
index 3eb6ba7..29590c5 100644
--- a/source/blender/blenkernel/BKE_screen.h
+++ b/source/blender/blenkernel/BKE_screen.h
@@ -52,6 +52,7 @@ struct wmKeyConfig;
 struct wmNotifier;
 struct wmWindow;
 struct wmWindowManager;
+struct GPUFXSettings;
 
 #include "BLI_compiler_attrs.h"
 
@@ -294,6 +295,7 @@ void BKE_screen_view3d_scene_sync(struct bScreen *sc);
 void BKE_screen_view3d_main_sync(ListBase *screen_lb, struct Scene *scene);
 void BKE_screen_view3d_twmode_remove(struct View3D *v3d, const int i);
 void BKE_screen_view3d_main_twmode_remove(ListBase *screen_lb, struct Scene *scene, const int i);
+void BKE_screen_gpu_fx_validate(struct GPUFXSettings *fx_settings);
 
 /* zoom factor conversion */
 float BKE_screen_view3d_zoom_to_fac(float camzoom);
diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c
index e424823..e1d771d 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -49,6 +49,8 @@
 #include "BKE_main.h"
 #include "BKE_screen.h"
 
+#include "GPU_compositing.h"
+
 /****************************** Camera Datablock *****************************/
 
 void *BKE_camera_add(Main *bmain, const char *name)
@@ -66,7 +68,9 @@ void *BKE_camera_add(Main *bmain, const char *name)
 	cam->ortho_scale = 6.0;
 	cam->flag |= CAM_SHOWPASSEPARTOUT;
 	cam->passepartalpha = 0.5f;
-	
+
+	GPU_fx_compositor_init_dof_settings(&cam->gpu_dof);
+
 	return cam;
 }
 
@@ -686,3 +690,18 @@ bool BKE_camera_view_frame_fit_to_coords(
 	return camera_frame_fit_calc_from_data(&params, &data_cb, r_co, r_scale);
 }
 
+void BKE_camera_to_gpu_dof(struct Object *camera, struct GPUFXSettings *r_fx_settings)
+{
+	if (camera->type == OB_CAMERA) {
+		Camera *cam = camera->data;
+		r_fx_settings->dof = &cam->gpu_dof;
+		r_fx_settings->dof->focal_length = cam->lens;
+		r_fx_settings->dof->sensor = BKE_camera_sensor_size(cam->sensor_fit, cam->sensor_x, cam->sensor_y);
+		if (cam->dof_ob) {
+			r_fx_settings->dof->focus_distance = len_v3v3(cam->dof_ob->obmat[3], camera->obmat[3]);
+		}
+		else {
+			r_fx_settings->dof->focus_distance = cam->YF_dofdist;
+		}
+	}
+}
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index c9dba38..a6ac455 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -39,6 +39,8 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "GPU_compositing.h"
+
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_space_types.h"
@@ -598,3 +600,26 @@ float BKE_screen_view3d_zoom_from_fac(float zoomfac)
 {
 	return ((sqrtf(4.0f * zoomfac) - (float)M_SQRT2) * 50.0f);
 }
+
+void BKE_screen_gpu_fx_validate(GPUFXSettings *fx_settings)
+{
+	/* currently we use DOF from the camera _only_,
+	 * so we never allocate this, only copy from the Camera */
+#if 0
+	if ((fx_settings->dof == NULL) &&
+	    (fx_settings->fx_flag & GPU_FX_FLAG_DOF))
+	{
+		GPUDOFSettings *fx_dof;
+		fx_dof = fx_settings->dof = MEM_callocN(sizeof(GPUDOFSettings), __func__);
+	}
+#endif
+
+	if ((fx_settings->ssao == NULL) &&
+	    (fx_settings->fx_flag & GPU_FX_FLAG_SSAO))
+	{
+		GPUSSAOSettings *fx_ssao;
+		fx_ssao = fx_settings->ssao = MEM_callocN(sizeof(GPUSSAOSettings), __func__);
+
+		GPU_fx_compositor_init_ssao_settings(fx_ssao);
+	}
+}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 66fbca3..204a7af 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6421,6 +6421,7 @@ static void direct_link_region(FileData *fd, ARegion *ar, int spacetype)
 				rv3d->render_engine = NULL;
 				rv3d->sms = NULL;
 				rv3d->smooth_timer = NULL;
+				rv3d->compositor = NULL;
 			}
 		}
 	}
@@ -6528,7 +6529,7 @@ static bool direct_link_screen(FileData *fd, bScreen *sc)
 		/* add local view3d too */
 		else if (sa->spacetype == SPACE_VIEW3D)
 			blo_do_versions_view3d_split_250(sa->spacedata.first, &sa->regionbase);
-		
+
 		/* incase we set above */
 		sa->butspacetype = sa->spacetype;
 
@@ -6575,6 +6576,11 @@ static bool direct_link_screen(FileData *fd, bScreen *sc)
 				/* render can be quite heavy, set to solid on load */
 				if (v3d->drawtype == OB_RENDER)
 					v3d->drawtype = OB_SOLID;
+
+				if (v3d->fx_settings.dof)
+					v3d->fx_settings.dof = newdataadr(fd, v3d->fx_settings.dof);
+				if (v3d->fx_settings.ssao)
+					v3d->fx_settings.ssao = newdataadr(fd, v3d->fx_settings.ssao);
 				
 				blo_do_versions_view3d_split_250(v3d, &sl->regionbase);
 			}
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index 572566d..23bf291 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -35,6 +35,7 @@
 #define DNA_DEPRECATED_ALLOW
 
 #include "DNA_brush_types.h"
+#include "DNA_camera_types.h"
 #include "DNA_cloth_types.h"
 #include "DNA_constraint_types.h"
 #include "DNA_sdna_types.h"
@@ -562,6 +563,16 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
 			}
 			FOREACH_NODETREE_END
 		}
+
+		if (!DNA_struct_elem_find(fd->filesdna, "Camera", "GPUDOFSettings", "gpu_dof")) {
+			Camera *ca;
+			for (ca = main->camera.first; ca; ca = ca->id.next) {
+				ca->gpu_dof.fstop = 128.0f;
+				ca->gpu_dof.focal_length = 1.0f;
+				ca->gpu_dof.focus_distance = 1.0f;
+				ca->gpu_dof.sensor = 1.0f;
+			}
+		}
 	}
 
 	if (!MAIN_VERSION_ATLEAST(main, 273, 7)) {
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list