[Bf-blender-cvs] [e6998b6e625] blender2.8-workbench: Workbench: Silhouette shading
Jeroen Bakker
noreply at git.blender.org
Fri Apr 13 18:01:09 CEST 2018
Commit: e6998b6e62517a658aac5a042beab835e259d7e6
Author: Jeroen Bakker
Date: Fri Apr 13 15:49:50 2018 +0200
Branches: blender2.8-workbench
https://developer.blender.org/rBe6998b6e62517a658aac5a042beab835e259d7e6
Workbench: Silhouette shading
Currently it uses the `obj->col`. This needs to be made more intelligent
with fe collection overrides.
===================================================================
M source/blender/draw/CMakeLists.txt
A source/blender/draw/engines/workbench/shaders/silhouette_frag.glsl
A source/blender/draw/engines/workbench/shaders/workbench_vert.glsl
A source/blender/draw/engines/workbench/workbench_engine.c
A source/blender/draw/engines/workbench/workbench_engine.h
A source/blender/draw/engines/workbench/workbench_materials.c
A source/blender/draw/engines/workbench/workbench_private.h
M source/blender/draw/intern/draw_manager.c
===================================================================
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index eb66e9c20ea..3e09cdd9768 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -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)
diff --git a/source/blender/draw/engines/workbench/shaders/silhouette_frag.glsl b/source/blender/draw/engines/workbench/shaders/silhouette_frag.glsl
new file mode 100644
index 00000000000..3a6700bdadc
--- /dev/null
+++ b/source/blender/draw/engines/workbench/shaders/silhouette_frag.glsl
@@ -0,0 +1,8 @@
+uniform vec3 color;
+
+out vec4 fragColor;
+
+void main()
+{
+ fragColor = vec4(color, 1.0);
+}
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_vert.glsl b/source/blender/draw/engines/workbench/shaders/workbench_vert.glsl
new file mode 100644
index 00000000000..97639f03734
--- /dev/null
+++ b/source/blender/draw/engines/workbench/shaders/workbench_vert.glsl
@@ -0,0 +1,8 @@
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec3 pos;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+}
diff --git a/source/blender/draw/engines/workbench/workbench_engine.c b/source/blender/draw/engines/workbench/workbench_engine.c
new file mode 100644
index 00000000000..bcaed908ec6
--- /dev/null
+++ b/source/blender/draw/engines/workbench/workbench_engine.c
@@ -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
diff --git a/source/blender/draw/engines/workbench/workbench_engine.h b/source/blender/draw/engines/workbench/workbench_engine.h
new file mode 100644
index 00000000000..ca968452090
--- /dev/null
+++ b/source/blender/draw/engines/workbench/workbench_engine.h
@@ -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__ */
diff --git a/source/blender/draw/engines/workbench/workbench_materials.c b/source/blender/draw/engines/workbench/workbench_materials.c
new file mode 100644
index 00000000000..3a6d199cecf
--- /dev/null
+++ b/source/blender/draw/engines/workbench/workbench_materials.c
@@ -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);
+}
+
+
+
diff --git a/source/blender/draw/engines/workbench/workbench_private.h b/source/blender/draw/engines/workbench/workbench_private.h
new file mode 100644
index 00000000000..e9f915aebac
--- /dev/null
+++ b/source/blender/draw/engines/workbench/workbench_private.h
@@ -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
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list