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!
This commit is contained in:
Sergey Sharybin
2017-11-24 12:19:26 +01:00
parent 37fc23dd9e
commit 9b42b3e114
13 changed files with 81 additions and 20 deletions

View File

@@ -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"

View File

@@ -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)(

View File

@@ -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 */

View File

@@ -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;

View File

@@ -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(

View File

@@ -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);

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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 */

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);