Workbench: clean up the viewport shading code
- added the drawtype_solid, drawtype_wireframe, drawtype_texture to View3D - enabled workbench panels for important render engines - merged workbench_materials to solid_flat_mode. All draw modes will get its own fast implementation in the workbench
This commit is contained in:
parent
dd8d55b31a
commit
3f762dd764
|
@ -87,12 +87,7 @@ class COLLECTION_PT_clay_settings(CollectionButtonsPanel, Panel):
|
|||
|
||||
|
||||
class COLLECTION_PT_workbench_settings(CollectionButtonsPanel, Panel):
|
||||
bl_label = "Render Settings"
|
||||
COMPAT_ENGINES = {'BLENDER_WORKBENCH'}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.view_render.engine in cls.COMPAT_ENGINES
|
||||
bl_label = "Workbench Settings"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
|
|
@ -913,8 +913,8 @@ class RENDER_PT_eevee_film(RenderButtonsPanel, Panel):
|
|||
|
||||
|
||||
class RENDER_PT_workbench_collection_settings(RenderButtonsPanel, Panel):
|
||||
bl_label = "Workbench Collection Settings"
|
||||
COMPAT_ENGINES = {'BLENDER_WORKBENCH'}
|
||||
bl_label = "Workbench Settings"
|
||||
COMPAT_ENGINES = {'BLENDER_WORKBENCH', 'BLENDER_EEVEE', 'CYCLES'}
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
|
|
@ -46,7 +46,10 @@ 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")
|
||||
row.prop(view, "viewport_shade", text="", icon_only=True)
|
||||
|
||||
if view.viewport_shade == "SOLID":
|
||||
row.prop(view, "viewport_shade_solid", text="")
|
||||
|
||||
if obj:
|
||||
mode = obj.mode
|
||||
|
|
|
@ -104,7 +104,6 @@ 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/solid_flat_mode.c
|
||||
engines/external/external_engine.c
|
||||
|
@ -206,7 +205,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/solid_frag.glsl SRC)
|
||||
data_to_c_simple(engines/workbench/shaders/solid_flat_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)
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
/** \file workbench_engine.c
|
||||
/** \file solid_flat_mode.c
|
||||
* \ingroup draw_engine
|
||||
*
|
||||
* Simple engine for drawing color and/or depth.
|
||||
|
@ -28,49 +28,112 @@
|
|||
|
||||
#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"
|
||||
extern char datatoc_solid_flat_frag_glsl[];
|
||||
extern char datatoc_workbench_vert_glsl[];
|
||||
|
||||
/* *********** STATIC *********** */
|
||||
static struct {
|
||||
struct GPUShader *depth_sh;
|
||||
|
||||
/* Shading Pass */
|
||||
struct GPUShader *solid_sh;
|
||||
|
||||
} e_data = {NULL};
|
||||
|
||||
|
||||
/* Functions */
|
||||
|
||||
static void workbench_engine_init(void *UNUSED(vedata))
|
||||
static void workbench_solid_flat_engine_init(void *UNUSED(vedata))
|
||||
{
|
||||
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.solid_sh = DRW_shader_create(
|
||||
datatoc_workbench_vert_glsl, NULL, datatoc_solid_flat_frag_glsl, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void workbench_cache_init(void *vedata)
|
||||
static void workbench_solid_flat_cache_init(void *vedata)
|
||||
{
|
||||
workbench_solid_materials_cache_init((WORKBENCH_Data *)vedata);
|
||||
|
||||
WORKBENCH_Data * data = (WORKBENCH_Data *)vedata;
|
||||
WORKBENCH_PassList *psl = data->psl;
|
||||
WORKBENCH_StorageList *stl = data->stl;
|
||||
|
||||
if (!stl->g_data) {
|
||||
/* Alloc transient pointers */
|
||||
stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
|
||||
}
|
||||
|
||||
/* Depth Pass */
|
||||
{
|
||||
int state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
|
||||
psl->depth_pass = DRW_pass_create("Depth Pass", state);
|
||||
stl->g_data->depth_shgrp = DRW_shgroup_create(e_data.depth_sh, psl->depth_pass);
|
||||
}
|
||||
|
||||
/* Solid Pass */
|
||||
{
|
||||
int state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
static void workbench_cache_populate(void *vedata, Object *ob)
|
||||
static void workbench_solid_flat_cache_populate(void *vedata, Object *ob)
|
||||
{
|
||||
workbench_solid_materials_cache_populate((WORKBENCH_Data *)vedata, ob);
|
||||
WORKBENCH_Data * data = (WORKBENCH_Data *)vedata;
|
||||
|
||||
WORKBENCH_PassList *psl = data->psl;
|
||||
WORKBENCH_StorageList *stl = data->stl;
|
||||
|
||||
IDProperty *props = BKE_layer_collection_engine_evaluated_get(ob, COLLECTION_MODE_NONE, RE_engine_id_BLENDER_WORKBENCH);
|
||||
const float* color = BKE_collection_engine_property_value_get_float_array(props, "object_color");
|
||||
|
||||
if (!DRW_object_is_renderable(ob))
|
||||
return;
|
||||
|
||||
struct Gwn_Batch *geom = DRW_cache_object_surface_get(ob);
|
||||
DRWShadingGroup *grp;
|
||||
if (geom) {
|
||||
/* Depth */
|
||||
DRW_shgroup_call_add(stl->g_data->depth_shgrp, geom, ob->obmat);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
||||
static void workbench_cache_finish(void *vedata)
|
||||
static void workbench_solid_flat_cache_finish(void *UNUSED(vedata))
|
||||
{
|
||||
workbench_solid_materials_cache_finish((WORKBENCH_Data *)vedata);
|
||||
}
|
||||
|
||||
static void workbench_draw_scene(void *vedata)
|
||||
static void workbench_solid_flat_draw_scene(void *vedata)
|
||||
{
|
||||
workbench_solid_materials_draw_scene((WORKBENCH_Data *)vedata);
|
||||
WORKBENCH_Data * data = (WORKBENCH_Data *)vedata;
|
||||
WORKBENCH_PassList *psl = ((WORKBENCH_Data *)vedata)->psl;
|
||||
|
||||
DRW_draw_pass(psl->depth_pass);
|
||||
DRW_draw_pass(psl->solid_pass);
|
||||
}
|
||||
|
||||
static void workbench_engine_free(void)
|
||||
static void workbench_solid_flat_engine_free(void)
|
||||
{
|
||||
workbench_solid_materials_free();
|
||||
DRW_SHADER_FREE_SAFE(e_data.solid_sh);
|
||||
}
|
||||
|
||||
static const DrawEngineDataSize workbench_data_size = DRW_VIEWPORT_DATA_SIZE(WORKBENCH_Data);
|
||||
|
@ -79,17 +142,14 @@ 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,
|
||||
&workbench_solid_flat_engine_init,
|
||||
&workbench_solid_flat_engine_free,
|
||||
&workbench_solid_flat_cache_init,
|
||||
&workbench_solid_flat_cache_populate,
|
||||
&workbench_solid_flat_cache_finish,
|
||||
NULL,
|
||||
&workbench_draw_scene,
|
||||
&workbench_solid_flat_draw_scene,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
||||
#undef WORKBENCH_ENGINE
|
||||
|
|
|
@ -1,143 +0,0 @@
|
|||
/*
|
||||
* 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_materials.c
|
||||
* \ingroup draw_engine
|
||||
*/
|
||||
|
||||
#include "workbench_private.h"
|
||||
#include "GPU_shader.h"
|
||||
|
||||
extern char datatoc_solid_frag_glsl[];
|
||||
extern char datatoc_flat_lighting_frag_glsl[];
|
||||
extern char datatoc_workbench_vert_glsl[];
|
||||
|
||||
/* *********** STATIC *********** */
|
||||
static struct {
|
||||
struct GPUShader *depth_sh;
|
||||
|
||||
/* Shading Pass */
|
||||
struct GPUShader *solid_sh;
|
||||
|
||||
} e_data = {NULL};
|
||||
|
||||
|
||||
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.solid_sh = DRW_shader_create(
|
||||
datatoc_workbench_vert_glsl, NULL, datatoc_solid_frag_glsl, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
void workbench_solid_materials_cache_init(WORKBENCH_Data* vedata)
|
||||
{
|
||||
WORKBENCH_PassList *psl = vedata->psl;
|
||||
WORKBENCH_StorageList *stl = vedata->stl;
|
||||
|
||||
if (!stl->g_data) {
|
||||
/* Alloc transient pointers */
|
||||
stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
|
||||
}
|
||||
|
||||
/* Depth Pass */
|
||||
{
|
||||
int state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
|
||||
psl->depth_pass = DRW_pass_create("Depth Pass", state);
|
||||
stl->g_data->depth_shgrp = DRW_shgroup_create(e_data.depth_sh, psl->depth_pass);
|
||||
}
|
||||
|
||||
/* Solid Pass */
|
||||
{
|
||||
int state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL;
|
||||
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_solid_materials_cache_populate(WORKBENCH_Data* vedata, Object *ob)
|
||||
{
|
||||
WORKBENCH_PassList *psl = vedata->psl;
|
||||
WORKBENCH_StorageList *stl = vedata->stl;
|
||||
|
||||
IDProperty *props = BKE_layer_collection_engine_evaluated_get(ob, COLLECTION_MODE_NONE, RE_engine_id_BLENDER_WORKBENCH);
|
||||
const float* color = BKE_collection_engine_property_value_get_float_array(props, "object_color");
|
||||
|
||||
if (!DRW_object_is_renderable(ob))
|
||||
return;
|
||||
|
||||
struct Gwn_Batch *geom = DRW_cache_object_surface_get(ob);
|
||||
DRWShadingGroup *grp;
|
||||
if (geom) {
|
||||
/* Depth */
|
||||
DRW_shgroup_call_add(stl->g_data->depth_shgrp, geom, ob->obmat);
|
||||
|
||||
/* 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_solid_materials_cache_finish(WORKBENCH_Data *vedata)
|
||||
{
|
||||
WORKBENCH_StorageList *stl = ((WORKBENCH_Data *)vedata)->stl;
|
||||
|
||||
UNUSED_VARS(stl);
|
||||
}
|
||||
|
||||
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);
|
||||
// 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_solid_materials_free(void)
|
||||
{
|
||||
DRW_SHADER_FREE_SAFE(e_data.solid_sh);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -895,11 +895,20 @@ static void drw_engines_enable_external(void)
|
|||
/* TODO revisit this when proper layering is implemented */
|
||||
/* Gather all draw engines needed and store them in DST.enabled_engines
|
||||
* That also define the rendering order of engines */
|
||||
static void drw_engines_enable_from_engine(RenderEngineType *engine_type, int draw_mode)
|
||||
static void drw_engines_enable_from_engine(RenderEngineType *engine_type, int draw_mode,
|
||||
int UNUSED(draw_mode_wireframe), int draw_mode_solid, int UNUSED(draw_mode_texture))
|
||||
{
|
||||
switch (draw_mode) {
|
||||
case OB_WIRE:
|
||||
break;
|
||||
|
||||
case OB_SOLID:
|
||||
use_drw_engine(&draw_engine_workbench_solid_flat);
|
||||
if (draw_mode_solid == OB_LIGHTING_FLAT) {
|
||||
use_drw_engine(&draw_engine_workbench_solid_flat);
|
||||
}
|
||||
break;
|
||||
|
||||
case OB_TEXTURE:
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -984,9 +993,13 @@ static void drw_engines_enable(ViewLayer *view_layer, RenderEngineType *engine_t
|
|||
{
|
||||
Object *obact = OBACT(view_layer);
|
||||
const int mode = CTX_data_mode_enum_ex(DST.draw_ctx.object_edit, obact, DST.draw_ctx.object_mode);
|
||||
const int draw_mode = DST.draw_ctx.v3d->drawtype;
|
||||
View3D * v3d = DST.draw_ctx.v3d;
|
||||
const int draw_mode = v3d->drawtype;
|
||||
const int draw_mode_wireframe = v3d->drawtype_wireframe;
|
||||
const int draw_mode_solid = v3d->drawtype_solid;
|
||||
const int draw_mode_texture = v3d->drawtype_texture;
|
||||
|
||||
drw_engines_enable_from_engine(engine_type, draw_mode);
|
||||
drw_engines_enable_from_engine(engine_type, draw_mode, draw_mode_wireframe, draw_mode_solid, draw_mode_texture);
|
||||
|
||||
if (DRW_state_draw_support()) {
|
||||
drw_engines_enable_from_object_mode();
|
||||
|
|
|
@ -446,6 +446,12 @@ enum {
|
|||
OB_PAINT = 100, /* temporary used in draw code */
|
||||
};
|
||||
|
||||
enum {
|
||||
OB_LIGHTING_FLAT = 0,
|
||||
OB_LIGHTING_STUDIO = 1,
|
||||
OB_LIGHTING_SCENE = 2
|
||||
};
|
||||
|
||||
/* dtx: flags (short) */
|
||||
enum {
|
||||
OB_DRAWBOUNDOX = 1 << 0,
|
||||
|
|
|
@ -238,8 +238,12 @@ typedef struct View3D {
|
|||
* Runtime-only, set in the rendered viewport toggle operator.
|
||||
*/
|
||||
short prev_drawtype;
|
||||
short pad1;
|
||||
float pad2;
|
||||
/* drawtype subtype (visibility) used when drawtype == OB_WIRE */
|
||||
short drawtype_wireframe;
|
||||
/* drawtype subtype (lighting) used when drawtype == OB_SOLID */
|
||||
short drawtype_solid;
|
||||
/* drawtype subtype (lighting) used when drawtype == OB_TEXTURE */
|
||||
short drawtype_texture;
|
||||
View3DDebug debug;
|
||||
} View3D;
|
||||
|
||||
|
|
|
@ -194,6 +194,19 @@ const EnumPropertyItem rna_enum_viewport_shade_items[] = {
|
|||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
const EnumPropertyItem rna_enum_viewport_shade_solid_items[] = {
|
||||
{OB_LIGHTING_FLAT, "FLAT", ICON_SOLID, "Flat Lighting", "Display using flat lighting"},
|
||||
{OB_LIGHTING_STUDIO, "STUDIO", ICON_SOLID, "Studio Lighting", "Display using studio lighting"},
|
||||
// {OB_LIGHTING_SCENE, "SCENE", ICON_SOLID, "Scene Lighting", "Display using scene lighting"},
|
||||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
const EnumPropertyItem rna_enum_viewport_shade_texture_items[] = {
|
||||
{OB_LIGHTING_FLAT, "FLAT", ICON_POTATO, "Flat Lighting", "Display using flat lighting"},
|
||||
{OB_LIGHTING_STUDIO, "STUDIO", ICON_POTATO, "Studio Lighting", "Display using studio lighting"},
|
||||
// {OB_LIGHTING_SCENE, "SCENE", ICON_POTATO, "Scene Lighting", "Display using scene lighting"},
|
||||
{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"},
|
||||
|
@ -2373,6 +2386,18 @@ static void rna_def_space_view3d(BlenderRNA *brna)
|
|||
RNA_def_property_ui_text(prop, "Viewport Shading", "Method to display/shade objects in the 3D View");
|
||||
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_SpaceView3D_viewport_shade_update");
|
||||
|
||||
prop = RNA_def_property(srna, "viewport_shade_solid", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_sdna(prop, NULL, "drawtype_solid");
|
||||
RNA_def_property_enum_items(prop, rna_enum_viewport_shade_solid_items);
|
||||
RNA_def_property_ui_text(prop, "Viewport Lighting (Solid)", "Lighting Method for Solid Viewport Shading");
|
||||
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_SpaceView3D_viewport_shade_update");
|
||||
|
||||
prop = RNA_def_property(srna, "viewport_shade_texture", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_sdna(prop, NULL, "drawtype_texture");
|
||||
RNA_def_property_enum_items(prop, rna_enum_viewport_shade_texture_items);
|
||||
RNA_def_property_ui_text(prop, "Viewport Lighting (Texture)", "Lighting Method for Texture Viewport Shading");
|
||||
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_SpaceView3D_viewport_shade_update");
|
||||
|
||||
prop = RNA_def_property(srna, "local_view", PROP_POINTER, PROP_NONE);
|
||||
RNA_def_property_pointer_sdna(prop, NULL, "localvd");
|
||||
RNA_def_property_ui_text(prop, "Local View",
|
||||
|
|
Loading…
Reference in New Issue