~ubuntu-branches/ubuntu/utopic/blender/utopic-proposed

« back to all changes in this revision

Viewing changes to source/blender/compositor/operations/COM_RenderLayersProg.cpp

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-02-19 11:24:23 UTC
  • mfrom: (14.2.23 sid)
  • Revision ID: package-import@ubuntu.com-20140219112423-rkmaz2m7ha06d4tk
Tags: 2.69-3ubuntu1
* Merge with Debian; remaining changes:
  - Configure without OpenImageIO on armhf, as it is not available on
    Ubuntu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2011, Blender Foundation.
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 *
 
18
 * Contributor: 
 
19
 *              Jeroen Bakker 
 
20
 *              Monique Dewanchand
 
21
 */
 
22
 
 
23
#include "COM_RenderLayersProg.h"
 
24
 
 
25
#include "BLI_listbase.h"
 
26
#include "DNA_scene_types.h"
 
27
 
 
28
extern "C" {
 
29
        #include "RE_pipeline.h"
 
30
        #include "RE_shader_ext.h"
 
31
        #include "RE_render_ext.h"
 
32
}
 
33
 
 
34
/* ******** Render Layers Base Prog ******** */
 
35
 
 
36
RenderLayersBaseProg::RenderLayersBaseProg(int renderpass, int elementsize) : NodeOperation()
 
37
{
 
38
        this->m_renderpass = renderpass;
 
39
        this->setScene(NULL);
 
40
        this->m_inputBuffer = NULL;
 
41
        this->m_elementsize = elementsize;
 
42
        this->m_rd = NULL;
 
43
}
 
44
 
 
45
 
 
46
void RenderLayersBaseProg::initExecution()
 
47
{
 
48
        Scene *scene = this->getScene();
 
49
        Render *re = (scene) ? RE_GetRender(scene->id.name) : NULL;
 
50
        RenderResult *rr = NULL;
 
51
        
 
52
        if (re)
 
53
                rr = RE_AcquireResultRead(re);
 
54
        
 
55
        if (rr) {
 
56
                SceneRenderLayer *srl = (SceneRenderLayer *)BLI_findlink(&scene->r.layers, getLayerId());
 
57
                if (srl) {
 
58
 
 
59
                        RenderLayer *rl = RE_GetRenderLayer(rr, srl->name);
 
60
                        if (rl && rl->rectf) {
 
61
                                this->m_inputBuffer = RE_RenderLayerGetPass(rl, this->m_renderpass);
 
62
 
 
63
                                if (this->m_inputBuffer == NULL || this->m_renderpass == SCE_PASS_COMBINED) {
 
64
                                        this->m_inputBuffer = rl->rectf;
 
65
                                }
 
66
                        }
 
67
                }
 
68
        }
 
69
        if (re) {
 
70
                RE_ReleaseResult(re);
 
71
                re = NULL;
 
72
        }
 
73
}
 
74
 
 
75
void RenderLayersBaseProg::doInterpolation(float output[4], float x, float y, PixelSampler sampler)
 
76
{
 
77
        unsigned int offset;
 
78
        int ix, iy;
 
79
        int width = this->getWidth(), height = this->getHeight();
 
80
 
 
81
        switch (sampler) {
 
82
                case COM_PS_NEAREST:
 
83
                        ix = x;
 
84
                        iy = y;
 
85
                        offset = (iy * width + ix) * this->m_elementsize;
 
86
 
 
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]);
 
91
                        else
 
92
                                copy_v4_v4(output, &this->m_inputBuffer[offset]);
 
93
 
 
94
                        break;
 
95
 
 
96
                case COM_PS_BILINEAR:
 
97
                        BLI_bilinear_interpolation_fl(this->m_inputBuffer, output, width, height, this->m_elementsize, x, y);
 
98
                        break;
 
99
 
 
100
                case COM_PS_BICUBIC:
 
101
                        BLI_bicubic_interpolation_fl(this->m_inputBuffer, output, width, height, this->m_elementsize, x, y);
 
102
                        break;
 
103
        }
 
104
 
 
105
        if (this->m_elementsize == 1) {
 
106
                output[1] = 0.0f;
 
107
                output[2] = 0.0f;
 
108
                output[3] = 0.0f;
 
109
        }
 
110
        else if (this->m_elementsize == 3) {
 
111
                output[3] = 1.0f;
 
112
        }
 
113
}
 
114
 
 
115
void RenderLayersBaseProg::executePixel(float output[4], float x, float y, PixelSampler sampler)
 
116
{
 
117
#if 0
 
118
        const RenderData *rd = this->m_rd;
 
119
 
 
120
        int dx = 0, dy = 0;
 
121
 
 
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
 
125
                 */
 
126
                int full_width  = rd->xsch * rd->size / 100;
 
127
                int full_height = rd->ysch * rd->size / 100;
 
128
 
 
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;
 
131
        }
 
132
 
 
133
        int ix = x - dx;
 
134
        int iy = y - dy;
 
135
#else
 
136
        int ix = x;
 
137
        int iy = y;
 
138
#endif
 
139
 
 
140
        if (this->m_inputBuffer == NULL || ix < 0 || iy < 0 || ix >= (int)this->getWidth() || iy >= (int)this->getHeight() ) {
 
141
                zero_v4(output);
 
142
        }
 
143
        else {
 
144
                doInterpolation(output, ix, iy, sampler);
 
145
        }
 
146
}
 
147
 
 
148
void RenderLayersBaseProg::deinitExecution()
 
149
{
 
150
        this->m_inputBuffer = NULL;
 
151
}
 
152
 
 
153
void RenderLayersBaseProg::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
 
154
{
 
155
        Scene *sce = this->getScene();
 
156
        Render *re = (sce) ? RE_GetRender(sce->id.name) : NULL;
 
157
        RenderResult *rr = NULL;
 
158
        
 
159
        resolution[0] = 0;
 
160
        resolution[1] = 0;
 
161
        
 
162
        if (re)
 
163
                rr = RE_AcquireResultRead(re);
 
164
        
 
165
        if (rr) {
 
166
                SceneRenderLayer *srl   = (SceneRenderLayer *)BLI_findlink(&sce->r.layers, getLayerId());
 
167
                if (srl) {
 
168
                        RenderLayer *rl = RE_GetRenderLayer(rr, srl->name);
 
169
                        if (rl && rl->rectf) {
 
170
                                resolution[0] = rl->rectx;
 
171
                                resolution[1] = rl->recty;
 
172
                        }
 
173
                }
 
174
        }
 
175
        
 
176
        if (re)
 
177
                RE_ReleaseResult(re);
 
178
 
 
179
}
 
180
 
 
181
/* ******** Render Layers AO Operation ******** */
 
182
 
 
183
RenderLayersAOOperation::RenderLayersAOOperation() : RenderLayersBaseProg(SCE_PASS_AO, 3)
 
184
{
 
185
        this->addOutputSocket(COM_DT_COLOR);
 
186
}
 
187
 
 
188
/* ******** Render Layers Alpha Operation ******** */
 
189
 
 
190
RenderLayersAlphaProg::RenderLayersAlphaProg() : RenderLayersBaseProg(SCE_PASS_COMBINED, 4)
 
191
{
 
192
        this->addOutputSocket(COM_DT_VALUE);
 
193
}
 
194
 
 
195
void RenderLayersAlphaProg::executePixel(float output[4], float x, float y, PixelSampler sampler)
 
196
{
 
197
        int ix = x;
 
198
        int iy = y;
 
199
        float *inputBuffer = this->getInputBuffer();
 
200
 
 
201
        if (inputBuffer == NULL || ix < 0 || iy < 0 || ix >= (int)this->getWidth() || iy >= (int)this->getHeight() ) {
 
202
                output[0] = 0.0f;
 
203
                output[1] = 0.0f;
 
204
                output[2] = 0.0f;
 
205
                output[3] = 0.0f;
 
206
        }
 
207
        else {
 
208
                unsigned int offset = (iy * this->getWidth() + ix) * 4;
 
209
                output[0] = inputBuffer[offset + 3];
 
210
                output[1] = 0.0f;
 
211
                output[2] = 0.0f;
 
212
                output[3] = 0.0f;
 
213
        }
 
214
}
 
215
 
 
216
/* ******** Render Layers Color Operation ******** */
 
217
 
 
218
RenderLayersColorOperation::RenderLayersColorOperation() : RenderLayersBaseProg(SCE_PASS_RGBA, 4)
 
219
{
 
220
        this->addOutputSocket(COM_DT_COLOR);
 
221
}
 
222
 
 
223
/* ******** Render Layers Cycles Operation ******** */
 
224
 
 
225
RenderLayersCyclesOperation::RenderLayersCyclesOperation(int pass) : RenderLayersBaseProg(pass, 3)
 
226
{
 
227
        this->addOutputSocket(COM_DT_COLOR);
 
228
}
 
229
 
 
230
/* ******** Render Layers Depth Operation ******** */
 
231
 
 
232
RenderLayersDepthProg::RenderLayersDepthProg() : RenderLayersBaseProg(SCE_PASS_Z, 1)
 
233
{
 
234
        this->addOutputSocket(COM_DT_VALUE);
 
235
}
 
236
 
 
237
void RenderLayersDepthProg::executePixel(float output[4], float x, float y, PixelSampler sampler)
 
238
{
 
239
        int ix = x;
 
240
        int iy = y;
 
241
        float *inputBuffer = this->getInputBuffer();
 
242
 
 
243
        if (inputBuffer == NULL || ix < 0 || iy < 0 || ix >= (int)this->getWidth() || iy >= (int)this->getHeight() ) {
 
244
                output[0] = 0.0f;
 
245
                output[1] = 0.0f;
 
246
                output[2] = 0.0f;
 
247
                output[3] = 0.0f;
 
248
        }
 
249
        else {
 
250
                unsigned int offset = (iy * this->getWidth() + ix);
 
251
                output[0] = inputBuffer[offset];
 
252
                output[1] = 0.0f;
 
253
                output[2] = 0.0f;
 
254
                output[3] = 0.0f;
 
255
        }
 
256
}
 
257
 
 
258
/* ******** Render Layers Diffuse Operation ******** */
 
259
 
 
260
RenderLayersDiffuseOperation::RenderLayersDiffuseOperation() : RenderLayersBaseProg(SCE_PASS_DIFFUSE, 3)
 
261
{
 
262
        this->addOutputSocket(COM_DT_COLOR);
 
263
}
 
264
 
 
265
/* ******** Render Layers Emit Operation ******** */
 
266
 
 
267
RenderLayersEmitOperation::RenderLayersEmitOperation() : RenderLayersBaseProg(SCE_PASS_EMIT, 3)
 
268
{
 
269
        this->addOutputSocket(COM_DT_COLOR);
 
270
}
 
271
 
 
272
/* ******** Render Layers Environment Operation ******** */
 
273
 
 
274
RenderLayersEnvironmentOperation::RenderLayersEnvironmentOperation() : RenderLayersBaseProg(SCE_PASS_ENVIRONMENT, 3)
 
275
{
 
276
        this->addOutputSocket(COM_DT_COLOR);
 
277
}
 
278
 
 
279
/* ******** Render Layers Image Operation ******** */
 
280
 
 
281
RenderLayersColorProg::RenderLayersColorProg() : RenderLayersBaseProg(SCE_PASS_COMBINED, 4)
 
282
{
 
283
        this->addOutputSocket(COM_DT_COLOR);
 
284
}
 
285
 
 
286
/* ******** Render Layers Indirect Operation ******** */
 
287
 
 
288
RenderLayersIndirectOperation::RenderLayersIndirectOperation() : RenderLayersBaseProg(SCE_PASS_INDIRECT, 3)
 
289
{
 
290
        this->addOutputSocket(COM_DT_COLOR);
 
291
}
 
292
 
 
293
/* ******** Render Layers Material Index Operation ******** */
 
294
 
 
295
RenderLayersMaterialIndexOperation::RenderLayersMaterialIndexOperation() : RenderLayersBaseProg(SCE_PASS_INDEXMA, 1)
 
296
{
 
297
        this->addOutputSocket(COM_DT_VALUE);
 
298
}
 
299
 
 
300
/* ******** Render Layers Mist Operation ******** */
 
301
 
 
302
RenderLayersMistOperation::RenderLayersMistOperation() : RenderLayersBaseProg(SCE_PASS_MIST, 1)
 
303
{
 
304
        this->addOutputSocket(COM_DT_VALUE);
 
305
}
 
306
 
 
307
/* ******** Render Layers Normal Operation ******** */
 
308
 
 
309
RenderLayersNormalOperation::RenderLayersNormalOperation() : RenderLayersBaseProg(SCE_PASS_NORMAL, 3)
 
310
{
 
311
        this->addOutputSocket(COM_DT_VECTOR);
 
312
}
 
313
 
 
314
/* ******** Render Layers Object Index Operation ******** */
 
315
 
 
316
RenderLayersObjectIndexOperation::RenderLayersObjectIndexOperation() : RenderLayersBaseProg(SCE_PASS_INDEXOB, 1)
 
317
{
 
318
        this->addOutputSocket(COM_DT_VALUE);
 
319
}
 
320
 
 
321
/* ******** Render Layers Reflection Operation ******** */
 
322
 
 
323
RenderLayersReflectionOperation::RenderLayersReflectionOperation() : RenderLayersBaseProg(SCE_PASS_REFLECT, 3)
 
324
{
 
325
        this->addOutputSocket(COM_DT_COLOR);
 
326
}
 
327
 
 
328
/* ******** Render Layers Refraction Operation ******** */
 
329
 
 
330
RenderLayersRefractionOperation::RenderLayersRefractionOperation() : RenderLayersBaseProg(SCE_PASS_REFRACT, 3)
 
331
{
 
332
        this->addOutputSocket(COM_DT_COLOR);
 
333
}
 
334
 
 
335
/* ******** Render Layers Shadow Operation ******** */
 
336
 
 
337
RenderLayersShadowOperation::RenderLayersShadowOperation() : RenderLayersBaseProg(SCE_PASS_SHADOW, 3)
 
338
{
 
339
        this->addOutputSocket(COM_DT_COLOR);
 
340
}
 
341
 
 
342
/* ******** Render Layers Specular Operation ******** */
 
343
 
 
344
RenderLayersSpecularOperation::RenderLayersSpecularOperation() : RenderLayersBaseProg(SCE_PASS_SPEC, 3)
 
345
{
 
346
        this->addOutputSocket(COM_DT_COLOR);
 
347
}
 
348
 
 
349
/* ******** Render Layers Speed Operation ******** */
 
350
 
 
351
RenderLayersSpeedOperation::RenderLayersSpeedOperation() : RenderLayersBaseProg(SCE_PASS_VECTOR, 4)
 
352
{
 
353
        this->addOutputSocket(COM_DT_COLOR);
 
354
}
 
355
 
 
356
/* ******** Render Layers UV Operation ******** */
 
357
 
 
358
RenderLayersUVOperation::RenderLayersUVOperation() : RenderLayersBaseProg(SCE_PASS_UV, 3)
 
359
{
 
360
        this->addOutputSocket(COM_DT_VECTOR);
 
361
}