This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/compositor/nodes/COM_ImageNode.cpp
Dalai Felinto d5f1b9c222 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

274 lines
9.6 KiB
C++

/*
* Copyright 2011, Blender Foundation.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor:
* Jeroen Bakker
* Monique Dewanchand
* Lukas Tönne
*/
#include "COM_ImageNode.h"
#include "COM_ExecutionSystem.h"
#include "COM_ImageOperation.h"
#include "COM_MultilayerImageOperation.h"
#include "COM_ConvertOperation.h"
#include "BKE_node.h"
#include "BLI_utildefines.h"
#include "COM_SetValueOperation.h"
#include "COM_SetVectorOperation.h"
#include "COM_SetColorOperation.h"
#include "COM_SeparateColorNode.h"
ImageNode::ImageNode(bNode *editorNode) : Node(editorNode)
{
/* pass */
}
NodeOperation *ImageNode::doMultilayerCheck(NodeConverter &converter, RenderLayer *rl, Image *image, ImageUser *user,
int framenumber, int outputsocketIndex, int passtype, int view, DataType datatype) const
{
NodeOutput *outputSocket = this->getOutputSocket(outputsocketIndex);
MultilayerBaseOperation *operation = NULL;
switch (datatype) {
case COM_DT_VALUE:
operation = new MultilayerValueOperation(passtype, view);
break;
case COM_DT_VECTOR:
operation = new MultilayerVectorOperation(passtype, view);
break;
case COM_DT_COLOR:
operation = new MultilayerColorOperation(passtype, view);
break;
default:
break;
}
operation->setImage(image);
operation->setRenderLayer(rl);
operation->setImageUser(user);
operation->setFramenumber(framenumber);
converter.addOperation(operation);
converter.mapOutputSocket(outputSocket, operation->getOutputSocket());
return operation;
}
void ImageNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const
{
/// Image output
NodeOutput *outputImage = this->getOutputSocket(0);
bNode *editorNode = this->getbNode();
Image *image = (Image *)editorNode->id;
ImageUser *imageuser = (ImageUser *)editorNode->storage;
int framenumber = context.getFramenumber();
int numberOfOutputs = this->getNumberOfOutputSockets();
bool outputStraightAlpha = (editorNode->custom1 & CMP_NODE_IMAGE_USE_STRAIGHT_OUTPUT) != 0;
BKE_image_user_frame_calc(imageuser, context.getFramenumber(), 0);
NodeOperation *combined_operation = NULL;
/* force a load, we assume iuser index will be set OK anyway */
if (image && image->type == IMA_TYPE_MULTILAYER) {
bool is_multilayer_ok = false;
ImBuf *ibuf = BKE_image_acquire_ibuf(image, imageuser, NULL);
if (image->rr) {
RenderLayer *rl = (RenderLayer *)BLI_findlink(&image->rr->layers, imageuser->layer);
if (rl) {
NodeOutput *socket;
int index;
is_multilayer_ok = true;
for (index = 0; index < numberOfOutputs; index++) {
NodeOperation *operation = NULL;
socket = this->getOutputSocket(index);
bNodeSocket *bnodeSocket = socket->getbNodeSocket();
RenderPass *rpass = (RenderPass *)BLI_findstring(&rl->passes, bnodeSocket->identifier, offsetof(RenderPass, internal_name));
int view = (rpass ? rpass->view_id : 0);
/* Passes in the file can differ from passes stored in sockets (#36755).
* Look up the correct file pass using the socket identifier instead.
*/
#if 0
NodeImageLayer *storage = (NodeImageLayer *)bnodeSocket->storage;*/
int passindex = storage->pass_index;*/
RenderPass *rpass = (RenderPass *)BLI_findlink(&rl->passes, passindex);
#endif
/* returns the image view to use for the current active view */
if (BLI_listbase_count_ex(&image->rr->views, 2) > 1) {
const int view_image = imageuser->view;
const bool is_allview = (view_image == 0); /* if view selected == All (0) */
if (is_allview) {
/* heuristic to match image name with scene names
* check if the view name exists in the image */
view = BLI_findstringindex(&image->rr->views, context.getViewName(), offsetof(RenderView, name));
}
else {
view = view_image - 1;
}
}
if (STREQ(bnodeSocket->identifier, "Alpha")) {
BLI_assert(combined_operation != NULL);
NodeOutput *outputSocket = this->getOutputSocket(index);
SeparateChannelOperation *separate_operation;
separate_operation = new SeparateChannelOperation();
separate_operation->setChannel(3);
converter.addOperation(separate_operation);
converter.addLink(combined_operation->getOutputSocket(), separate_operation->getInputSocket(0));
converter.mapOutputSocket(outputSocket, separate_operation->getOutputSocket());
operation = separate_operation;
}
else {
if (rpass) {
switch (rpass->channels) {
case 1:
operation = doMultilayerCheck(converter, rl, image, imageuser, framenumber, index,
rpass->passtype, view, COM_DT_VALUE);
break;
/* using image operations for both 3 and 4 channels (RGB and RGBA respectively) */
/* XXX any way to detect actual vector images? */
case 3:
operation = doMultilayerCheck(converter, rl, image, imageuser, framenumber, index,
rpass->passtype, view, COM_DT_VECTOR);
break;
case 4:
operation = doMultilayerCheck(converter, rl, image, imageuser, framenumber, index,
rpass->passtype, view, COM_DT_COLOR);
break;
default:
/* dummy operation is added below */
break;
}
if (index == 0 && operation) {
converter.addPreview(operation->getOutputSocket());
}
if (STREQ(rpass->chan_id, "RGBA")) {
combined_operation = operation;
}
}
}
/* incase we can't load the layer */
if (operation == NULL)
converter.setInvalidOutput(getOutputSocket(index));
}
}
}
BKE_image_release_ibuf(image, ibuf, NULL);
/* without this, multilayer that fail to load will crash blender [#32490] */
if (is_multilayer_ok == false) {
for (int i = 0; i < getNumberOfOutputSockets(); ++i)
converter.setInvalidOutput(getOutputSocket(i));
}
}
else {
if (numberOfOutputs > 0) {
ImageOperation *operation = new ImageOperation();
operation->setImage(image);
operation->setImageUser(imageuser);
operation->setFramenumber(framenumber);
operation->setRenderData(context.getRenderData());
operation->setViewName(context.getViewName());
converter.addOperation(operation);
if (outputStraightAlpha) {
NodeOperation *alphaConvertOperation = new ConvertPremulToStraightOperation();
converter.addOperation(alphaConvertOperation);
converter.mapOutputSocket(outputImage, alphaConvertOperation->getOutputSocket());
converter.addLink(operation->getOutputSocket(0), alphaConvertOperation->getInputSocket(0));
}
else {
converter.mapOutputSocket(outputImage, operation->getOutputSocket());
}
converter.addPreview(operation->getOutputSocket());
}
if (numberOfOutputs > 1) {
NodeOutput *alphaImage = this->getOutputSocket(1);
ImageAlphaOperation *alphaOperation = new ImageAlphaOperation();
alphaOperation->setImage(image);
alphaOperation->setImageUser(imageuser);
alphaOperation->setFramenumber(framenumber);
alphaOperation->setRenderData(context.getRenderData());
alphaOperation->setViewName(context.getViewName());
converter.addOperation(alphaOperation);
converter.mapOutputSocket(alphaImage, alphaOperation->getOutputSocket());
}
if (numberOfOutputs > 2) {
NodeOutput *depthImage = this->getOutputSocket(2);
ImageDepthOperation *depthOperation = new ImageDepthOperation();
depthOperation->setImage(image);
depthOperation->setImageUser(imageuser);
depthOperation->setFramenumber(framenumber);
depthOperation->setRenderData(context.getRenderData());
depthOperation->setViewName(context.getViewName());
converter.addOperation(depthOperation);
converter.mapOutputSocket(depthImage, depthOperation->getOutputSocket());
}
if (numberOfOutputs > 3) {
/* happens when unlinking image datablock from multilayer node */
for (int i = 3; i < numberOfOutputs; i++) {
NodeOutput *output = this->getOutputSocket(i);
NodeOperation *operation = NULL;
switch (output->getDataType()) {
case COM_DT_VALUE:
{
SetValueOperation *valueoperation = new SetValueOperation();
valueoperation->setValue(0.0f);
operation = valueoperation;
break;
}
case COM_DT_VECTOR:
{
SetVectorOperation *vectoroperation = new SetVectorOperation();
vectoroperation->setX(0.0f);
vectoroperation->setY(0.0f);
vectoroperation->setW(0.0f);
operation = vectoroperation;
break;
}
case COM_DT_COLOR:
{
SetColorOperation *coloroperation = new SetColorOperation();
coloroperation->setChannel1(0.0f);
coloroperation->setChannel2(0.0f);
coloroperation->setChannel3(0.0f);
coloroperation->setChannel4(0.0f);
operation = coloroperation;
break;
}
}
if (operation) {
/* not supporting multiview for this generic case */
converter.addOperation(operation);
converter.mapOutputSocket(output, operation->getOutputSocket());
}
}
}
}
}