[Bf-blender-cvs] [31cdeed9169] tmp-workbench-rewrite2: Border Clipping
Miguel Pozo
noreply at git.blender.org
Thu Nov 3 20:02:28 CET 2022
Commit: 31cdeed91695dd2018ad39ac6f13163108a417b7
Author: Miguel Pozo
Date: Thu Nov 3 19:29:22 2022 +0100
Branches: tmp-workbench-rewrite2
https://developer.blender.org/rB31cdeed91695dd2018ad39ac6f13163108a417b7
Border Clipping
===================================================================
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
M source/blender/draw/engines/workbench/workbench_state.cc
===================================================================
diff --git a/source/blender/draw/engines/workbench/workbench_engine.cc b/source/blender/draw/engines/workbench/workbench_engine.cc
index ccfc22505b5..74615a29320 100644
--- a/source/blender/draw/engines/workbench/workbench_engine.cc
+++ b/source/blender/draw/engines/workbench/workbench_engine.cc
@@ -302,10 +302,6 @@ class Instance {
anti_aliasing_ps.setup_view(view, resolution);
- if (!scene_state.clip_planes.is_empty()) {
- // view.set_clip_planes(scene_state.clip_planes);
- }
-
resources.color_tx.acquire(resolution, GPU_RGBA16F);
resources.color_tx.clear(resources.world_buf.background_color);
if (scene_state.draw_object_id) {
diff --git a/source/blender/draw/engines/workbench/workbench_mesh_passes.cc b/source/blender/draw/engines/workbench/workbench_mesh_passes.cc
index e71b7273337..32d5f77cac9 100644
--- a/source/blender/draw/engines/workbench/workbench_mesh_passes.cc
+++ b/source/blender/draw/engines/workbench/workbench_mesh_passes.cc
@@ -12,14 +12,17 @@ bool MeshPass::is_empty() const
return is_empty_;
}
-void MeshPass::init_pass(SceneResources &resources, DRWState state)
+void MeshPass::init_pass(SceneResources &resources, DRWState state, int clip_planes)
{
is_empty_ = true;
PassMain::init();
- state_set(state);
+ state_set(state, clip_planes);
bind_texture(WB_MATCAP_SLOT, resources.matcap_tx);
bind_ssbo(WB_MATERIAL_SLOT, &resources.material_buf);
bind_ubo(WB_WORLD_SLOT, resources.world_buf);
+ if (clip_planes > 0) {
+ bind_ubo(DRW_CLIPPING_UBO_SLOT, resources.clip_planes_buf);
+ }
}
void MeshPass::init_subpasses(ePipelineType pipeline,
@@ -92,18 +95,18 @@ PassMain::Sub &MeshPass::sub_pass_get(ObjectRef &ref,
void OpaquePass::sync(const SceneState &scene_state, SceneResources &resources)
{
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL |
- scene_state.cull_state | scene_state.clip_state;
+ scene_state.cull_state;
- bool clip = scene_state.clip_state & DRW_STATE_CLIP_PLANES;
+ bool clip = scene_state.clip_planes.size() > 0;
DRWState in_front_state = state | DRW_STATE_WRITE_STENCIL | DRW_STATE_STENCIL_ALWAYS;
- gbuffer_in_front_ps_.init_pass(resources, in_front_state);
+ gbuffer_in_front_ps_.init_pass(resources, in_front_state, scene_state.clip_planes.size());
gbuffer_in_front_ps_.state_stencil(0xFF, 0xFF, 0x00);
gbuffer_in_front_ps_.init_subpasses(
ePipelineType::OPAQUE, scene_state.lighting_type, clip, resources.shader_cache);
state |= DRW_STATE_STENCIL_NEQUAL;
- gbuffer_ps_.init_pass(resources, state);
+ gbuffer_ps_.init_pass(resources, state, scene_state.clip_planes.size());
gbuffer_ps_.state_stencil(0x00, 0xFF, 0xFF);
gbuffer_ps_.init_subpasses(
ePipelineType::OPAQUE, scene_state.lighting_type, clip, resources.shader_cache);
@@ -175,17 +178,18 @@ bool OpaquePass::is_empty() const
void TransparentPass::sync(const SceneState &scene_state, SceneResources &resources)
{
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND_OIT |
- scene_state.cull_state | scene_state.clip_state;
+ scene_state.cull_state;
- bool clip = scene_state.clip_state & DRW_STATE_CLIP_PLANES;
+ bool clip = scene_state.clip_planes.size() > 0;
- accumulation_ps_.init_pass(resources, state | DRW_STATE_STENCIL_NEQUAL);
+ accumulation_ps_.init_pass(
+ resources, state | DRW_STATE_STENCIL_NEQUAL, scene_state.clip_planes.size());
accumulation_ps_.state_stencil(0x00, 0xFF, 0xFF);
accumulation_ps_.clear_color(float4(0.0f, 0.0f, 0.0f, 1.0f));
accumulation_ps_.init_subpasses(
ePipelineType::TRANSPARENT, scene_state.lighting_type, clip, resources.shader_cache);
- accumulation_in_front_ps_.init_pass(resources, state);
+ accumulation_in_front_ps_.init_pass(resources, state, scene_state.clip_planes.size());
accumulation_in_front_ps_.clear_color(float4(0.0f, 0.0f, 0.0f, 1.0f));
accumulation_in_front_ps_.init_subpasses(
ePipelineType::TRANSPARENT, scene_state.lighting_type, clip, resources.shader_cache);
@@ -245,12 +249,12 @@ bool TransparentPass::is_empty() const
void TransparentDepthPass::sync(const SceneState &scene_state, SceneResources &resources)
{
DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL |
- scene_state.cull_state | scene_state.clip_state;
+ scene_state.cull_state;
- bool clip = scene_state.clip_state & DRW_STATE_CLIP_PLANES;
+ bool clip = scene_state.clip_planes.size() > 0;
DRWState in_front_state = state | DRW_STATE_WRITE_STENCIL | DRW_STATE_STENCIL_ALWAYS;
- in_front_ps_.init_pass(resources, in_front_state);
+ in_front_ps_.init_pass(resources, in_front_state, scene_state.clip_planes.size());
in_front_ps_.state_stencil(0xFF, 0xFF, 0x00);
in_front_ps_.init_subpasses(
ePipelineType::OPAQUE, eLightingType::FLAT, clip, resources.shader_cache);
@@ -267,7 +271,7 @@ void TransparentDepthPass::sync(const SceneState &scene_state, SceneResources &r
merge_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 3);
state |= DRW_STATE_STENCIL_NEQUAL;
- main_ps_.init_pass(resources, state);
+ main_ps_.init_pass(resources, state, scene_state.clip_planes.size());
main_ps_.state_stencil(0x00, 0xFF, 0xFF);
main_ps_.init_subpasses(
ePipelineType::OPAQUE, eLightingType::FLAT, clip, resources.shader_cache);
diff --git a/source/blender/draw/engines/workbench/workbench_private.hh b/source/blender/draw/engines/workbench/workbench_private.hh
index 9d350fda4c7..bdcceb5b1d4 100644
--- a/source/blender/draw/engines/workbench/workbench_private.hh
+++ b/source/blender/draw/engines/workbench/workbench_private.hh
@@ -69,7 +69,6 @@ struct SceneState {
bool xray_mode;
DRWState cull_state;
- DRWState clip_state;
Vector<float4> clip_planes = {};
float4 background_color;
@@ -140,6 +139,7 @@ struct SceneResources {
StorageVectorBuffer<Material> material_buf = {"material_buf"};
UniformBuffer<WorldData> world_buf;
+ UniformArrayBuffer<float4, 6> clip_planes_buf;
static const int jitter_tx_size = 64;
Texture jitter_tx = "wb_jitter_tx";
@@ -165,7 +165,7 @@ class MeshPass : public PassMain {
/* Move to draw::Pass */
bool is_empty() const;
- void init_pass(SceneResources &resources, DRWState state);
+ void init_pass(SceneResources &resources, DRWState state, int clip_planes);
void init_subpasses(ePipelineType pipeline,
eLightingType lighting,
bool clip,
diff --git a/source/blender/draw/engines/workbench/workbench_resources.cc b/source/blender/draw/engines/workbench/workbench_resources.cc
index 3ed33bbfb27..c890a5bdbb5 100644
--- a/source/blender/draw/engines/workbench/workbench_resources.cc
+++ b/source/blender/draw/engines/workbench/workbench_resources.cc
@@ -156,6 +156,17 @@ void SceneResources::init(const SceneState &scene_state)
}
world_buf.push_update();
+
+ for (int i : IndexRange(6)) {
+ if (i < scene_state.clip_planes.size()) {
+ clip_planes_buf[i] = scene_state.clip_planes[i];
+ }
+ else {
+ clip_planes_buf[i] = float4(0);
+ }
+ }
+
+ clip_planes_buf.push_update();
}
} // namespace blender::workbench
diff --git a/source/blender/draw/engines/workbench/workbench_state.cc b/source/blender/draw/engines/workbench/workbench_state.cc
index a6a44e7cdb1..b9ea9a92cbe 100644
--- a/source/blender/draw/engines/workbench/workbench_state.cc
+++ b/source/blender/draw/engines/workbench/workbench_state.cc
@@ -59,12 +59,12 @@ void SceneState::init()
* 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;
+ DRWState old_clip_state = clip_planes.size() > 0 ? DRW_STATE_CLIP_PLANES : DRW_STATE_NO_DRAW;
+ if (new_clip_state != old_clip_state) {
reset_taa = true;
}
clip_planes.clear();
- if (clip_state & DRW_STATE_CLIP_PLANES) {
+ if (new_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]);
More information about the Bf-blender-cvs
mailing list