Files
test/source/blender/compositor/operations/COM_RenderLayersProg.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

352 lines
9.9 KiB
C++
Raw Normal View History

/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2011 Blender Foundation. */
#include "COM_RenderLayersProg.h"
#include "BKE_image.h"
2021-03-23 17:12:27 +01:00
namespace blender::compositor {
/* ******** Render Layers Base Prog ******** */
RenderLayersProg::RenderLayersProg(const char *pass_name, DataType type, int elementsize)
: pass_name_(pass_name)
{
this->set_scene(nullptr);
input_buffer_ = nullptr;
elementsize_ = elementsize;
rd_ = nullptr;
layer_buffer_ = nullptr;
this->add_output_socket(type);
}
void RenderLayersProg::init_execution()
{
Scene *scene = this->get_scene();
Render *re = (scene) ? RE_GetSceneRender(scene) : nullptr;
RenderResult *rr = nullptr;
if (re) {
rr = RE_AcquireResultRead(re);
}
if (rr) {
ViewLayer *view_layer = (ViewLayer *)BLI_findlink(&scene->view_layers, get_layer_id());
if (view_layer) {
RenderLayer *rl = RE_GetRenderLayer(rr, view_layer->name);
Multi-View and Stereo 3D Official Documentation: http://www.blender.org/manual/render/workflows/multiview.html Implemented Features ==================== Builtin Stereo Camera * Convergence Mode * Interocular Distance * Convergence Distance * Pivot Mode Viewport * Cameras * Plane * Volume Compositor * View Switch Node * Image Node Multi-View OpenEXR support Sequencer * Image/Movie Strips 'Use Multiview' UV/Image Editor * Option to see Multi-View images in Stereo-3D or its individual images * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images I/O * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images Scene Render Views * Ability to have an arbitrary number of views in the scene Missing Bits ============ First rule of Multi-View bug report: If something is not working as it should *when Views is off* this is a severe bug, do mention this in the report. Second rule is, if something works *when Views is off* but doesn't (or crashes) when *Views is on*, this is a important bug. Do mention this in the report. Everything else is likely small todos, and may wait until we are sure none of the above is happening. Apart from that there are those known issues: * Compositor Image Node poorly working for Multi-View OpenEXR (this was working prefectly before the 'Use Multi-View' functionality) * Selecting camera from Multi-View when looking from camera is problematic * Animation Playback (ctrl+F11) doesn't support stereo formats * Wrong filepath when trying to play back animated scene * Viewport Rendering doesn't support Multi-View * Overscan Rendering * Fullscreen display modes need to warn the user * Object copy should be aware of views suffix Acknowledgments =============== * Francesco Siddi for the help with the original feature specs and design * Brecht Van Lommel for the original review of the code and design early on * Blender Foundation for the Development Fund to support the project wrap up Final patch reviewers: * Antony Riakiotakis (psy-fi) * Campbell Barton (ideasman42) * Julian Eisel (Severin) * Sergey Sharybin (nazgul) * Thomas Dinged (dingto) Code contributors of the original branch in github: * Alexey Akishin * Gabriel Caraballo
2015-04-06 10:40:12 -03:00
if (rl) {
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());
}
}
}
}
if (re) {
RE_ReleaseResult(re);
re = nullptr;
}
}
void RenderLayersProg::do_interpolation(float output[4], float x, float y, PixelSampler sampler)
{
unsigned int offset;
int width = this->get_width(), height = this->get_height();
int ix = x, iy = y;
if (ix < 0 || iy < 0 || ix >= width || iy >= height) {
if (elementsize_ == 1) {
output[0] = 0.0f;
}
else if (elementsize_ == 3) {
zero_v3(output);
}
else {
zero_v4(output);
}
return;
}
switch (sampler) {
case PixelSampler::Nearest: {
offset = (iy * width + ix) * elementsize_;
if (elementsize_ == 1) {
output[0] = input_buffer_[offset];
}
else if (elementsize_ == 3) {
copy_v3_v3(output, &input_buffer_[offset]);
}
else {
copy_v4_v4(output, &input_buffer_[offset]);
}
break;
}
case PixelSampler::Bilinear:
BLI_bilinear_interpolation_fl(input_buffer_, output, width, height, elementsize_, x, y);
break;
case PixelSampler::Bicubic:
BLI_bicubic_interpolation_fl(input_buffer_, output, width, height, elementsize_, x, y);
break;
}
}
void RenderLayersProg::execute_pixel_sampled(float output[4],
float x,
float y,
PixelSampler sampler)
{
#if 0
const RenderData *rd = rd_;
int dx = 0, dy = 0;
if (rd->mode & R_BORDER && rd->mode & R_CROP) {
/* see comment in execute_region describing coordinate mapping,
* here it simply goes other way around
*/
int full_width = rd->xsch * rd->size / 100;
int full_height = rd->ysch * rd->size / 100;
dx = rd->border.xmin * full_width - (full_width - this->get_width()) / 2.0f;
dy = rd->border.ymin * full_height - (full_height - this->get_height()) / 2.0f;
}
int ix = x - dx;
int iy = y - dy;
#endif
#ifndef NDEBUG
{
const DataType data_type = this->get_output_socket()->get_data_type();
int actual_element_size = elementsize_;
int expected_element_size;
2021-03-19 14:26:24 +01:00
if (data_type == DataType::Value) {
expected_element_size = 1;
}
2021-03-19 14:26:24 +01:00
else if (data_type == DataType::Vector) {
expected_element_size = 3;
}
2021-03-19 14:26:24 +01:00
else if (data_type == DataType::Color) {
expected_element_size = 4;
}
else {
2015-08-12 22:17:27 +02:00
expected_element_size = 0;
BLI_assert_msg(0, "Something horribly wrong just happened");
}
BLI_assert(expected_element_size == actual_element_size);
}
#endif
if (input_buffer_ == nullptr) {
int elemsize = elementsize_;
if (elemsize == 1) {
output[0] = 0.0f;
}
else if (elemsize == 3) {
zero_v3(output);
2015-01-24 01:59:09 +11:00
}
else {
BLI_assert(elemsize == 4);
zero_v4(output);
}
}
else {
do_interpolation(output, x, y, sampler);
}
}
void RenderLayersProg::deinit_execution()
{
input_buffer_ = nullptr;
if (layer_buffer_) {
delete layer_buffer_;
layer_buffer_ = nullptr;
}
}
void RenderLayersProg::determine_canvas(const rcti &UNUSED(preferred_area), rcti &r_area)
{
Scene *sce = this->get_scene();
Render *re = (sce) ? RE_GetSceneRender(sce) : nullptr;
RenderResult *rr = nullptr;
r_area = COM_AREA_NONE;
if (re) {
rr = RE_AcquireResultRead(re);
}
if (rr) {
ViewLayer *view_layer = (ViewLayer *)BLI_findlink(&sce->view_layers, get_layer_id());
if (view_layer) {
RenderLayer *rl = RE_GetRenderLayer(rr, view_layer->name);
Multi-View and Stereo 3D Official Documentation: http://www.blender.org/manual/render/workflows/multiview.html Implemented Features ==================== Builtin Stereo Camera * Convergence Mode * Interocular Distance * Convergence Distance * Pivot Mode Viewport * Cameras * Plane * Volume Compositor * View Switch Node * Image Node Multi-View OpenEXR support Sequencer * Image/Movie Strips 'Use Multiview' UV/Image Editor * Option to see Multi-View images in Stereo-3D or its individual images * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images I/O * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images Scene Render Views * Ability to have an arbitrary number of views in the scene Missing Bits ============ First rule of Multi-View bug report: If something is not working as it should *when Views is off* this is a severe bug, do mention this in the report. Second rule is, if something works *when Views is off* but doesn't (or crashes) when *Views is on*, this is a important bug. Do mention this in the report. Everything else is likely small todos, and may wait until we are sure none of the above is happening. Apart from that there are those known issues: * Compositor Image Node poorly working for Multi-View OpenEXR (this was working prefectly before the 'Use Multi-View' functionality) * Selecting camera from Multi-View when looking from camera is problematic * Animation Playback (ctrl+F11) doesn't support stereo formats * Wrong filepath when trying to play back animated scene * Viewport Rendering doesn't support Multi-View * Overscan Rendering * Fullscreen display modes need to warn the user * Object copy should be aware of views suffix Acknowledgments =============== * Francesco Siddi for the help with the original feature specs and design * Brecht Van Lommel for the original review of the code and design early on * Blender Foundation for the Development Fund to support the project wrap up Final patch reviewers: * Antony Riakiotakis (psy-fi) * Campbell Barton (ideasman42) * Julian Eisel (Severin) * Sergey Sharybin (nazgul) * Thomas Dinged (dingto) Code contributors of the original branch in github: * Alexey Akishin * Gabriel Caraballo
2015-04-06 10:40:12 -03:00
if (rl) {
BLI_rcti_init(&r_area, 0, rl->rectx, 0, rl->recty);
}
}
}
if (re) {
RE_ReleaseResult(re);
}
}
std::unique_ptr<MetaData> RenderLayersProg::get_meta_data()
{
Scene *scene = this->get_scene();
Render *re = (scene) ? RE_GetSceneRender(scene) : nullptr;
RenderResult *render_result = nullptr;
MetaDataExtractCallbackData callback_data = {nullptr};
if (re) {
render_result = RE_AcquireResultRead(re);
}
if (render_result && render_result->stamp_data) {
ViewLayer *view_layer = (ViewLayer *)BLI_findlink(&scene->view_layers, get_layer_id());
if (view_layer) {
std::string full_layer_name = std::string(
view_layer->name,
BLI_strnlen(view_layer->name, sizeof(view_layer->name))) +
"." + 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);
callback_data.set_cryptomatte_keys(cryptomatte_layer_name);
BKE_stamp_info_callback(&callback_data,
render_result->stamp_data,
MetaDataExtractCallbackData::extract_cryptomatte_meta_data,
false);
}
}
if (re) {
RE_ReleaseResult(re);
re = nullptr;
}
return std::move(callback_data.meta_data);
}
void RenderLayersProg::update_memory_buffer_partial(MemoryBuffer *output,
const rcti &area,
Span<MemoryBuffer *> UNUSED(inputs))
{
BLI_assert(output->get_num_channels() >= elementsize_);
if (layer_buffer_) {
output->copy_from(layer_buffer_, area, 0, elementsize_, 0);
}
else {
std::unique_ptr<float[]> zero_elem = std::make_unique<float[]>(elementsize_);
output->fill(area, 0, zero_elem.get(), elementsize_);
}
}
/* ******** Render Layers AO Operation ******** */
void RenderLayersAOOperation::execute_pixel_sampled(float output[4],
float x,
float y,
PixelSampler sampler)
{
float *input_buffer = this->get_input_buffer();
if (input_buffer == nullptr) {
zero_v3(output);
}
else {
do_interpolation(output, x, y, sampler);
}
output[3] = 1.0f;
}
void RenderLayersAOOperation::update_memory_buffer_partial(MemoryBuffer *output,
const rcti &area,
Span<MemoryBuffer *> UNUSED(inputs))
{
BLI_assert(output->get_num_channels() == COM_DATA_TYPE_COLOR_CHANNELS);
BLI_assert(elementsize_ == COM_DATA_TYPE_COLOR_CHANNELS);
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);
}
/* ******** Render Layers Alpha Operation ******** */
void RenderLayersAlphaProg::execute_pixel_sampled(float output[4],
float x,
float y,
PixelSampler sampler)
{
float *input_buffer = this->get_input_buffer();
if (input_buffer == nullptr) {
output[0] = 0.0f;
}
else {
float temp[4];
do_interpolation(temp, x, y, sampler);
output[0] = temp[3];
}
}
void RenderLayersAlphaProg::update_memory_buffer_partial(MemoryBuffer *output,
const rcti &area,
Span<MemoryBuffer *> UNUSED(inputs))
{
BLI_assert(output->get_num_channels() == COM_DATA_TYPE_VALUE_CHANNELS);
BLI_assert(elementsize_ == COM_DATA_TYPE_COLOR_CHANNELS);
if (layer_buffer_) {
output->copy_from(layer_buffer_, area, 3, COM_DATA_TYPE_VALUE_CHANNELS, 0);
}
else {
output->fill(area, COM_VALUE_ZERO);
}
}
/* ******** Render Layers Depth Operation ******** */
void RenderLayersDepthProg::execute_pixel_sampled(float output[4],
float x,
float y,
PixelSampler /*sampler*/)
{
int ix = x;
int iy = y;
float *input_buffer = this->get_input_buffer();
if (input_buffer == nullptr || ix < 0 || iy < 0 || ix >= (int)this->get_width() ||
iy >= (int)this->get_height()) {
output[0] = 10e10f;
}
else {
unsigned int offset = (iy * this->get_width() + ix);
output[0] = input_buffer[offset];
}
}
2021-03-23 17:12:27 +01:00
void RenderLayersDepthProg::update_memory_buffer_partial(MemoryBuffer *output,
const rcti &area,
Span<MemoryBuffer *> UNUSED(inputs))
{
BLI_assert(output->get_num_channels() == COM_DATA_TYPE_VALUE_CHANNELS);
BLI_assert(elementsize_ == COM_DATA_TYPE_VALUE_CHANNELS);
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