Workbench: Switching Draw engines based on draw mode
This commit is contained in:
parent
3759b2aa59
commit
d26b7592b8
@ -46,6 +46,7 @@ class VIEW3D_HT_header(Header):
|
||||
# Contains buttons like Mode, Pivot, Manipulator, Layer, Mesh Select Mode...
|
||||
row = layout
|
||||
layout.template_header_3D()
|
||||
row.prop(view, "viewport_shade")
|
||||
|
||||
if obj:
|
||||
mode = obj.mode
|
||||
|
@ -104,8 +104,9 @@ set(SRC
|
||||
engines/eevee/eevee_subsurface.c
|
||||
engines/eevee/eevee_temporal_sampling.c
|
||||
engines/eevee/eevee_volumes.c
|
||||
engines/workbench/workbench_materials_solid.c
|
||||
engines/workbench/workbench_engine.c
|
||||
engines/workbench/workbench_materials.c
|
||||
engines/workbench/solid_flat_mode.c
|
||||
engines/external/external_engine.c
|
||||
|
||||
DRW_engine.h
|
||||
@ -205,7 +206,7 @@ data_to_c_simple(engines/eevee/shaders/volumetric_resolve_frag.glsl SRC)
|
||||
data_to_c_simple(engines/eevee/shaders/volumetric_scatter_frag.glsl SRC)
|
||||
data_to_c_simple(engines/eevee/shaders/volumetric_integration_frag.glsl SRC)
|
||||
|
||||
data_to_c_simple(engines/workbench/shaders/silhouette_frag.glsl SRC)
|
||||
data_to_c_simple(engines/workbench/shaders/solid_frag.glsl SRC)
|
||||
data_to_c_simple(engines/workbench/shaders/workbench_vert.glsl SRC)
|
||||
|
||||
data_to_c_simple(modes/shaders/common_globals_lib.glsl SRC)
|
||||
|
95
source/blender/draw/engines/workbench/solid_flat_mode.c
Normal file
95
source/blender/draw/engines/workbench/solid_flat_mode.c
Normal file
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright 2016, Blender Foundation.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Blender Institute
|
||||
*
|
||||
*/
|
||||
|
||||
/** \file workbench_engine.c
|
||||
* \ingroup draw_engine
|
||||
*
|
||||
* Simple engine for drawing color and/or depth.
|
||||
* When we only need simple flat shaders.
|
||||
*/
|
||||
|
||||
#include "DRW_render.h"
|
||||
|
||||
#include "BKE_icons.h"
|
||||
#include "BKE_idprop.h"
|
||||
#include "BKE_main.h"
|
||||
|
||||
#include "GPU_shader.h"
|
||||
|
||||
#include "workbench_engine.h"
|
||||
#include "workbench_private.h"
|
||||
/* Shaders */
|
||||
|
||||
#define WORKBENCH_ENGINE "BLENDER_WORKBENCH"
|
||||
|
||||
|
||||
/* Functions */
|
||||
|
||||
static void workbench_engine_init(void *UNUSED(vedata))
|
||||
{
|
||||
workbench_solid_materials_init();
|
||||
}
|
||||
|
||||
static void workbench_cache_init(void *vedata)
|
||||
{
|
||||
workbench_solid_materials_cache_init((WORKBENCH_Data *)vedata);
|
||||
}
|
||||
|
||||
static void workbench_cache_populate(void *vedata, Object *ob)
|
||||
{
|
||||
workbench_solid_materials_cache_populate((WORKBENCH_Data *)vedata, ob);
|
||||
}
|
||||
|
||||
static void workbench_cache_finish(void *vedata)
|
||||
{
|
||||
workbench_solid_materials_cache_finish((WORKBENCH_Data *)vedata);
|
||||
}
|
||||
|
||||
static void workbench_draw_scene(void *vedata)
|
||||
{
|
||||
workbench_solid_materials_draw_scene((WORKBENCH_Data *)vedata);
|
||||
}
|
||||
|
||||
static void workbench_engine_free(void)
|
||||
{
|
||||
workbench_solid_materials_free();
|
||||
}
|
||||
|
||||
static const DrawEngineDataSize workbench_data_size = DRW_VIEWPORT_DATA_SIZE(WORKBENCH_Data);
|
||||
|
||||
DrawEngineType draw_engine_workbench_solid_flat = {
|
||||
NULL, NULL,
|
||||
N_("Workbench"),
|
||||
&workbench_data_size,
|
||||
&workbench_engine_init,
|
||||
&workbench_engine_free,
|
||||
&workbench_cache_init,
|
||||
&workbench_cache_populate,
|
||||
&workbench_cache_finish,
|
||||
NULL,
|
||||
&workbench_draw_scene,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
||||
#undef WORKBENCH_ENGINE
|
@ -43,36 +43,6 @@
|
||||
|
||||
/* Functions */
|
||||
|
||||
static void workbench_engine_init(void *UNUSED(vedata))
|
||||
{
|
||||
workbench_materials_init();
|
||||
}
|
||||
|
||||
static void workbench_cache_init(void *vedata)
|
||||
{
|
||||
workbench_materials_cache_init((WORKBENCH_Data *)vedata);
|
||||
}
|
||||
|
||||
static void workbench_cache_populate(void *vedata, Object *ob)
|
||||
{
|
||||
workbench_materials_cache_populate((WORKBENCH_Data *)vedata, ob);
|
||||
}
|
||||
|
||||
static void workbench_cache_finish(void *vedata)
|
||||
{
|
||||
workbench_materials_cache_finish((WORKBENCH_Data *)vedata);
|
||||
}
|
||||
|
||||
static void workbench_draw_scene(void *vedata)
|
||||
{
|
||||
workbench_materials_draw_scene((WORKBENCH_Data *)vedata);
|
||||
}
|
||||
|
||||
static void workbench_engine_free(void)
|
||||
{
|
||||
workbench_materials_free();
|
||||
}
|
||||
|
||||
static void workbench_layer_collection_settings_create(RenderEngine *UNUSED(engine), IDProperty *props)
|
||||
{
|
||||
BLI_assert(props &&
|
||||
@ -82,24 +52,6 @@ static void workbench_layer_collection_settings_create(RenderEngine *UNUSED(engi
|
||||
BKE_collection_engine_property_add_float_array(props, "object_color", default_object_color, 3);
|
||||
}
|
||||
|
||||
static const DrawEngineDataSize workbench_data_size = DRW_VIEWPORT_DATA_SIZE(WORKBENCH_Data);
|
||||
|
||||
DrawEngineType draw_engine_workbench_solid_flat = {
|
||||
NULL, NULL,
|
||||
N_("Workbench"),
|
||||
&workbench_data_size,
|
||||
&workbench_engine_init,
|
||||
&workbench_engine_free,
|
||||
&workbench_cache_init,
|
||||
&workbench_cache_populate,
|
||||
&workbench_cache_finish,
|
||||
NULL,
|
||||
&workbench_draw_scene,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
/* Note: currently unused, we may want to register so we can see this when debugging the view. */
|
||||
|
||||
RenderEngineType DRW_engine_viewport_workbench_type = {
|
||||
|
@ -26,7 +26,8 @@
|
||||
#include "workbench_private.h"
|
||||
#include "GPU_shader.h"
|
||||
|
||||
extern char datatoc_silhouette_frag_glsl[];
|
||||
extern char datatoc_solid_frag_glsl[];
|
||||
extern char datatoc_flat_lighting_frag_glsl[];
|
||||
extern char datatoc_workbench_vert_glsl[];
|
||||
|
||||
/* *********** STATIC *********** */
|
||||
@ -34,22 +35,23 @@ static struct {
|
||||
struct GPUShader *depth_sh;
|
||||
|
||||
/* Shading Pass */
|
||||
struct GPUShader *silhouette_sh;
|
||||
struct GPUShader *solid_sh;
|
||||
|
||||
} e_data = {NULL};
|
||||
|
||||
|
||||
void workbench_materials_init() {
|
||||
void workbench_solid_materials_init() {
|
||||
if (!e_data.depth_sh) {
|
||||
/* Depth pass */
|
||||
e_data.depth_sh = DRW_shader_create_3D_depth_only();
|
||||
|
||||
/* Shading pass */
|
||||
e_data.silhouette_sh = DRW_shader_create(
|
||||
datatoc_workbench_vert_glsl, NULL, datatoc_silhouette_frag_glsl, "\n");
|
||||
e_data.solid_sh = DRW_shader_create(
|
||||
datatoc_workbench_vert_glsl, NULL, datatoc_solid_frag_glsl, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
void workbench_materials_cache_init(WORKBENCH_Data* vedata)
|
||||
void workbench_solid_materials_cache_init(WORKBENCH_Data* vedata)
|
||||
{
|
||||
WORKBENCH_PassList *psl = vedata->psl;
|
||||
WORKBENCH_StorageList *stl = vedata->stl;
|
||||
@ -66,14 +68,20 @@ void workbench_materials_cache_init(WORKBENCH_Data* vedata)
|
||||
stl->g_data->depth_shgrp = DRW_shgroup_create(e_data.depth_sh, psl->depth_pass);
|
||||
}
|
||||
|
||||
/* Shadeless Pass */
|
||||
/* Solid Pass */
|
||||
{
|
||||
int state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL;
|
||||
psl->silhouette_pass = DRW_pass_create("Silhouette Pass", state);
|
||||
psl->solid_pass = DRW_pass_create("Solid Pass", state);
|
||||
}
|
||||
|
||||
/* Flat Lighting Pass */
|
||||
{
|
||||
int state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL;
|
||||
psl->lighting_pass = DRW_pass_create("Lighting Pass", state);
|
||||
}
|
||||
}
|
||||
|
||||
void workbench_materials_cache_populate(WORKBENCH_Data* vedata, Object *ob)
|
||||
void workbench_solid_materials_cache_populate(WORKBENCH_Data* vedata, Object *ob)
|
||||
{
|
||||
WORKBENCH_PassList *psl = vedata->psl;
|
||||
WORKBENCH_StorageList *stl = vedata->stl;
|
||||
@ -90,32 +98,45 @@ void workbench_materials_cache_populate(WORKBENCH_Data* vedata, Object *ob)
|
||||
/* Depth */
|
||||
DRW_shgroup_call_add(stl->g_data->depth_shgrp, geom, ob->obmat);
|
||||
|
||||
/* Silhouette */
|
||||
grp = DRW_shgroup_create(e_data.silhouette_sh, psl->silhouette_pass);
|
||||
/* Solid */
|
||||
grp = DRW_shgroup_create(e_data.solid_sh, psl->solid_pass);
|
||||
DRW_shgroup_uniform_vec3(grp, "color", color, 1);
|
||||
DRW_shgroup_call_add(grp, geom, ob->obmat);
|
||||
|
||||
/* Lighting */
|
||||
// if studio lighting
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void workbench_materials_cache_finish(WORKBENCH_Data *vedata)
|
||||
void workbench_solid_materials_cache_finish(WORKBENCH_Data *vedata)
|
||||
{
|
||||
WORKBENCH_StorageList *stl = ((WORKBENCH_Data *)vedata)->stl;
|
||||
|
||||
UNUSED_VARS(stl);
|
||||
}
|
||||
|
||||
void workbench_materials_draw_scene(WORKBENCH_Data *vedata)
|
||||
void workbench_solid_materials_draw_scene(WORKBENCH_Data *vedata)
|
||||
{
|
||||
|
||||
WORKBENCH_PassList *psl = ((WORKBENCH_Data *)vedata)->psl;
|
||||
DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
|
||||
|
||||
DRW_draw_pass(psl->depth_pass);
|
||||
DRW_draw_pass(psl->silhouette_pass);
|
||||
// if (studio lighting) {
|
||||
// DRW_draw_pass(psl->lighting_pass);
|
||||
// DRW_draw_pass(psl->solid_pass);
|
||||
// TODO: COMPOSITE
|
||||
// }
|
||||
|
||||
// if (flat lighting) {
|
||||
DRW_draw_pass(psl->solid_pass);
|
||||
// }
|
||||
}
|
||||
|
||||
void workbench_materials_free(void)
|
||||
void workbench_solid_materials_free(void)
|
||||
{
|
||||
DRW_SHADER_FREE_SAFE(e_data.silhouette_sh);
|
||||
DRW_SHADER_FREE_SAFE(e_data.solid_sh);
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,8 @@
|
||||
|
||||
#include "DRW_render.h"
|
||||
|
||||
#define WORKBENCH_ENGINE "BLENDER_WORKBENCH"
|
||||
|
||||
|
||||
typedef struct WORKBENCH_StorageList {
|
||||
struct WORKBENCH_PrivateData *g_data;
|
||||
@ -37,7 +39,8 @@ typedef struct WORKBENCH_StorageList {
|
||||
typedef struct WORKBENCH_PassList {
|
||||
struct DRWPass *depth_pass;
|
||||
|
||||
struct DRWPass *silhouette_pass;
|
||||
struct DRWPass *solid_pass;
|
||||
struct DRWPass *lighting_pass;
|
||||
} WORKBENCH_PassList;
|
||||
|
||||
typedef struct WORKBENCH_FrameBufferList {
|
||||
@ -59,16 +62,19 @@ typedef struct WORKBENCH_PrivateData {
|
||||
DRWShadingGroup *depth_shgrp;
|
||||
|
||||
DRWShadingGroup *shadeless_shgrp;
|
||||
|
||||
// Lighting passes
|
||||
DRWShadingGroup *flat_lighting_shgrp;
|
||||
} WORKBENCH_PrivateData; /* Transient data */
|
||||
|
||||
|
||||
/* workbench_materials.c */
|
||||
void workbench_materials_init(void);
|
||||
void workbench_materials_cache_init(WORKBENCH_Data* vedata);
|
||||
void workbench_materials_cache_populate(WORKBENCH_Data* vedata, Object* ob);
|
||||
void workbench_materials_cache_finish(WORKBENCH_Data* vedata);
|
||||
void workbench_materials_draw_scene(WORKBENCH_Data* vedata);
|
||||
void workbench_materials_free(void);
|
||||
void workbench_solid_materials_init(void);
|
||||
void workbench_solid_materials_cache_init(WORKBENCH_Data* vedata);
|
||||
void workbench_solid_materials_cache_populate(WORKBENCH_Data* vedata, Object* ob);
|
||||
void workbench_solid_materials_cache_finish(WORKBENCH_Data* vedata);
|
||||
void workbench_solid_materials_draw_scene(WORKBENCH_Data* vedata);
|
||||
void workbench_solid_materials_free(void);
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -187,16 +187,14 @@ static const EnumPropertyItem autosnap_items[] = {
|
||||
#endif
|
||||
|
||||
const EnumPropertyItem rna_enum_viewport_shade_items[] = {
|
||||
{OB_BOUNDBOX, "BOUNDBOX", ICON_BBOX, "Bounding Box", "Display the object's local bounding boxes only"},
|
||||
{OB_WIRE, "WIREFRAME", ICON_WIRE, "Wireframe", "Display the object as wire edges"},
|
||||
{OB_SOLID, "SOLID", ICON_SOLID, "Solid", "Display the object solid, lit with default OpenGL lights"},
|
||||
{OB_SOLID, "SOLID", ICON_SOLID, "Solid", "Display the object solid"},
|
||||
{OB_TEXTURE, "TEXTURED", ICON_POTATO, "Texture", "Display the object solid, with a texture"},
|
||||
{OB_MATERIAL, "MATERIAL", ICON_MATERIAL_DATA, "Material", "Display objects solid, with GLSL material"},
|
||||
{OB_RENDER, "RENDERED", ICON_SMOOTH, "Rendered", "Display render preview"},
|
||||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
const EnumPropertyItem rna_enum_clip_editor_mode_items[] = {
|
||||
{SC_MODE_TRACKING, "TRACKING", ICON_ANIM_DATA, "Tracking", "Show tracking and solving tools"},
|
||||
{SC_MODE_MASKEDIT, "MASK", ICON_MOD_MASK, "Mask", "Show mask editing tools"},
|
||||
|
Loading…
Reference in New Issue
Block a user