From 9b42b3e11462e96bf24970971ab181122c6b33df Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 24 Nov 2017 12:19:26 +0100 Subject: Sequencer: Add option to render OpenGL preview with DoF The title says it all actually, controlled with DoF check box next to textured solid check box. Thanks Campbell for review! --- release/scripts/startup/bl_ui/space_sequencer.py | 2 ++ source/blender/blenkernel/BKE_sequencer.h | 3 ++- source/blender/blenkernel/intern/sequencer.c | 1 + source/blender/blenloader/intern/readfile.c | 2 +- source/blender/editors/include/ED_view3d.h | 1 + source/blender/editors/render/render_opengl.c | 5 +++++ .../editors/space_sequencer/sequencer_draw.c | 9 +++++++- .../editors/space_sequencer/space_sequencer.c | 7 ++++++ source/blender/editors/space_view3d/view3d_draw.c | 19 ++++++++++------ source/blender/makesdna/DNA_scene_types.h | 9 +++++--- source/blender/makesdna/DNA_space_types.h | 3 +++ source/blender/makesrna/intern/rna_camera.c | 15 +++++++++++-- source/blender/makesrna/intern/rna_scene.c | 25 ++++++++++++++++------ 13 files changed, 81 insertions(+), 20 deletions(-) diff --git a/release/scripts/startup/bl_ui/space_sequencer.py b/release/scripts/startup/bl_ui/space_sequencer.py index 1ca1da315b7..106e6695553 100644 --- a/release/scripts/startup/bl_ui/space_sequencer.py +++ b/release/scripts/startup/bl_ui/space_sequencer.py @@ -1128,6 +1128,8 @@ class SEQUENCER_PT_preview(SequencerButtonsPanel_Output, Panel): row.active = render.sequencer_gl_preview == 'SOLID' row.prop(render, "use_sequencer_gl_textured_solid") + col.prop(render, "use_sequencer_gl_dof") + class SEQUENCER_PT_view(SequencerButtonsPanel_Output, Panel): bl_label = "View Settings" diff --git a/source/blender/blenkernel/BKE_sequencer.h b/source/blender/blenkernel/BKE_sequencer.h index 66325cee98e..6c9dc12b44f 100644 --- a/source/blender/blenkernel/BKE_sequencer.h +++ b/source/blender/blenkernel/BKE_sequencer.h @@ -421,13 +421,14 @@ struct Sequence *BKE_sequencer_add_sound_strip(struct bContext *C, ListBase *seq struct Sequence *BKE_sequencer_add_movie_strip(struct bContext *C, ListBase *seqbasep, struct SeqLoadInfo *seq_load); /* view3d draw callback, run when not in background view */ -/* NOTE: Keep in sync with V3D_OFS_* flags. */ +/* NOTE: Keep in sync with V3D_OFSDRAW_* flags. */ enum { SEQ_OFSDRAW_NONE = (0), SEQ_OFSDRAW_USE_BACKGROUND = (1 << 0), SEQ_OFSDRAW_USE_FULL_SAMPLE = (1 << 1), SEQ_OFSDRAW_USE_GPENCIL = (1 << 2), SEQ_OFSDRAW_USE_SOLID_TEX = (1 << 2), + SEQ_OFSDRAW_USE_CAMERA_DOF = (1 << 3), }; typedef struct ImBuf *(*SequencerDrawView)( diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index 592091b057f..9e8e202c2bc 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -3305,6 +3305,7 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, Sequence *seq draw_flags |= (use_background) ? SEQ_OFSDRAW_USE_BACKGROUND : 0; draw_flags |= (context->gpu_full_samples) ? SEQ_OFSDRAW_USE_FULL_SAMPLE : 0; draw_flags |= (context->scene->r.seq_flag & R_SEQ_SOLID_TEX) ? SEQ_OFSDRAW_USE_SOLID_TEX : 0; + draw_flags |= (context->scene->r.seq_flag & R_SEQ_CAMERA_DOF) ? SEQ_OFSDRAW_USE_CAMERA_DOF : 0; /* for old scene this can be uninitialized, * should probably be added to do_versions at some point if the functionality stays */ diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 646cf978453..fb45fdc8136 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -7298,7 +7298,7 @@ static bool direct_link_screen(FileData *fd, bScreen *sc) sseq->scopes.sep_waveform_ibuf = NULL; sseq->scopes.vector_ibuf = NULL; sseq->scopes.histogram_ibuf = NULL; - + sseq->compositor = NULL; } else if (sl->spacetype == SPACE_BUTS) { SpaceButs *sbuts = (SpaceButs *)sl; diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 0a87360e58d..2cc928117c5 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -376,6 +376,7 @@ enum { /* Only works with ED_view3d_draw_offscreen_imbuf_simple(). */ V3D_OFSDRAW_USE_GPENCIL = (1 << 2), V3D_OFSDRAW_USE_SOLID_TEX = (1 << 2), + V3D_OFSDRAW_USE_CAMERA_DOF = (1 << 3), }; struct ImBuf *ED_view3d_draw_offscreen_imbuf( diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c index a2d34ffefa8..b7a23bafced 100644 --- a/source/blender/editors/render/render_opengl.c +++ b/source/blender/editors/render/render_opengl.c @@ -684,6 +684,11 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op) oglrender->fx = GPU_fx_compositor_create(); } } + else if (is_sequencer) { + if (scene->r.seq_flag & R_SEQ_CAMERA_DOF) { + oglrender->fx = GPU_fx_compositor_create(); + } + } /* create render */ oglrender->re = RE_NewSceneRender(scene); diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 160aa157189..bb7e2d75482 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -60,6 +60,7 @@ #include "BIF_glutil.h" #include "GPU_basic_shader.h" +#include "GPU_compositing.h" #include "ED_anim_api.h" #include "ED_gpencil.h" @@ -908,7 +909,7 @@ void ED_sequencer_special_preview_clear(void) ImBuf *sequencer_ibuf_get(struct Main *bmain, Scene *scene, SpaceSeq *sseq, int cfra, int frame_ofs, const char *viewname) { - SeqRenderData context; + SeqRenderData context = {0}; ImBuf *ibuf; int rectx, recty; float render_size; @@ -935,6 +936,12 @@ ImBuf *sequencer_ibuf_get(struct Main *bmain, Scene *scene, SpaceSeq *sseq, int rectx, recty, proxy_size, &context); context.view_id = BKE_scene_multiview_view_id_get(&scene->r, viewname); + if (scene->r.seq_flag & R_SEQ_CAMERA_DOF) { + if (sseq->compositor == NULL) { + sseq->compositor = GPU_fx_compositor_create(); + } + context.gpu_fx = sseq->compositor; + } /* sequencer could start rendering, in this case we need to be sure it wouldn't be canceled * by Esc pressed somewhere in the past diff --git a/source/blender/editors/space_sequencer/space_sequencer.c b/source/blender/editors/space_sequencer/space_sequencer.c index f1d0f23f8af..6b50d3fecdf 100644 --- a/source/blender/editors/space_sequencer/space_sequencer.c +++ b/source/blender/editors/space_sequencer/space_sequencer.c @@ -60,6 +60,8 @@ #include "IMB_imbuf.h" +#include "GPU_compositing.h" + #include "sequencer_intern.h" // own include /**************************** common state *****************************/ @@ -218,6 +220,11 @@ static void sequencer_free(SpaceLink *sl) if (scopes->histogram_ibuf) IMB_freeImBuf(scopes->histogram_ibuf); + + if (sseq->compositor != NULL) { + GPU_fx_compositor_destroy(sseq->compositor); + sseq->compositor = NULL; + } } diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index 8fd38d6a8de..9e220f4b141 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -3473,15 +3473,22 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple( v3d.lay = scene->lay; v3d.drawtype = drawtype; v3d.flag2 = V3D_RENDER_OVERRIDE; - - if (draw_flags & V3D_OFSDRAW_USE_GPENCIL) - v3d.flag2 |= V3D_SHOW_GPENCIL; - if (draw_flags & V3D_OFSDRAW_USE_SOLID_TEX) + if (draw_flags & V3D_OFSDRAW_USE_GPENCIL) { + v3d.flag2 |= V3D_SHOW_GPENCIL; + } + if (draw_flags & V3D_OFSDRAW_USE_SOLID_TEX) { v3d.flag2 |= V3D_SOLID_TEX; - - if (draw_flags & V3D_OFSDRAW_USE_BACKGROUND) + } + if (draw_flags & V3D_OFSDRAW_USE_BACKGROUND) { v3d.flag3 |= V3D_SHOW_WORLD; + } + if (draw_flags & V3D_OFSDRAW_USE_CAMERA_DOF) { + if (camera->type == OB_CAMERA) { + v3d.fx_settings.dof = &((Camera *)camera->data)->gpu_dof; + v3d.fx_settings.fx_flag |= GPU_FX_FLAG_DOF; + } + } rv3d.persp = RV3D_CAMOB; diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index b9f19a36072..90815b95d24 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -1744,9 +1744,12 @@ typedef struct Scene { #define R_USE_WS_SHADING 0x8000000 /* use world space interpretation of lighting data */ /* seq_flag */ -// #define R_SEQ_GL_PREV 1 // UNUSED, we just use setting from seq_prev_type now. -// #define R_SEQ_GL_REND 2 // UNUSED, opengl render has its own operator now. -#define R_SEQ_SOLID_TEX 4 +enum { + // R_SEQ_GL_PREV = (1 << 1), // UNUSED, we just use setting from seq_prev_type now. + // R_SEQ_GL_REND = (1 << 2), // UNUSED, opengl render has its own operator now. + R_SEQ_SOLID_TEX = (1 << 3), + R_SEQ_CAMERA_DOF = (1 << 4), +}; /* displaymode */ diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h index a0f77d61d1d..015583d898c 100644 --- a/source/blender/makesdna/DNA_space_types.h +++ b/source/blender/makesdna/DNA_space_types.h @@ -512,6 +512,9 @@ typedef struct SpaceSeq { char multiview_eye; /* multiview current eye - for internal use */ char pad2[7]; + + struct GPUFX *compositor; + void *pad3; } SpaceSeq; diff --git a/source/blender/makesrna/intern/rna_camera.c b/source/blender/makesrna/intern/rna_camera.c index 68cd2902acd..981ae75e7c5 100644 --- a/source/blender/makesrna/intern/rna_camera.c +++ b/source/blender/makesrna/intern/rna_camera.c @@ -39,8 +39,11 @@ #ifdef RNA_RUNTIME #include "BKE_camera.h" -#include "BKE_object.h" #include "BKE_depsgraph.h" +#include "BKE_object.h" +#include "BKE_sequencer.h" + +#include "WM_api.h" static float rna_Camera_angle_get(PointerRNA *ptr) { @@ -94,6 +97,14 @@ static void rna_Camera_dependency_update(Main *bmain, Scene *UNUSED(scene), Poin DAG_id_tag_update(&camera->id, 0); } +static void rna_Camera_dof_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr)) +{ + /* TODO(sergey): Can be more selective here. */ + BKE_sequencer_cache_cleanup(); + BKE_sequencer_preprocessed_cache_cleanup(); + WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, scene); +} + #else static void rna_def_camera_stereo_data(BlenderRNA *brna) @@ -323,7 +334,7 @@ void RNA_def_camera(BlenderRNA *brna) RNA_def_property_range(prop, 0.0f, FLT_MAX); RNA_def_property_ui_range(prop, 0.0f, 5000.0f, 1, 2); RNA_def_property_ui_text(prop, "DOF Distance", "Distance to the focus point for depth of field"); - RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL); + RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_dof_update"); /* Stereo Settings */ prop = RNA_def_property(srna, "stereo", PROP_POINTER, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 8f050fcbd49..fda92ff7c0d 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -2133,6 +2133,14 @@ static void rna_GPUDOFSettings_blades_set(PointerRNA *ptr, const int value) dofsettings->num_blades = value; } +static void rna_GPUDOFSettings_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr)) +{ + /* TODO(sergey): Can be more selective here. */ + BKE_sequencer_cache_cleanup(); + BKE_sequencer_preprocessed_cache_cleanup(); + WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, scene); +} + static void rna_Stereo3dFormat_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) { ID *id = ptr->id.data; @@ -4909,37 +4917,37 @@ static void rna_def_gpu_dof_fx(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Focus distance", "Viewport depth of field focus distance"); RNA_def_property_range(prop, 0.0f, FLT_MAX); RNA_def_property_ui_range(prop, 0.0f, 5000.0f, 1, 2); - RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_GPUDOFSettings_update"); prop = RNA_def_property(srna, "focal_length", PROP_FLOAT, PROP_DISTANCE_CAMERA); RNA_def_property_ui_text(prop, "Focal Length", "Focal length for dof effect"); RNA_def_property_range(prop, 1.0f, FLT_MAX); RNA_def_property_ui_range(prop, 1.0f, 5000.0f, 1, 2); - RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_GPUDOFSettings_update"); prop = RNA_def_property(srna, "sensor", PROP_FLOAT, PROP_DISTANCE_CAMERA); RNA_def_property_ui_text(prop, "Sensor", "Size of sensor"); RNA_def_property_range(prop, 1.0f, FLT_MAX); RNA_def_property_ui_range(prop, 1.0f, 5000.0f, 1, 2); - RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_GPUDOFSettings_update"); prop = RNA_def_property(srna, "fstop", PROP_FLOAT, PROP_NONE); RNA_def_property_ui_text(prop, "F-stop", "F-stop for dof effect"); RNA_def_property_range(prop, 0.0f, FLT_MAX); RNA_def_property_ui_range(prop, 0.1f, 128.0f, 10, 1); - RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_GPUDOFSettings_update"); prop = RNA_def_property(srna, "blades", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "num_blades"); RNA_def_property_ui_text(prop, "Blades", "Blades for dof effect"); RNA_def_property_range(prop, 0, 16); RNA_def_property_int_funcs(prop, NULL, "rna_GPUDOFSettings_blades_set", NULL); - RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_GPUDOFSettings_update"); prop = RNA_def_property(srna, "use_high_quality", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "high_quality", 1); RNA_def_property_ui_text(prop, "High Quality", "Use high quality depth of field"); - RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_GPUDOFSettings_update"); prop = RNA_def_property(srna, "is_hq_supported", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_funcs(prop, "rna_gpu_is_hq_supported_get", NULL); @@ -6466,6 +6474,11 @@ static void rna_def_scene_render_data(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Textured Solid", "Draw face-assigned textures in solid draw method"); RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SceneSequencer_update"); + prop = RNA_def_property(srna, "use_sequencer_gl_dof", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "seq_flag", R_SEQ_CAMERA_DOF); + RNA_def_property_ui_text(prop, "Depth of Field", "Use depth of field using the values from scene strip active camera"); + RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SceneSequencer_update"); + /* layers */ prop = RNA_def_property(srna, "layers", PROP_COLLECTION, PROP_NONE); RNA_def_property_collection_sdna(prop, NULL, "layers", NULL); -- cgit v1.2.3