[Bf-blender-cvs] [c38e219a106] cycles-x: Cycles X: Move actual pass type logic outside of pass accessor
Sergey Sharybin
noreply at git.blender.org
Wed May 19 10:19:01 CEST 2021
Commit: c38e219a1066d076bcbb35a5732e6627e9bbadf5
Author: Sergey Sharybin
Date: Fri May 14 12:09:00 2021 +0200
Branches: cycles-x
https://developer.blender.org/rBc38e219a1066d076bcbb35a5732e6627e9bbadf5
Cycles X: Move actual pass type logic outside of pass accessor
Keeps the accessor free from tricky logic, allowing to make more
comprehensive decisions based on various scene settings.
Differential Revision: https://developer.blender.org/D11293
===================================================================
M intern/cycles/render/pass.cpp
M intern/cycles/render/pass.h
M intern/cycles/render/pass_accessor.cpp
M intern/cycles/render/pass_accessor.h
M intern/cycles/render/session.cpp
===================================================================
diff --git a/intern/cycles/render/pass.cpp b/intern/cycles/render/pass.cpp
index 8e4128b072c..63766accdcd 100644
--- a/intern/cycles/render/pass.cpp
+++ b/intern/cycles/render/pass.cpp
@@ -405,4 +405,40 @@ void Pass::remove_all_auto(vector<Pass> &passes)
passes = new_passes;
}
+const Pass *Pass::find(const vector<Pass> &passes, const string &name)
+{
+ for (const Pass &pass : passes) {
+ if (pass.name == name) {
+ return &pass;
+ }
+ }
+
+ return nullptr;
+}
+
+const Pass *Pass::find(const vector<Pass> &passes, PassType type)
+{
+ for (const Pass &pass : passes) {
+ if (pass.type == type) {
+ return &pass;
+ }
+ }
+
+ return nullptr;
+}
+
+int Pass::get_offset(const vector<Pass> &passes, PassType type)
+{
+ int pass_offset = 0;
+
+ for (const Pass &pass : passes) {
+ if (pass.type == type) {
+ return pass_offset;
+ }
+ pass_offset += pass.components;
+ }
+
+ return PASS_UNUSED;
+}
+
CCL_NAMESPACE_END
diff --git a/intern/cycles/render/pass.h b/intern/cycles/render/pass.h
index 8bbd4227b0a..6287a6afc8d 100644
--- a/intern/cycles/render/pass.h
+++ b/intern/cycles/render/pass.h
@@ -67,6 +67,13 @@ class Pass : public Node {
/* Remove all passes which were automatically created. */
static void remove_all_auto(vector<Pass> &passes);
+
+ /* Returns nullptr if there is no pass with the given name or type. */
+ static const Pass *find(const vector<Pass> &passes, const string &name);
+ static const Pass *find(const vector<Pass> &passes, PassType type);
+
+ /* Returns PASS_UNUSED if there is no pass with the given type. */
+ static int get_offset(const vector<Pass> &passes, PassType type);
};
CCL_NAMESPACE_END
diff --git a/intern/cycles/render/pass_accessor.cpp b/intern/cycles/render/pass_accessor.cpp
index 9eb1dc0f5c7..75f6985f6b4 100644
--- a/intern/cycles/render/pass_accessor.cpp
+++ b/intern/cycles/render/pass_accessor.cpp
@@ -167,32 +167,18 @@ static float4 shadow_catcher_calc_matte_with_shadow(const float scale,
PassAccessor::PassAccessor(const Film *film,
const vector<Pass> &passes,
- const string &pass_name,
+ const Pass *pass,
int num_components,
float exposure,
int num_samples)
: film_(film),
passes_(passes),
- pass_offset_(PASS_UNUSED),
- pass_(nullptr),
+ pass_offset_(Pass::get_offset(passes, pass->type)),
+ pass_(pass),
num_components_(num_components),
exposure_(exposure),
num_samples_(num_samples)
{
- get_pass_by_name(pass_name, &pass_, &pass_offset_);
-
- /* When shadow catcher is used the combined pass is only used to get proper value for the
- * shadow catcher pass. It is not very useful for artists as it is. What artists expect as a
- * combined pass is something what is to be alpha-overed onto the footage. So we swap the
- * combined pass with shadow catcher matte here. */
- if (pass_ && pass_->type == PASS_COMBINED) {
- get_pass_by_type(PASS_SHADOW_CATCHER_MATTE, &pass_, &pass_offset_);
- }
-}
-
-bool PassAccessor::is_valid() const
-{
- return pass_ != nullptr;
}
bool PassAccessor::get_render_tile_pixels(RenderBuffers *render_buffers, float *pixels)
@@ -526,50 +512,7 @@ bool PassAccessor::set_pass_rect(PassType type, int components, float *pixels, i
int PassAccessor::get_pass_offset(PassType type) const
{
- int pass_offset = 0;
-
- for (const Pass &pass : passes_) {
- if (pass.type == type) {
- return pass_offset;
- }
- pass_offset += pass.components;
- }
-
- return PASS_UNUSED;
-}
-
-bool PassAccessor::get_pass_by_name(const string &name, const Pass **r_pass, int *r_offset) const
-{
- int pass_offset = 0;
- for (const Pass &pass : passes_) {
- /* Pass is identified by both type and name, multiple of the same type may exist with a
- * different name. */
- if (pass.name == name) {
- *r_pass = &pass;
- if (r_offset) {
- *r_offset = pass_offset;
- }
- return true;
- }
- pass_offset += pass.components;
- }
- return false;
-}
-
-bool PassAccessor::get_pass_by_type(const PassType type, const Pass **r_pass, int *r_offset) const
-{
- int pass_offset = 0;
- for (const Pass &pass : passes_) {
- if (pass.type == type) {
- *r_pass = &pass;
- if (r_offset) {
- *r_offset = pass_offset;
- }
- return true;
- }
- pass_offset += pass.components;
- }
- return false;
+ return Pass::get_offset(passes_, type);
}
CCL_NAMESPACE_END
diff --git a/intern/cycles/render/pass_accessor.h b/intern/cycles/render/pass_accessor.h
index 6fc3b99d2ab..2e1eb1b2ac0 100644
--- a/intern/cycles/render/pass_accessor.h
+++ b/intern/cycles/render/pass_accessor.h
@@ -32,13 +32,11 @@ class PassAccessor {
public:
PassAccessor(const Film *film,
const vector<Pass> &passes,
- const string &pass_name,
+ const Pass *pass,
int num_components,
float exposure,
int num_samples);
- bool is_valid() const;
-
/* Get pass data from the given render buffers, perform needed filtering, and store result into
* the pixels.
* The result is stored sequentially starting from the very beginning of the pixels memory. */
@@ -48,12 +46,9 @@ class PassAccessor {
bool set_pass_rect(PassType type, int components, float *pixels);
#endif
+ /* Returns PASS_UNUSED if there is no pass with the given type. */
int get_pass_offset(PassType type) const;
- /* NOTE: Leaves pass and offset unchanged if the pass is not found. */
- bool get_pass_by_name(const string &name, const Pass **r_pass, int *r_offset = nullptr) const;
- bool get_pass_by_type(const PassType type, const Pass **r_pass, int *r_offset = nullptr) const;
-
protected:
const Film *film_;
diff --git a/intern/cycles/render/session.cpp b/intern/cycles/render/session.cpp
index 9501f99b1b3..e5a5f554385 100644
--- a/intern/cycles/render/session.cpp
+++ b/intern/cycles/render/session.cpp
@@ -557,17 +557,39 @@ int2 Session::get_render_tile_offset() const
return make_int2(tile.x - tile.full_x, tile.y - tile.full_y);
}
+static const Pass *get_actual_pass_for_pixels(const vector<Pass> &passes, const string &pass_name)
+{
+ const Pass *pass = Pass::find(passes, pass_name);
+ if (!pass) {
+ return nullptr;
+ }
+
+ /* When shadow catcher is used the combined pass is only used to get proper value for the
+ * shadow catcher pass. It is not very useful for artists as it is. What artists expect as a
+ * combined pass is something what is to be alpha-overed onto the footage. So we swap the
+ * combined pass with shadow catcher matte here. */
+ if (pass->type == PASS_COMBINED) {
+ const Pass *matte_pass = Pass::find(passes, PASS_SHADOW_CATCHER_MATTE);
+ if (matte_pass) {
+ return matte_pass;
+ }
+ }
+
+ return pass;
+}
+
bool Session::get_render_tile_pixels(const string &pass_name, int num_components, float *pixels)
{
+ const Pass *pass = get_actual_pass_for_pixels(scene->passes, pass_name);
+ if (!pass) {
+ return false;
+ }
+
const float exposure = scene->film->get_exposure();
const int num_samples = render_scheduler_.get_num_rendered_samples();
PassAccessor pass_accessor(
- scene->film, scene->passes, pass_name, num_components, exposure, num_samples);
-
- if (!pass_accessor.is_valid()) {
- return false;
- }
+ scene->film, scene->passes, pass, num_components, exposure, num_samples);
return path_trace_->get_render_tile_pixels(pass_accessor, pixels);
}
More information about the Bf-blender-cvs
mailing list