Blender  V2.93
COM_RenderLayersNode.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * Copyright 2011, Blender Foundation.
17  */
18 
19 #include "COM_RenderLayersNode.h"
20 #include "COM_RenderLayersProg.h"
21 #include "COM_RotateOperation.h"
22 #include "COM_ScaleOperation.h"
23 #include "COM_SetColorOperation.h"
24 #include "COM_SetValueOperation.h"
25 #include "COM_SetVectorOperation.h"
26 #include "COM_TranslateOperation.h"
27 
28 namespace blender::compositor {
29 
30 RenderLayersNode::RenderLayersNode(bNode *editorNode) : Node(editorNode)
31 {
32  /* pass */
33 }
34 
35 void RenderLayersNode::testSocketLink(NodeConverter &converter,
38  RenderLayersProg *operation,
39  Scene *scene,
40  int layerId,
41  bool is_preview) const
42 {
43  operation->setScene(scene);
44  operation->setLayerId(layerId);
45  operation->setRenderData(context.getRenderData());
46  operation->setViewName(context.getViewName());
47 
48  converter.mapOutputSocket(output, operation->getOutputSocket());
49  converter.addOperation(operation);
50 
51  if (is_preview) { /* only for image socket */
52  converter.addPreview(operation->getOutputSocket());
53  }
54 }
55 
56 void RenderLayersNode::testRenderLink(NodeConverter &converter,
57  const CompositorContext &context,
58  Render *re) const
59 {
60  Scene *scene = (Scene *)this->getbNode()->id;
61  const short layerId = this->getbNode()->custom1;
63  if (rr == nullptr) {
64  missingRenderLink(converter);
65  return;
66  }
67  ViewLayer *view_layer = (ViewLayer *)BLI_findlink(&scene->view_layers, layerId);
68  if (view_layer == nullptr) {
69  missingRenderLink(converter);
70  return;
71  }
72  RenderLayer *rl = RE_GetRenderLayer(rr, view_layer->name);
73  if (rl == nullptr) {
74  missingRenderLink(converter);
75  return;
76  }
77 
78  for (NodeOutput *output : getOutputSockets()) {
79  NodeImageLayer *storage = (NodeImageLayer *)output->getbNodeSocket()->storage;
81  &rl->passes, storage->pass_name, offsetof(RenderPass, name));
82  if (rpass == nullptr) {
83  missingSocketLink(converter, output);
84  continue;
85  }
86  RenderLayersProg *operation;
87  bool is_preview;
88  if (STREQ(rpass->name, RE_PASSNAME_COMBINED) &&
89  STREQ(output->getbNodeSocket()->name, "Alpha")) {
90  operation = new RenderLayersAlphaProg(rpass->name, DataType::Value, rpass->channels);
91  is_preview = false;
92  }
93  else if (STREQ(rpass->name, RE_PASSNAME_Z)) {
94  operation = new RenderLayersDepthProg(rpass->name, DataType::Value, rpass->channels);
95  is_preview = false;
96  }
97  else {
98  DataType type;
99  switch (rpass->channels) {
100  case 4:
102  break;
103  case 3:
105  break;
106  case 1:
108  break;
109  default:
110  BLI_assert(!"Unexpected number of channels for pass");
112  break;
113  }
114  operation = new RenderLayersProg(rpass->name, type, rpass->channels);
115  is_preview = STREQ(output->getbNodeSocket()->name, "Image");
116  }
117  testSocketLink(converter, context, output, operation, scene, layerId, is_preview);
118  }
119 }
120 
121 void RenderLayersNode::missingSocketLink(NodeConverter &converter, NodeOutput *output) const
122 {
123  NodeOperation *operation;
124  switch (output->getDataType()) {
125  case DataType::Color: {
126  const float color[4] = {0.0f, 0.0f, 0.0f, 0.0f};
127  SetColorOperation *color_operation = new SetColorOperation();
128  color_operation->setChannels(color);
129  operation = color_operation;
130  break;
131  }
132  case DataType::Vector: {
133  const float vector[3] = {0.0f, 0.0f, 0.0f};
134  SetVectorOperation *vector_operation = new SetVectorOperation();
135  vector_operation->setVector(vector);
136  operation = vector_operation;
137  break;
138  }
139  case DataType::Value: {
140  SetValueOperation *value_operation = new SetValueOperation();
141  value_operation->setValue(0.0f);
142  operation = value_operation;
143  break;
144  }
145  default: {
146  BLI_assert("!Unexpected data type");
147  return;
148  }
149  }
150 
151  converter.mapOutputSocket(output, operation->getOutputSocket());
152  converter.addOperation(operation);
153 }
154 
155 void RenderLayersNode::missingRenderLink(NodeConverter &converter) const
156 {
157  for (NodeOutput *output : outputs) {
158  missingSocketLink(converter, output);
159  }
160 }
161 
163  const CompositorContext &context) const
164 {
165  Scene *scene = (Scene *)this->getbNode()->id;
166  Render *re = (scene) ? RE_GetSceneRender(scene) : nullptr;
167 
168  if (re != nullptr) {
169  testRenderLink(converter, context, re);
170  RE_ReleaseResult(re);
171  }
172  else {
173  missingRenderLink(converter);
174  }
175 }
176 
177 } // namespace blender::compositor
#define BLI_assert(a)
Definition: BLI_assert.h:58
void * BLI_findstring(const struct ListBase *listbase, const char *id, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define STREQ(a, b)
#define RE_PASSNAME_COMBINED
#define RE_PASSNAME_Z
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
#define output
Overall context of the compositor.
void addPreview(NodeOperationOutput *output)
void addOperation(NodeOperation *operation)
void mapOutputSocket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
NodeOperationOutput * getOutputSocket(unsigned int index=0)
NodeOutput are sockets that can send data/input.
Definition: COM_Node.h:258
Vector< NodeOutput * > outputs
the list of actual output-sockets
Definition: COM_Node.h:73
bNode * getbNode() const
get the reference to the SDNA bNode struct
Definition: COM_Node.h:82
const Vector< NodeOutput * > & getOutputSockets() const
get access to the vector of input sockets
Definition: COM_Node.h:126
void convertToOperations(NodeConverter &converter, const CompositorContext &context) const override
convert node to operation
void setRenderData(const RenderData *rd)
Scene scene
DataType
Definition: device_memory.h:46
@ Vector
Vector data type.
RenderResult * RE_AcquireResultRead(Render *re)
Definition: pipeline.c:343
Render * RE_GetSceneRender(const Scene *scene)
Definition: pipeline.c:591
RenderLayer * RE_GetRenderLayer(RenderResult *rr, const char *name)
Definition: pipeline.c:276
void RE_ReleaseResult(Render *re)
Definition: pipeline.c:379
char pass_name[64]
ListBase passes
Definition: RE_pipeline.h:108
char name[64]
Definition: RE_pipeline.h:80
int channels
Definition: RE_pipeline.h:79
ListBase view_layers
char name[64]
short custom1
struct ID * id