[Bf-blender-cvs] [109b1a717ad] tmp-workbench-rewrite2: DrawConfig refactor
Miguel Pozo
noreply at git.blender.org
Fri Oct 28 19:33:00 CEST 2022
Commit: 109b1a717ad04f4a4bb0d85fdc00d9a85cdfa291
Author: Miguel Pozo
Date: Fri Oct 28 16:52:48 2022 +0200
Branches: tmp-workbench-rewrite2
https://developer.blender.org/rB109b1a717ad04f4a4bb0d85fdc00d9a85cdfa291
DrawConfig refactor
===================================================================
M source/blender/draw/CMakeLists.txt
A source/blender/draw/engines/workbench/workbench_config.cc
M source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc
M source/blender/draw/engines/workbench/workbench_effect_cavity.cc
M source/blender/draw/engines/workbench/workbench_effect_dof.cc
M source/blender/draw/engines/workbench/workbench_engine.cc
M source/blender/draw/engines/workbench/workbench_mesh_passes.cc
M source/blender/draw/engines/workbench/workbench_private.hh
M source/blender/draw/engines/workbench/workbench_resources.cc
===================================================================
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 243186e0c22..336f10343b9 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -153,6 +153,7 @@ set(SRC
engines/eevee_next/eevee_velocity.cc
engines/eevee_next/eevee_view.cc
engines/eevee_next/eevee_world.cc
+ engines/workbench/workbench_config.cc
engines/workbench/workbench_data.c
engines/workbench/workbench_effect_antialiasing.c
engines/workbench/workbench_effect_antialiasing.cc
diff --git a/source/blender/draw/engines/workbench/workbench_config.cc b/source/blender/draw/engines/workbench/workbench_config.cc
new file mode 100644
index 00000000000..bec2b0a614a
--- /dev/null
+++ b/source/blender/draw/engines/workbench/workbench_config.cc
@@ -0,0 +1,294 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2020 Blender Foundation. */
+
+#include "workbench_private.hh"
+
+#include "BKE_camera.h"
+#include "BKE_editmesh.h"
+#include "BKE_modifier.h"
+#include "BKE_object.h"
+#include "BKE_paint.h"
+#include "BKE_particle.h"
+#include "BKE_pbvh.h"
+#include "DEG_depsgraph_query.h"
+#include "DNA_camera_types.h"
+#include "DNA_fluid_types.h"
+#include "ED_paint.h"
+#include "ED_view3d.h"
+#include "GPU_capabilities.h"
+
+namespace blender::workbench {
+
+static const CustomData *get_loop_custom_data(const Mesh *mesh)
+{
+ if (mesh->runtime.wrapper_type == ME_WRAPPER_TYPE_BMESH) {
+ BLI_assert(mesh->edit_mesh != nullptr);
+ BLI_assert(mesh->edit_mesh->bm != nullptr);
+ return &mesh->edit_mesh->bm->ldata;
+ }
+ return &mesh->ldata;
+}
+
+static const CustomData *get_vert_custom_data(const Mesh *mesh)
+{
+ if (mesh->runtime.wrapper_type == ME_WRAPPER_TYPE_BMESH) {
+ BLI_assert(mesh->edit_mesh != nullptr);
+ BLI_assert(mesh->edit_mesh->bm != nullptr);
+ return &mesh->edit_mesh->bm->vdata;
+ }
+ return &mesh->vdata;
+}
+
+void DrawConfig::init()
+{
+ reset_taa = reset_taa_next_sample;
+ reset_taa_next_sample = false;
+
+ const DRWContextState *context = DRW_context_state_get();
+ View3D *v3d = context->v3d;
+ RegionView3D *rv3d = context->rv3d;
+
+ scene = DEG_get_evaluated_scene(context->depsgraph);
+
+ GPUTexture *viewport_tx = DRW_viewport_texture_list_get()->color;
+ resolution = int2(GPU_texture_width(viewport_tx), GPU_texture_height(viewport_tx));
+
+ camera_object = nullptr;
+ if (v3d && rv3d) {
+ camera_object = (rv3d->persp == RV3D_CAMOB) ? v3d->camera : nullptr;
+ }
+ else {
+ /*TODO(Miguel Pozo)*/
+ // camera = wpd->cam_original_ob;
+ }
+ Camera *camera = camera_object ? static_cast<Camera *>(camera_object->data) : nullptr;
+
+ object_mode = CTX_data_mode_enum_ex(context->object_edit, context->obact, context->object_mode);
+
+ /* TODO(Miguel Pozo):
+ * Check why Workbench Next exposes OB_MATERIAL, and Workbench exposes OB_RENDER */
+ bool is_render_mode = !v3d || ELEM(v3d->shading.type, OB_RENDER, OB_MATERIAL);
+
+ const View3DShading previous_shading = shading;
+ shading = is_render_mode ? scene->display.shading : v3d->shading;
+
+ cull_state = shading.flag & V3D_SHADING_BACKFACE_CULLING ? DRW_STATE_CULL_BACK :
+ DRW_STATE_NO_DRAW;
+
+ /* FIXME: This reproduce old behavior when workbench was separated in 2 engines.
+ * But this is a workaround for a missing update tagging. */
+ DRWState new_clip_state = RV3D_CLIPPING_ENABLED(v3d, rv3d) ? DRW_STATE_CLIP_PLANES :
+ DRW_STATE_NO_DRAW;
+ if (clip_state != new_clip_state) {
+ clip_state = new_clip_state;
+ reset_taa = true;
+ }
+ clip_planes.clear();
+ if (clip_state & DRW_STATE_CLIP_PLANES) {
+ int plane_len = (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXCLIP) ? 4 : 6;
+ for (auto i : IndexRange(plane_len)) {
+ clip_planes.append(rv3d->clip[i]);
+ }
+ }
+
+ if (!is_render_mode) {
+ if (shading.type < OB_SOLID) {
+ shading.light = V3D_LIGHTING_FLAT;
+ shading.color_type = V3D_SHADING_OBJECT_COLOR;
+ shading.xray_alpha = 0.0f;
+ }
+ else if (SHADING_XRAY_ENABLED(shading)) {
+ shading.xray_alpha = SHADING_XRAY_ALPHA(shading);
+ }
+ else {
+ shading.xray_alpha = 1.0f;
+ }
+ }
+ xray_mode = !is_render_mode && shading.xray_alpha != 1.0f;
+
+ if (SHADING_XRAY_FLAG_ENABLED(shading)) {
+ /* Disable shading options that aren't supported in transparency mode. */
+ shading.flag &= ~(V3D_SHADING_SHADOW | V3D_SHADING_CAVITY | V3D_SHADING_DEPTH_OF_FIELD);
+ }
+ if (SHADING_XRAY_ENABLED(shading) != SHADING_XRAY_ENABLED(previous_shading) ||
+ shading.flag != previous_shading.flag) {
+ reset_taa = true;
+ }
+
+ shading_type = shading_type_from_v3d_lighting(shading.light);
+ material_override = Material(shading.single_color);
+
+ background_color = float4(0.0f);
+ if (is_render_mode && scene->r.alphamode != R_ALPHAPREMUL) {
+ if (World *w = scene->world) {
+ background_color = float4(w->horr, w->horg, w->horb, 1.0f);
+ }
+ }
+
+ if (rv3d && rv3d->rflag & RV3D_GPULIGHT_UPDATE) {
+ reset_taa = true;
+ /* FIXME: This reproduce old behavior when workbench was separated in 2 engines.
+ * But this is a workaround for a missing update tagging. */
+ rv3d->rflag &= ~RV3D_GPULIGHT_UPDATE;
+ }
+
+ float4x4 matrix;
+ /*TODO(Miguel Pozo): New API ?*/
+ DRW_view_persmat_get(nullptr, matrix.ptr(), false);
+ if (matrix != view_projection_matrix) {
+ view_projection_matrix = matrix;
+ reset_taa = true;
+ }
+
+ bool is_playback = DRW_state_is_playback();
+ bool is_navigating = DRW_state_is_navigating();
+
+ /* Reset complete drawing when navigating or during viewport playback or when
+ * leaving one of those states. In case of multires modifier the navigation
+ * mesh differs from the viewport mesh, so we need to be sure to restart. */
+ if (is_playback || is_navigating) {
+ reset_taa = true;
+ reset_taa_next_sample = true;
+ }
+
+ int _aa_samples = U.viewport_aa;
+ if (is_navigating || is_playback) {
+ /* Only draw using SMAA or no AA when navigating. */
+ _aa_samples = min_ii(_aa_samples, 1);
+ }
+ else if (v3d && ELEM(v3d->shading.type, OB_RENDER, OB_MATERIAL)) {
+ _aa_samples = scene->display.viewport_aa;
+ }
+ else if (DRW_state_is_image_render()) {
+ _aa_samples = scene->display.render_aa;
+ }
+
+ /* Reset the TAA when we have already draw a sample, but the sample count differs from previous
+ * time. This removes render artifacts when the viewport anti-aliasing in the user preferences
+ * is set to a lower value. */
+ if (aa_samples != _aa_samples) {
+ aa_samples = _aa_samples;
+ reset_taa = true;
+ }
+
+ /* TODO(Miguel Pozo) volumes_do */
+
+ draw_cavity = shading.flag & V3D_SHADING_CAVITY &&
+ ELEM(shading.cavity_type, V3D_SHADING_CAVITY_SSAO, V3D_SHADING_CAVITY_BOTH);
+ draw_curvature = shading.flag & V3D_SHADING_CAVITY && ELEM(shading.cavity_type,
+ V3D_SHADING_CAVITY_CURVATURE,
+ V3D_SHADING_CAVITY_BOTH);
+ draw_outline = shading.flag & V3D_SHADING_OBJECT_OUTLINE;
+ draw_dof = camera && camera->dof.flag & CAM_DOF_ENABLED &&
+ shading.flag & V3D_SHADING_DEPTH_OF_FIELD;
+
+ draw_transparent_depth = draw_outline || draw_dof;
+ draw_object_id = draw_outline || draw_curvature;
+};
+
+void DrawConfig::ObjectConfig::compute_config()
+{
+ material_type = color_type_from_v3d_shading(color_type);
+ material_subtype = material_subtype_from_v3d_shading(color_type);
+ use_per_material_batches = image_paint_override == nullptr && ELEM(color_type,
+ V3D_SHADING_TEXTURE_COLOR,
+ V3D_SHADING_MATERIAL_COLOR);
+};
+
+const DrawConfig::ObjectConfig DrawConfig::get_object_config(Object *ob)
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ const Mesh *me = (ob->type == OB_MESH) ? static_cast<Mesh *>(ob->data) : nullptr;
+ const bool is_active = (ob == draw_ctx->obact);
+ /* TODO(Miguel Pozo) Is the double check needed?
+ * If it is, wouldn't be needed for sculpt_pbvh too?
+ */
+ const bool is_render = DRW_state_is_image_render() && (draw_ctx->v3d == nullptr);
+
+ DrawConfig::ObjectConfig config = {};
+ config.color_type = (eV3DShadingColorType)shading.color_type;
+ if (!(is_active && DRW_object_use_hide_faces(ob))) {
+ config.draw_shadow = (ob->dtx & OB_DRAW_NO_SHADOW_CAST) == 0 &&
+ shading.flag & V3D_SHADING_SHADOW;
+ }
+ if (me == nullptr) {
+ if (config.color_type == V3D_SHADING_TEXTURE_COLOR) {
+ config.color_type = V3D_SHADING_MATERIAL_COLOR;
+ }
+ else if (config.color_type == V3D_SHADING_VERTEX_COLOR) {
+ config.color_type = V3D_SHADING_OBJECT_COLOR;
+ }
+ /* Early return */
+ config.compute_config();
+ return config;
+ }
+
+ config.sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->v3d) &&
+ !DRW_state_is_image_render();
+
+ if (config.sculpt_pbvh) {
+ /* Shadows are unsupported in sculpt mode. We could revert to the slow
+ * method in this case but I'm not sure if it's a good idea given that
+ * sculpted meshes are heavy to begin with. */
+ config.draw_shadow = false;
+
+ if (config.color_type == V3D_SHADING_TEXTURE_COLOR &&
+ BKE_pbvh_type(ob->sculpt->pbvh) != PBVH_FACES) {
+ /* Force use of material color for sculpt. */
+ config.color_type = V3D_SHADING_MATERIAL_COLOR;
+ }
+
+ /* Bad call C is required to access the tool system that is context aware. Cast to non-const
+ * due to current API. */
+ bContext *C = (bContext *)DRW_context_state_get()->evil_C;
+ if (C != NULL) {
+ config.color_type = ED_paint_shading_color_override(
+ C, &scene->toolsettings->paint_mode, ob, config.color_type);
+ }
+ }
+ else {
+ const CustomData *cd_vdata = get_vert_custom_data(me);
+ const CustomData *cd_ldata = get_loop_custom_data(me);
+
+ bool has_color = (CustomData_has
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list