2
* Copyright 2011, Blender Foundation.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
#include "COM_RenderLayersProg.h"
25
#include "BLI_listbase.h"
26
#include "DNA_scene_types.h"
29
#include "RE_pipeline.h"
30
#include "RE_shader_ext.h"
31
#include "RE_render_ext.h"
34
/* ******** Render Layers Base Prog ******** */
36
RenderLayersBaseProg::RenderLayersBaseProg(int renderpass, int elementsize) : NodeOperation()
38
this->m_renderpass = renderpass;
40
this->m_inputBuffer = NULL;
41
this->m_elementsize = elementsize;
46
void RenderLayersBaseProg::initExecution()
48
Scene *scene = this->getScene();
49
Render *re = (scene) ? RE_GetRender(scene->id.name) : NULL;
50
RenderResult *rr = NULL;
53
rr = RE_AcquireResultRead(re);
56
SceneRenderLayer *srl = (SceneRenderLayer *)BLI_findlink(&scene->r.layers, getLayerId());
59
RenderLayer *rl = RE_GetRenderLayer(rr, srl->name);
60
if (rl && rl->rectf) {
61
this->m_inputBuffer = RE_RenderLayerGetPass(rl, this->m_renderpass);
63
if (this->m_inputBuffer == NULL || this->m_renderpass == SCE_PASS_COMBINED) {
64
this->m_inputBuffer = rl->rectf;
75
void RenderLayersBaseProg::doInterpolation(float output[4], float x, float y, PixelSampler sampler)
79
int width = this->getWidth(), height = this->getHeight();
85
offset = (iy * width + ix) * this->m_elementsize;
87
if (this->m_elementsize == 1)
88
output[0] = this->m_inputBuffer[offset];
89
else if (this->m_elementsize == 3)
90
copy_v3_v3(output, &this->m_inputBuffer[offset]);
92
copy_v4_v4(output, &this->m_inputBuffer[offset]);
97
BLI_bilinear_interpolation_fl(this->m_inputBuffer, output, width, height, this->m_elementsize, x, y);
101
BLI_bicubic_interpolation_fl(this->m_inputBuffer, output, width, height, this->m_elementsize, x, y);
105
if (this->m_elementsize == 1) {
110
else if (this->m_elementsize == 3) {
115
void RenderLayersBaseProg::executePixel(float output[4], float x, float y, PixelSampler sampler)
118
const RenderData *rd = this->m_rd;
122
if (rd->mode & R_BORDER && rd->mode & R_CROP) {
123
/* see comment in executeRegion describing coordinate mapping,
124
* here it simply goes other way around
126
int full_width = rd->xsch * rd->size / 100;
127
int full_height = rd->ysch * rd->size / 100;
129
dx = rd->border.xmin * full_width - (full_width - this->getWidth()) / 2.0f;
130
dy = rd->border.ymin * full_height - (full_height - this->getHeight()) / 2.0f;
140
if (this->m_inputBuffer == NULL || ix < 0 || iy < 0 || ix >= (int)this->getWidth() || iy >= (int)this->getHeight() ) {
144
doInterpolation(output, ix, iy, sampler);
148
void RenderLayersBaseProg::deinitExecution()
150
this->m_inputBuffer = NULL;
153
void RenderLayersBaseProg::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
155
Scene *sce = this->getScene();
156
Render *re = (sce) ? RE_GetRender(sce->id.name) : NULL;
157
RenderResult *rr = NULL;
163
rr = RE_AcquireResultRead(re);
166
SceneRenderLayer *srl = (SceneRenderLayer *)BLI_findlink(&sce->r.layers, getLayerId());
168
RenderLayer *rl = RE_GetRenderLayer(rr, srl->name);
169
if (rl && rl->rectf) {
170
resolution[0] = rl->rectx;
171
resolution[1] = rl->recty;
177
RE_ReleaseResult(re);
181
/* ******** Render Layers AO Operation ******** */
183
RenderLayersAOOperation::RenderLayersAOOperation() : RenderLayersBaseProg(SCE_PASS_AO, 3)
185
this->addOutputSocket(COM_DT_COLOR);
188
/* ******** Render Layers Alpha Operation ******** */
190
RenderLayersAlphaProg::RenderLayersAlphaProg() : RenderLayersBaseProg(SCE_PASS_COMBINED, 4)
192
this->addOutputSocket(COM_DT_VALUE);
195
void RenderLayersAlphaProg::executePixel(float output[4], float x, float y, PixelSampler sampler)
199
float *inputBuffer = this->getInputBuffer();
201
if (inputBuffer == NULL || ix < 0 || iy < 0 || ix >= (int)this->getWidth() || iy >= (int)this->getHeight() ) {
208
unsigned int offset = (iy * this->getWidth() + ix) * 4;
209
output[0] = inputBuffer[offset + 3];
216
/* ******** Render Layers Color Operation ******** */
218
RenderLayersColorOperation::RenderLayersColorOperation() : RenderLayersBaseProg(SCE_PASS_RGBA, 4)
220
this->addOutputSocket(COM_DT_COLOR);
223
/* ******** Render Layers Cycles Operation ******** */
225
RenderLayersCyclesOperation::RenderLayersCyclesOperation(int pass) : RenderLayersBaseProg(pass, 3)
227
this->addOutputSocket(COM_DT_COLOR);
230
/* ******** Render Layers Depth Operation ******** */
232
RenderLayersDepthProg::RenderLayersDepthProg() : RenderLayersBaseProg(SCE_PASS_Z, 1)
234
this->addOutputSocket(COM_DT_VALUE);
237
void RenderLayersDepthProg::executePixel(float output[4], float x, float y, PixelSampler sampler)
241
float *inputBuffer = this->getInputBuffer();
243
if (inputBuffer == NULL || ix < 0 || iy < 0 || ix >= (int)this->getWidth() || iy >= (int)this->getHeight() ) {
250
unsigned int offset = (iy * this->getWidth() + ix);
251
output[0] = inputBuffer[offset];
258
/* ******** Render Layers Diffuse Operation ******** */
260
RenderLayersDiffuseOperation::RenderLayersDiffuseOperation() : RenderLayersBaseProg(SCE_PASS_DIFFUSE, 3)
262
this->addOutputSocket(COM_DT_COLOR);
265
/* ******** Render Layers Emit Operation ******** */
267
RenderLayersEmitOperation::RenderLayersEmitOperation() : RenderLayersBaseProg(SCE_PASS_EMIT, 3)
269
this->addOutputSocket(COM_DT_COLOR);
272
/* ******** Render Layers Environment Operation ******** */
274
RenderLayersEnvironmentOperation::RenderLayersEnvironmentOperation() : RenderLayersBaseProg(SCE_PASS_ENVIRONMENT, 3)
276
this->addOutputSocket(COM_DT_COLOR);
279
/* ******** Render Layers Image Operation ******** */
281
RenderLayersColorProg::RenderLayersColorProg() : RenderLayersBaseProg(SCE_PASS_COMBINED, 4)
283
this->addOutputSocket(COM_DT_COLOR);
286
/* ******** Render Layers Indirect Operation ******** */
288
RenderLayersIndirectOperation::RenderLayersIndirectOperation() : RenderLayersBaseProg(SCE_PASS_INDIRECT, 3)
290
this->addOutputSocket(COM_DT_COLOR);
293
/* ******** Render Layers Material Index Operation ******** */
295
RenderLayersMaterialIndexOperation::RenderLayersMaterialIndexOperation() : RenderLayersBaseProg(SCE_PASS_INDEXMA, 1)
297
this->addOutputSocket(COM_DT_VALUE);
300
/* ******** Render Layers Mist Operation ******** */
302
RenderLayersMistOperation::RenderLayersMistOperation() : RenderLayersBaseProg(SCE_PASS_MIST, 1)
304
this->addOutputSocket(COM_DT_VALUE);
307
/* ******** Render Layers Normal Operation ******** */
309
RenderLayersNormalOperation::RenderLayersNormalOperation() : RenderLayersBaseProg(SCE_PASS_NORMAL, 3)
311
this->addOutputSocket(COM_DT_VECTOR);
314
/* ******** Render Layers Object Index Operation ******** */
316
RenderLayersObjectIndexOperation::RenderLayersObjectIndexOperation() : RenderLayersBaseProg(SCE_PASS_INDEXOB, 1)
318
this->addOutputSocket(COM_DT_VALUE);
321
/* ******** Render Layers Reflection Operation ******** */
323
RenderLayersReflectionOperation::RenderLayersReflectionOperation() : RenderLayersBaseProg(SCE_PASS_REFLECT, 3)
325
this->addOutputSocket(COM_DT_COLOR);
328
/* ******** Render Layers Refraction Operation ******** */
330
RenderLayersRefractionOperation::RenderLayersRefractionOperation() : RenderLayersBaseProg(SCE_PASS_REFRACT, 3)
332
this->addOutputSocket(COM_DT_COLOR);
335
/* ******** Render Layers Shadow Operation ******** */
337
RenderLayersShadowOperation::RenderLayersShadowOperation() : RenderLayersBaseProg(SCE_PASS_SHADOW, 3)
339
this->addOutputSocket(COM_DT_COLOR);
342
/* ******** Render Layers Specular Operation ******** */
344
RenderLayersSpecularOperation::RenderLayersSpecularOperation() : RenderLayersBaseProg(SCE_PASS_SPEC, 3)
346
this->addOutputSocket(COM_DT_COLOR);
349
/* ******** Render Layers Speed Operation ******** */
351
RenderLayersSpeedOperation::RenderLayersSpeedOperation() : RenderLayersBaseProg(SCE_PASS_VECTOR, 4)
353
this->addOutputSocket(COM_DT_COLOR);
356
/* ******** Render Layers UV Operation ******** */
358
RenderLayersUVOperation::RenderLayersUVOperation() : RenderLayersBaseProg(SCE_PASS_UV, 3)
360
this->addOutputSocket(COM_DT_VECTOR);