~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to intern/cycles/render/camera.cpp

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include "camera.h"
20
20
#include "scene.h"
21
21
 
 
22
#include "device.h"
 
23
 
22
24
#include "util_vector.h"
23
25
 
24
26
CCL_NAMESPACE_BEGIN
25
27
 
26
28
Camera::Camera()
27
29
{
28
 
        shutteropen = 0.0f;
29
 
        shutterclose = 1.0f;
 
30
        shuttertime = 1.0f;
30
31
 
31
32
        aperturesize = 0.0f;
32
33
        focaldistance = 10.0f;
35
36
 
36
37
        matrix = transform_identity();
37
38
 
 
39
        motion.pre = transform_identity();
 
40
        motion.post = transform_identity();
 
41
        use_motion = false;
 
42
 
38
43
        type = CAMERA_PERSPECTIVE;
 
44
        panorama_type = PANORAMA_EQUIRECTANGULAR;
 
45
        fisheye_fov = M_PI_F;
 
46
        fisheye_lens = 10.5f;
39
47
        fov = M_PI_F/4.0f;
40
48
 
 
49
        sensorwidth = 0.036;
 
50
        sensorheight = 0.024;
 
51
 
41
52
        nearclip = 1e-5f;
42
53
        farclip = 1e5f;
43
54
 
44
55
        width = 1024;
45
56
        height = 512;
46
57
 
47
 
        left = -((float)width/(float)height);
48
 
        right = (float)width/(float)height;
49
 
        bottom = -1.0f;
50
 
        top = 1.0f;
 
58
        viewplane.left = -((float)width/(float)height);
 
59
        viewplane.right = (float)width/(float)height;
 
60
        viewplane.bottom = -1.0f;
 
61
        viewplane.top = 1.0f;
51
62
 
52
63
        screentoworld = transform_identity();
53
64
        rastertoworld = transform_identity();
61
72
 
62
73
        need_update = true;
63
74
        need_device_update = true;
 
75
        previous_need_motion = -1;
64
76
}
65
77
 
66
78
Camera::~Camera()
77
89
        Transform ndctoraster = transform_scale(width, height, 1.0f);
78
90
 
79
91
        /* raster to screen */
80
 
        Transform screentoraster = ndctoraster;
81
 
        
82
 
        screentoraster = ndctoraster *
83
 
                transform_scale(1.0f/(right - left), 1.0f/(top - bottom), 1.0f) *
84
 
                transform_translate(-left, -bottom, 0.0f);
 
92
        Transform screentondc = 
 
93
                transform_scale(1.0f/(viewplane.right - viewplane.left),
 
94
                                1.0f/(viewplane.top - viewplane.bottom), 1.0f) *
 
95
                transform_translate(-viewplane.left, -viewplane.bottom, 0.0f);
85
96
 
 
97
        Transform screentoraster = ndctoraster * screentondc;
86
98
        Transform rastertoscreen = transform_inverse(screentoraster);
87
99
 
88
100
        /* screen to camera */
92
104
                screentocamera = transform_inverse(transform_orthographic(nearclip, farclip));
93
105
        else
94
106
                screentocamera = transform_identity();
 
107
        
 
108
        Transform cameratoscreen = transform_inverse(screentocamera);
95
109
 
96
110
        rastertocamera = screentocamera * rastertoscreen;
 
111
        cameratoraster = screentoraster * cameratoscreen;
97
112
 
98
113
        cameratoworld = matrix;
99
114
        screentoworld = cameratoworld * screentocamera;
100
115
        rastertoworld = cameratoworld * rastertocamera;
101
116
        ndctoworld = rastertoworld * ndctoraster;
102
 
        worldtoraster = transform_inverse(rastertoworld);
 
117
 
 
118
        /* note we recompose matrices instead of taking inverses of the above, this
 
119
         * is needed to avoid inverting near degenerate matrices that happen due to
 
120
         * precision issues with large scenes */
 
121
        worldtocamera = transform_inverse(matrix);
 
122
        worldtoscreen = cameratoscreen * worldtocamera;
 
123
        worldtondc = screentondc * worldtoscreen;
 
124
        worldtoraster = ndctoraster * worldtondc;
103
125
 
104
126
        /* differentials */
105
127
        if(type == CAMERA_ORTHOGRAPHIC) {
124
146
        need_device_update = true;
125
147
}
126
148
 
127
 
void Camera::device_update(Device *device, DeviceScene *dscene)
 
149
void Camera::device_update(Device *device, DeviceScene *dscene, Scene *scene)
128
150
{
 
151
        Scene::MotionType need_motion = scene->need_motion(device->info.advanced_shading);
 
152
 
129
153
        update();
130
154
 
 
155
        if (previous_need_motion != need_motion) {
 
156
                /* scene's motion model could have been changed since previous device
 
157
                 * camera update this could happen for example in case when one render
 
158
                 * layer has got motion pass and another not */
 
159
                need_device_update = true;
 
160
        }
 
161
 
131
162
        if(!need_device_update)
132
163
                return;
133
164
        
136
167
        /* store matrices */
137
168
        kcam->screentoworld = screentoworld;
138
169
        kcam->rastertoworld = rastertoworld;
139
 
        kcam->ndctoworld = ndctoworld;
140
170
        kcam->rastertocamera = rastertocamera;
141
171
        kcam->cameratoworld = cameratoworld;
142
 
        kcam->worldtoscreen = transform_inverse(screentoworld);
143
 
        kcam->worldtoraster = transform_inverse(rastertoworld);
144
 
        kcam->worldtondc = transform_inverse(ndctoworld);
145
 
        kcam->worldtocamera = transform_inverse(cameratoworld);
 
172
        kcam->worldtocamera = worldtocamera;
 
173
        kcam->worldtoscreen = worldtoscreen;
 
174
        kcam->worldtoraster = worldtoraster;
 
175
        kcam->worldtondc = worldtondc;
 
176
 
 
177
        /* camera motion */
 
178
        kcam->have_motion = 0;
 
179
 
 
180
        if(need_motion == Scene::MOTION_PASS) {
 
181
                if(type == CAMERA_PANORAMA) {
 
182
                        if(use_motion) {
 
183
                                kcam->motion.pre = transform_inverse(motion.pre);
 
184
                                kcam->motion.post = transform_inverse(motion.post);
 
185
                        }
 
186
                        else {
 
187
                                kcam->motion.pre = kcam->worldtocamera;
 
188
                                kcam->motion.post = kcam->worldtocamera;
 
189
                        }
 
190
                }
 
191
                else {
 
192
                        if(use_motion) {
 
193
                                kcam->motion.pre = cameratoraster * transform_inverse(motion.pre);
 
194
                                kcam->motion.post = cameratoraster * transform_inverse(motion.post);
 
195
                        }
 
196
                        else {
 
197
                                kcam->motion.pre = worldtoraster;
 
198
                                kcam->motion.post = worldtoraster;
 
199
                        }
 
200
                }
 
201
        }
 
202
#ifdef __CAMERA_MOTION__
 
203
        else if(need_motion == Scene::MOTION_BLUR) {
 
204
                if(use_motion) {
 
205
                        transform_motion_decompose((DecompMotionTransform*)&kcam->motion, &motion, &matrix);
 
206
                        kcam->have_motion = 1;
 
207
                }
 
208
        }
 
209
#endif
146
210
 
147
211
        /* depth of field */
148
212
        kcam->aperturesize = aperturesize;
151
215
        kcam->bladesrotation = bladesrotation;
152
216
 
153
217
        /* motion blur */
154
 
        kcam->shutteropen = shutteropen;
155
 
        kcam->shutterclose = shutterclose;
 
218
#ifdef __CAMERA_MOTION__
 
219
        kcam->shuttertime = (need_motion == Scene::MOTION_BLUR) ? shuttertime: -1.0f;
 
220
#else
 
221
        kcam->shuttertime = -1.0f;
 
222
#endif
156
223
 
157
224
        /* type */
158
225
        kcam->type = type;
159
226
 
 
227
        /* panorama */
 
228
        kcam->panorama_type = panorama_type;
 
229
        kcam->fisheye_fov = fisheye_fov;
 
230
        kcam->fisheye_lens = fisheye_lens;
 
231
 
 
232
        /* sensor size */
 
233
        kcam->sensorwidth = sensorwidth;
 
234
        kcam->sensorheight = sensorheight;
 
235
 
 
236
        /* render size */
 
237
        kcam->width = width;
 
238
        kcam->height = height;
 
239
 
160
240
        /* store differentials */
161
241
        kcam->dx = float3_to_float4(dx);
162
242
        kcam->dy = float3_to_float4(dy);
166
246
        kcam->cliplength = (farclip == FLT_MAX)? FLT_MAX: farclip - nearclip;
167
247
 
168
248
        need_device_update = false;
 
249
        previous_need_motion = need_motion;
169
250
}
170
251
 
171
252
void Camera::device_free(Device *device, DeviceScene *dscene)
175
256
 
176
257
bool Camera::modified(const Camera& cam)
177
258
{
178
 
        return !((shutteropen == cam.shutteropen) &&
179
 
                (shutterclose == cam.shutterclose) &&
 
259
        return !((shuttertime == cam.shuttertime) &&
180
260
                (aperturesize == cam.aperturesize) &&
181
261
                (blades == cam.blades) &&
182
262
                (bladesrotation == cam.bladesrotation) &&
185
265
                (fov == cam.fov) &&
186
266
                (nearclip == cam.nearclip) &&
187
267
                (farclip == cam.farclip) &&
 
268
                (sensorwidth == cam.sensorwidth) &&
 
269
                (sensorheight == cam.sensorheight) &&
188
270
                // modified for progressive render
189
271
                // (width == cam.width) &&
190
272
                // (height == cam.height) &&
191
 
                (left == cam.left) &&
192
 
                (right == cam.right) &&
193
 
                (bottom == cam.bottom) &&
194
 
                (top == cam.top) &&
195
 
                (matrix == cam.matrix));
 
273
                (viewplane == cam.viewplane) &&
 
274
                (border == cam.border) &&
 
275
                (matrix == cam.matrix) &&
 
276
                (panorama_type == cam.panorama_type) &&
 
277
                (fisheye_fov == cam.fisheye_fov) &&
 
278
                (fisheye_lens == cam.fisheye_lens));
 
279
}
 
280
 
 
281
bool Camera::motion_modified(const Camera& cam)
 
282
{
 
283
        return !((motion == cam.motion) &&
 
284
                (use_motion == cam.use_motion));
196
285
}
197
286
 
198
287
void Camera::tag_update()