Workbench: Silhouette shading

Currently it uses the `obj->col`. This needs to be made more intelligent
with fe collection overrides.
This commit is contained in:
Jeroen Bakker 2018-04-13 15:49:50 +02:00
parent 31067c9757
commit e6998b6e62
8 changed files with 353 additions and 0 deletions

View File

@ -104,6 +104,8 @@ set(SRC
engines/eevee/eevee_subsurface.c
engines/eevee/eevee_temporal_sampling.c
engines/eevee/eevee_volumes.c
engines/workbench/workbench_engine.c
engines/workbench/workbench_materials.c
engines/external/external_engine.c
DRW_engine.h
@ -204,6 +206,9 @@ 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/workbench_vert.glsl SRC)
data_to_c_simple(modes/shaders/common_globals_lib.glsl SRC)
data_to_c_simple(modes/shaders/common_view_lib.glsl SRC)
data_to_c_simple(modes/shaders/common_fxaa_lib.glsl SRC)

View File

@ -0,0 +1,8 @@
uniform vec3 color;
out vec4 fragColor;
void main()
{
fragColor = vec4(color, 1.0);
}

View File

@ -0,0 +1,8 @@
uniform mat4 ModelViewProjectionMatrix;
in vec3 pos;
void main()
{
gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
}

View File

@ -0,0 +1,105 @@
/*
* 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_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 const DrawEngineDataSize workbench_data_size = DRW_VIEWPORT_DATA_SIZE(WORKBENCH_Data);
DrawEngineType draw_engine_workbench_type = {
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 = {
NULL, NULL,
WORKBENCH_ENGINE, N_("Workbench"), RE_INTERNAL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
&draw_engine_workbench_type,
{NULL, NULL, NULL}
};
#undef WORKBENCH_ENGINE

View File

@ -0,0 +1,32 @@
/*
* 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.h
* \ingroup draw_engine
*/
#ifndef __WORKBENCH_ENGINE_H__
#define __WORKBENCH_ENGINE_H__
extern DrawEngineType draw_engine_workbench_type;
extern RenderEngineType DRW_engine_viewport_workbench_type;
#endif /* __WORKBENCH_ENGINE_H__ */

View File

@ -0,0 +1,119 @@
/*
* 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_silhouette_frag_glsl[];
extern char datatoc_workbench_vert_glsl[];
/* *********** STATIC *********** */
static struct {
struct GPUShader *depth_sh;
/* Shading Pass */
struct GPUShader *silhouette_sh;
} e_data = {NULL};
void workbench_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");
}
}
void workbench_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);
}
/* Shadeless Pass */
{
int state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL;
psl->silhouette_pass = DRW_pass_create("Silhouette Pass", state);
}
}
void workbench_materials_cache_populate(WORKBENCH_Data* vedata, Object *ob)
{
WORKBENCH_PassList *psl = vedata->psl;
WORKBENCH_StorageList *stl = vedata->stl;
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);
/* Silhouette */
grp = DRW_shgroup_create(e_data.silhouette_sh, psl->silhouette_pass);
DRW_shgroup_uniform_vec3(grp, "color", ob->col, 1);
DRW_shgroup_call_add(grp, geom, ob->obmat);
}
}
void workbench_materials_cache_finish(WORKBENCH_Data *vedata)
{
WORKBENCH_StorageList *stl = ((WORKBENCH_Data *)vedata)->stl;
UNUSED_VARS(stl);
}
void workbench_materials_draw_scene(WORKBENCH_Data *vedata)
{
WORKBENCH_PassList *psl = ((WORKBENCH_Data *)vedata)->psl;
DRW_draw_pass(psl->depth_pass);
DRW_draw_pass(psl->silhouette_pass);
}
void workbench_materials_free(void)
{
DRW_SHADER_FREE_SAFE(e_data.silhouette_sh);
}

View File

@ -0,0 +1,74 @@
/*
* 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_private.h
* \ingroup draw_engine
*/
#ifndef __WORKBENCH_PRIVATE_H__
#define __WORKBENCH_PRIVATE_H__
#include "DRW_render.h"
typedef struct WORKBENCH_StorageList {
struct WORKBENCH_PrivateData *g_data;
} WORKBENCH_StorageList;
typedef struct WORKBENCH_PassList {
struct DRWPass *depth_pass;
struct DRWPass *silhouette_pass;
} WORKBENCH_PassList;
typedef struct WORKBENCH_FrameBufferList {
} WORKBENCH_FrameBufferList;
typedef struct WORKBENCH_TextureList {
} WORKBENCH_TextureList;
typedef struct WORKBENCH_Data {
void *engine_type;
WORKBENCH_FrameBufferList *fbl;
WORKBENCH_TextureList *txl;
WORKBENCH_PassList *psl;
WORKBENCH_StorageList *stl;
} WORKBENCH_Data;
typedef struct WORKBENCH_PrivateData {
DRWShadingGroup *depth_shgrp;
DRWShadingGroup *shadeless_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);
#endif

View File

@ -76,6 +76,7 @@
#include "engines/clay/clay_engine.h"
#include "engines/eevee/eevee_engine.h"
#include "engines/basic/basic_engine.h"
#include "engines/workbench/workbench_engine.h"
#include "engines/external/external_engine.h"
#include "../../../intern/gawain/gawain/gwn_context.h"
@ -1924,6 +1925,7 @@ void DRW_engines_register(void)
RE_engines_register(NULL, &DRW_engine_viewport_clay_type);
#endif
RE_engines_register(NULL, &DRW_engine_viewport_eevee_type);
RE_engines_register(NULL, &DRW_engine_viewport_workbench_type);
DRW_engine_register(&draw_engine_object_type);
DRW_engine_register(&draw_engine_edit_armature_type);