[Bf-blender-cvs] [d4cfdc6c2c9] tmp-workbench-rewrite2: split samples_len/draw_aa
Miguel Pozo
noreply at git.blender.org
Thu Nov 3 20:02:27 CET 2022
Commit: d4cfdc6c2c9a9977fa83bdcf7a6a49f7dc1041c8
Author: Miguel Pozo
Date: Thu Nov 3 13:14:11 2022 +0100
Branches: tmp-workbench-rewrite2
https://developer.blender.org/rBd4cfdc6c2c9a9977fa83bdcf7a6a49f7dc1041c8
split samples_len/draw_aa
===================================================================
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_private.hh
M source/blender/draw/engines/workbench/workbench_state.cc
===================================================================
diff --git a/source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc b/source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc
index 6a56585f72c..de0277e4320 100644
--- a/source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc
+++ b/source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc
@@ -130,21 +130,22 @@ AntiAliasingPass::~AntiAliasingPass()
void AntiAliasingPass::init(const SceneState &scene_state)
{
+ enabled_ = scene_state.draw_aa;
sample_ = scene_state.sample;
samples_len_ = scene_state.samples_len;
}
void AntiAliasingPass::sync(SceneResources &resources, int2 resolution)
{
- if (samples_len_ > 0) {
- taa_accumulation_tx_.ensure_2d(GPU_RGBA16F, resolution);
- sample0_depth_tx_.ensure_2d(GPU_DEPTH24_STENCIL8, resolution);
- }
- else {
+ if (!enabled_) {
taa_accumulation_tx_.free();
sample0_depth_tx_.free();
+ return;
}
+ taa_accumulation_tx_.ensure_2d(GPU_RGBA16F, resolution);
+ sample0_depth_tx_.ensure_2d(GPU_DEPTH24_STENCIL8, resolution);
+
taa_accumulation_ps_.init();
taa_accumulation_ps_.state_set(sample_ == 0 ? DRW_STATE_WRITE_COLOR :
DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ADD_FULL);
@@ -183,16 +184,10 @@ void AntiAliasingPass::sync(SceneResources &resources, int2 resolution)
smaa_resolve_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 3);
}
-bool AntiAliasingPass::setup_view(View &view, int2 resolution)
+void AntiAliasingPass::setup_view(View &view, int2 resolution)
{
- if (samples_len_ == 0) {
- /* AA disabled. */
- return true;
- }
-
- if (sample_ >= samples_len_) {
- /* TAA accumulation has finished. Just copy the result back */
- return false;
+ if (!enabled_) {
+ return;
}
float2 sample_offset;
@@ -229,8 +224,6 @@ bool AntiAliasingPass::setup_view(View &view, int2 resolution)
winmat.ptr(), persmat.ptr(), sample_offset.x / resolution.x, sample_offset.y / resolution.y);
view.sync(viewmat, winmat);
-
- return true;
}
void AntiAliasingPass::draw(Manager &manager,
@@ -240,7 +233,7 @@ void AntiAliasingPass::draw(Manager &manager,
GPUTexture *depth_tx,
GPUTexture *color_tx)
{
- if (samples_len_ == 0) {
+ if (!enabled_) {
/* TODO(Miguel Pozo): Should render to the input color_tx and depth_tx in the first place */
GPU_texture_copy(color_tx, resources.color_tx);
GPU_texture_copy(depth_tx, resources.depth_tx);
diff --git a/source/blender/draw/engines/workbench/workbench_effect_cavity.cc b/source/blender/draw/engines/workbench/workbench_effect_cavity.cc
index f939f50295b..f2ec83fbf73 100644
--- a/source/blender/draw/engines/workbench/workbench_effect_cavity.cc
+++ b/source/blender/draw/engines/workbench/workbench_effect_cavity.cc
@@ -23,7 +23,7 @@ void CavityEffect::init(const SceneState &scene_state, SceneResources &resources
curvature_enabled_ = scene_state.draw_curvature;
const int ssao_samples = scene_state.scene->display.matcap_ssao_samples;
- int sample_count = min_ii(max_ii(1, scene_state.samples_len) * ssao_samples, max_samples_);
+ int sample_count = min_ii(scene_state.samples_len * ssao_samples, max_samples_);
const int max_iter_count = sample_count / ssao_samples;
sample_ = scene_state.sample % max_iter_count;
diff --git a/source/blender/draw/engines/workbench/workbench_effect_dof.cc b/source/blender/draw/engines/workbench/workbench_effect_dof.cc
index ee687ec2746..b388c2d907e 100644
--- a/source/blender/draw/engines/workbench/workbench_effect_dof.cc
+++ b/source/blender/draw/engines/workbench/workbench_effect_dof.cc
@@ -111,7 +111,7 @@ void DofPass::init(const SceneState &scene_state)
resolve_sh_ = GPU_shader_create_from_info_name("workbench_effect_dof_resolve");
}
- offset_ = scene_state.sample / (float)max_ii(1, scene_state.samples_len);
+ offset_ = scene_state.sample / (float)scene_state.samples_len;
int2 half_res = scene_state.resolution / 2;
half_res = {max_ii(half_res.x, 1), max_ii(half_res.y, 1)};
diff --git a/source/blender/draw/engines/workbench/workbench_private.hh b/source/blender/draw/engines/workbench/workbench_private.hh
index 0e5e7ad9591..bc5c731a7c4 100644
--- a/source/blender/draw/engines/workbench/workbench_private.hh
+++ b/source/blender/draw/engines/workbench/workbench_private.hh
@@ -77,6 +77,7 @@ struct SceneState {
bool draw_curvature;
bool draw_outline;
bool draw_dof;
+ bool draw_aa;
bool draw_object_id;
bool draw_transparent_depth;
@@ -287,6 +288,7 @@ class DofPass {
class AntiAliasingPass {
private:
+ bool enabled_;
/** Current TAA sample index in [0..samples_len_] range. */
int sample_;
/** Total number of samples to after which TAA stops accumulating samples. */
@@ -331,7 +333,7 @@ class AntiAliasingPass {
void init(const SceneState &scene_state);
void sync(SceneResources &resources, int2 resolution);
- bool setup_view(View &view, int2 resolution);
+ void setup_view(View &view, int2 resolution);
void draw(Manager &manager,
View &view,
SceneResources &resources,
diff --git a/source/blender/draw/engines/workbench/workbench_state.cc b/source/blender/draw/engines/workbench/workbench_state.cc
index cf369078079..7799e99efe0 100644
--- a/source/blender/draw/engines/workbench/workbench_state.cc
+++ b/source/blender/draw/engines/workbench/workbench_state.cc
@@ -132,16 +132,19 @@ void SceneState::init()
}
int _samples_len = U.viewport_aa;
- if (is_navigating || is_playback) {
- /* Only draw using SMAA or no AA when navigating. */
- _samples_len = min_ii(_samples_len, 1);
- }
- else if (v3d && ELEM(v3d->shading.type, OB_RENDER, OB_MATERIAL)) {
+ if (v3d && ELEM(v3d->shading.type, OB_RENDER, OB_MATERIAL)) {
_samples_len = scene->display.viewport_aa;
}
else if (DRW_state_is_image_render()) {
_samples_len = scene->display.render_aa;
}
+ if (is_navigating || is_playback) {
+ /* Only draw using SMAA or no AA when navigating. */
+ _samples_len = min_ii(_samples_len, 1);
+ }
+ /* 0 samples means no AA */
+ draw_aa = _samples_len > 0;
+ _samples_len = max_ii(_samples_len, 1);
/* 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
More information about the Bf-blender-cvs
mailing list