2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2013-09-05 09:39:38 +00:00
|
|
|
|
|
|
|
|
#include "COM_RenderLayersProg.h"
|
|
|
|
|
|
ImBuf: Refactor pixel interpolation functions
There exist a bunch of "give me a (filtered) image pixel at this location"
functions, some with duplicated functionality, some with almost the same but
not quite, some that look similar but behave slightly differently, etc.
Some of them were in BLI, some were in ImBuf.
This commit tries to improve the situation by:
* Adding low level interpolation functions to `BLI_math_interp.hh`
- With documentation on their behavior,
- And with more unit tests.
* At `ImBuf` level, there are only convenience inline wrappers to the above BLI
functions (split off into a separate header `IMB_interp.hh`). However, since
these wrappers are inline, some things get a tiny bit faster as a side
effect. E.g. VSE image strip, scaling to 4K resolution (Windows/Ryzen5950X):
- Nearest filter: 2.33 -> 1.94ms
- Bilinear filter: 5.83 -> 5.69ms
- Subsampled3x3 filter: 28.6 -> 22.4ms
Details on the functions:
- All of them have `_byte` and `_fl` suffixes.
- They exist in 4-channel byte (uchar4) and float (float4), as well as
explicitly passed amount of channels for other float images.
- New functions in BLI `blender::math` namespace:
- `interpolate_nearest`
- `interpolate_bilinear`
- `interpolate_bilinear_wrap`. Note that unlike previous "wrap" function,
this one no longer requires the caller to do their own wrapping.
- `interpolate_cubic_bspline`. Previous similar function was called just
"bicubic" which could mean many different things.
- Same functions exist in `IMB_interp.hh`, they are just convenience that takes
ImBuf and uses data pointer, width, height from that.
Other bits:
- Renamed `mod_f_positive` to `floored_fmod` (better matches `safe_floored_modf`
and `floored_modulo` that exist elsewhere), made it branchless and added more
unit tests.
- `interpolate_bilinear_wrap_fl` no longer clamps result to 0..1 range. Instead,
moved the clamp to be outside of the call in `paint_image_proj.cc` and
`paint_utils.cc`. Though the need for clamping in there is also questionable.
Pull Request: https://projects.blender.org/blender/blender/pulls/117387
2024-01-25 11:45:24 +01:00
|
|
|
#include "BLI_math_interp.hh"
|
2023-09-01 21:37:11 +02:00
|
|
|
#include "BLI_string.h"
|
|
|
|
|
|
2021-01-12 16:19:54 +01:00
|
|
|
#include "BKE_image.h"
|
2013-09-05 09:39:38 +00:00
|
|
|
|
2021-03-23 17:12:27 +01:00
|
|
|
namespace blender::compositor {
|
|
|
|
|
|
2013-09-05 09:39:38 +00:00
|
|
|
/* ******** Render Layers Base Prog ******** */
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
RenderLayersProg::RenderLayersProg(const char *pass_name, DataType type, int elementsize)
|
|
|
|
|
: pass_name_(pass_name)
|
2013-09-05 09:39:38 +00:00
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
this->set_scene(nullptr);
|
|
|
|
|
input_buffer_ = nullptr;
|
2021-10-13 23:01:04 +02:00
|
|
|
elementsize_ = elementsize;
|
|
|
|
|
rd_ = nullptr;
|
2021-07-13 21:48:42 +02:00
|
|
|
layer_buffer_ = nullptr;
|
Render API/Cycles: Identify Render Passes by their name instead of a type flag
Previously, every RenderPass would have a bitfield that specified its type. That limits the number of passes to 32, which was reached a while ago.
However, most of the code already supported arbitrary RenderPasses since they were also used to store Multilayer EXR images.
Therefore, this commit completely removes the passflag from RenderPass and changes all code to use the unique pass name for identification.
Since Blender Internal relies on hardcoded passes and to preserve compatibility, 32 pass names are reserved for the old hardcoded passes.
To support these arbitrary passes, the Render Result compositor node now adds dynamic sockets. For compatibility, the old hardcoded sockets are always stored and just hidden when the corresponding pass isn't available.
To use these changes, the Render Engine API now includes a function that allows render engines to add arbitrary passes to the render result. To be able to add options for these passes, addons can now add their own properties to SceneRenderLayers.
To keep the compositor input node updated, render engine plugins have to implement a callback that registers all the passes that will be generated.
From a user perspective, nothing should change with this commit.
Differential Revision: https://developer.blender.org/D2443
Differential Revision: https://developer.blender.org/D2444
2017-05-03 00:21:18 +02:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
this->add_output_socket(type);
|
2013-09-05 09:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
void RenderLayersProg::init_execution()
|
2013-09-05 09:39:38 +00:00
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
Scene *scene = this->get_scene();
|
2020-11-06 17:49:09 +01:00
|
|
|
Render *re = (scene) ? RE_GetSceneRender(scene) : nullptr;
|
|
|
|
|
RenderResult *rr = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-23 11:21:22 +10:00
|
|
|
if (re) {
|
2013-09-05 09:39:38 +00:00
|
|
|
rr = RE_AcquireResultRead(re);
|
2019-04-23 11:21:22 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-09-05 09:39:38 +00:00
|
|
|
if (rr) {
|
2021-10-13 23:01:15 +02:00
|
|
|
ViewLayer *view_layer = (ViewLayer *)BLI_findlink(&scene->view_layers, get_layer_id());
|
2017-11-22 10:52:39 -02:00
|
|
|
if (view_layer) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-22 10:52:39 -02:00
|
|
|
RenderLayer *rl = RE_GetRenderLayer(rr, view_layer->name);
|
2015-04-06 10:40:12 -03:00
|
|
|
if (rl) {
|
2021-10-13 23:01:15 +02:00
|
|
|
input_buffer_ = RE_RenderLayerGetPass(rl, pass_name_.c_str(), view_name_);
|
|
|
|
|
if (input_buffer_) {
|
|
|
|
|
layer_buffer_ = new MemoryBuffer(input_buffer_, elementsize_, get_width(), get_height());
|
2021-07-13 21:48:42 +02:00
|
|
|
}
|
2013-09-05 09:39:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (re) {
|
|
|
|
|
RE_ReleaseResult(re);
|
2020-11-06 17:49:09 +01:00
|
|
|
re = nullptr;
|
2013-09-05 09:39:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
void RenderLayersProg::deinit_execution()
|
2013-09-05 09:39:38 +00:00
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
input_buffer_ = nullptr;
|
2021-07-13 21:48:42 +02:00
|
|
|
if (layer_buffer_) {
|
|
|
|
|
delete layer_buffer_;
|
|
|
|
|
layer_buffer_ = nullptr;
|
|
|
|
|
}
|
2013-09-05 09:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
2022-10-03 17:37:25 -05:00
|
|
|
void RenderLayersProg::determine_canvas(const rcti & /*preferred_area*/, rcti &r_area)
|
2013-09-05 09:39:38 +00:00
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
Scene *sce = this->get_scene();
|
2020-11-06 17:49:09 +01:00
|
|
|
Render *re = (sce) ? RE_GetSceneRender(sce) : nullptr;
|
|
|
|
|
RenderResult *rr = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-09-28 19:32:49 +02:00
|
|
|
r_area = COM_AREA_NONE;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-23 11:21:22 +10:00
|
|
|
if (re) {
|
2013-09-05 09:39:38 +00:00
|
|
|
rr = RE_AcquireResultRead(re);
|
2019-04-23 11:21:22 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-09-05 09:39:38 +00:00
|
|
|
if (rr) {
|
2021-10-13 23:01:15 +02:00
|
|
|
ViewLayer *view_layer = (ViewLayer *)BLI_findlink(&sce->view_layers, get_layer_id());
|
2017-11-22 10:52:39 -02:00
|
|
|
if (view_layer) {
|
|
|
|
|
RenderLayer *rl = RE_GetRenderLayer(rr, view_layer->name);
|
2015-04-06 10:40:12 -03:00
|
|
|
if (rl) {
|
2021-09-28 19:32:49 +02:00
|
|
|
BLI_rcti_init(&r_area, 0, rl->rectx, 0, rl->recty);
|
2013-09-05 09:39:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-23 11:21:22 +10:00
|
|
|
if (re) {
|
2013-09-05 09:39:38 +00:00
|
|
|
RE_ReleaseResult(re);
|
2019-04-23 11:21:22 +10:00
|
|
|
}
|
2013-09-05 09:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
std::unique_ptr<MetaData> RenderLayersProg::get_meta_data()
|
2021-01-12 16:19:54 +01:00
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
Scene *scene = this->get_scene();
|
2021-01-12 16:19:54 +01:00
|
|
|
Render *re = (scene) ? RE_GetSceneRender(scene) : nullptr;
|
2021-03-02 11:08:04 +01:00
|
|
|
RenderResult *render_result = nullptr;
|
|
|
|
|
MetaDataExtractCallbackData callback_data = {nullptr};
|
2021-01-12 16:19:54 +01:00
|
|
|
|
|
|
|
|
if (re) {
|
2021-03-02 11:08:04 +01:00
|
|
|
render_result = RE_AcquireResultRead(re);
|
2021-01-12 16:19:54 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-02 11:08:04 +01:00
|
|
|
if (render_result && render_result->stamp_data) {
|
2021-10-13 23:01:15 +02:00
|
|
|
ViewLayer *view_layer = (ViewLayer *)BLI_findlink(&scene->view_layers, get_layer_id());
|
2021-01-12 16:19:54 +01:00
|
|
|
if (view_layer) {
|
|
|
|
|
std::string full_layer_name = std::string(
|
|
|
|
|
view_layer->name,
|
|
|
|
|
BLI_strnlen(view_layer->name, sizeof(view_layer->name))) +
|
2021-10-13 23:01:15 +02:00
|
|
|
"." + pass_name_;
|
2021-03-03 12:14:06 +01:00
|
|
|
blender::StringRef cryptomatte_layer_name =
|
|
|
|
|
blender::bke::cryptomatte::BKE_cryptomatte_extract_layer_name(full_layer_name);
|
2021-10-13 23:01:15 +02:00
|
|
|
callback_data.set_cryptomatte_keys(cryptomatte_layer_name);
|
2021-01-12 16:19:54 +01:00
|
|
|
|
2021-03-02 11:08:04 +01:00
|
|
|
BKE_stamp_info_callback(&callback_data,
|
|
|
|
|
render_result->stamp_data,
|
|
|
|
|
MetaDataExtractCallbackData::extract_cryptomatte_meta_data,
|
|
|
|
|
false);
|
2021-01-12 16:19:54 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (re) {
|
|
|
|
|
RE_ReleaseResult(re);
|
|
|
|
|
re = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return std::move(callback_data.meta_data);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-13 21:48:42 +02:00
|
|
|
void RenderLayersProg::update_memory_buffer_partial(MemoryBuffer *output,
|
|
|
|
|
const rcti &area,
|
2022-10-03 17:37:25 -05:00
|
|
|
Span<MemoryBuffer *> /*inputs*/)
|
2021-07-13 21:48:42 +02:00
|
|
|
{
|
2021-10-13 23:01:04 +02:00
|
|
|
BLI_assert(output->get_num_channels() >= elementsize_);
|
2021-07-13 21:48:42 +02:00
|
|
|
if (layer_buffer_) {
|
2021-10-13 23:01:04 +02:00
|
|
|
output->copy_from(layer_buffer_, area, 0, elementsize_, 0);
|
2021-07-13 21:48:42 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2021-10-13 23:01:04 +02:00
|
|
|
std::unique_ptr<float[]> zero_elem = std::make_unique<float[]>(elementsize_);
|
|
|
|
|
output->fill(area, 0, zero_elem.get(), elementsize_);
|
2021-07-13 21:48:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-05 09:39:38 +00:00
|
|
|
/* ******** Render Layers AO Operation ******** */
|
2021-12-09 20:01:49 +11:00
|
|
|
|
2021-07-13 21:48:42 +02:00
|
|
|
void RenderLayersAOOperation::update_memory_buffer_partial(MemoryBuffer *output,
|
|
|
|
|
const rcti &area,
|
2022-10-03 17:37:25 -05:00
|
|
|
Span<MemoryBuffer *> /*inputs*/)
|
2021-07-13 21:48:42 +02:00
|
|
|
{
|
|
|
|
|
BLI_assert(output->get_num_channels() == COM_DATA_TYPE_COLOR_CHANNELS);
|
2021-10-13 23:01:04 +02:00
|
|
|
BLI_assert(elementsize_ == COM_DATA_TYPE_COLOR_CHANNELS);
|
2021-07-13 21:48:42 +02:00
|
|
|
if (layer_buffer_) {
|
|
|
|
|
output->copy_from(layer_buffer_, area, 0, COM_DATA_TYPE_VECTOR_CHANNELS, 0);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
output->fill(area, 0, COM_VECTOR_ZERO, COM_DATA_TYPE_VECTOR_CHANNELS);
|
|
|
|
|
}
|
|
|
|
|
output->fill(area, 3, COM_VALUE_ONE, COM_DATA_TYPE_VALUE_CHANNELS);
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-05 09:39:38 +00:00
|
|
|
/* ******** Render Layers Alpha Operation ******** */
|
2021-12-09 20:01:49 +11:00
|
|
|
|
2021-07-13 21:48:42 +02:00
|
|
|
void RenderLayersAlphaProg::update_memory_buffer_partial(MemoryBuffer *output,
|
|
|
|
|
const rcti &area,
|
2022-10-03 17:37:25 -05:00
|
|
|
Span<MemoryBuffer *> /*inputs*/)
|
2021-07-13 21:48:42 +02:00
|
|
|
{
|
|
|
|
|
BLI_assert(output->get_num_channels() == COM_DATA_TYPE_VALUE_CHANNELS);
|
2021-10-13 23:01:04 +02:00
|
|
|
BLI_assert(elementsize_ == COM_DATA_TYPE_COLOR_CHANNELS);
|
2021-07-13 21:48:42 +02:00
|
|
|
if (layer_buffer_) {
|
|
|
|
|
output->copy_from(layer_buffer_, area, 3, COM_DATA_TYPE_VALUE_CHANNELS, 0);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
output->fill(area, COM_VALUE_ZERO);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-05 09:39:38 +00:00
|
|
|
/* ******** Render Layers Depth Operation ******** */
|
2021-12-09 20:01:49 +11:00
|
|
|
|
2021-07-13 21:48:42 +02:00
|
|
|
void RenderLayersDepthProg::update_memory_buffer_partial(MemoryBuffer *output,
|
|
|
|
|
const rcti &area,
|
2022-10-03 17:37:25 -05:00
|
|
|
Span<MemoryBuffer *> /*inputs*/)
|
2021-07-13 21:48:42 +02:00
|
|
|
{
|
|
|
|
|
BLI_assert(output->get_num_channels() == COM_DATA_TYPE_VALUE_CHANNELS);
|
2021-10-13 23:01:04 +02:00
|
|
|
BLI_assert(elementsize_ == COM_DATA_TYPE_VALUE_CHANNELS);
|
2021-07-13 21:48:42 +02:00
|
|
|
if (layer_buffer_) {
|
|
|
|
|
output->copy_from(layer_buffer_, area);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
const float default_depth = 10e10f;
|
|
|
|
|
output->fill(area, &default_depth);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-23 17:12:27 +01:00
|
|
|
} // namespace blender::compositor
|