Blender V5.3
kernel/camera/camera.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include "kernel/globals.h"
8
13
14#ifdef WITH_OSL
15# include "kernel/osl/camera.h"
16#endif
17
19
20/* Perspective Camera */
21
23{
24 const float blades = cam->blades;
25 float2 bokeh;
26
27 if (blades == 0.0f) {
28 /* sample disk */
29 bokeh = sample_uniform_disk(rand);
30 }
31 else {
32 /* sample polygon */
33 const float rotation = cam->bladesrotation;
34 bokeh = regular_polygon_sample(blades, rotation, rand);
35 }
36
37 /* anamorphic lens bokeh */
38 bokeh.x *= cam->inv_aperture_ratio;
39
40 return bokeh;
41}
42
44 const float2 raster_xy,
45 const float2 rand_lens,
46 ccl_private Ray *ray)
47{
48 /* create ray form raster position */
49 const ProjectionTransform rastertocamera = kernel_data.cam.rastertocamera;
50 const float3 raster = make_float3(raster_xy);
51 float3 Pcamera = transform_perspective(&rastertocamera, raster);
52
53 if (kernel_data.cam.have_perspective_motion) {
54 /* TODO(sergey): Currently we interpolate projected coordinate which
55 * gives nice looking result and which is simple, but is in fact a bit
56 * different comparing to constructing projective matrix from an
57 * interpolated field of view.
58 */
59 if (ray->time < 0.5f) {
60 const ProjectionTransform rastertocamera_pre = kernel_data.cam.perspective_pre;
61 const float3 Pcamera_pre = transform_perspective(&rastertocamera_pre, raster);
62 Pcamera = interp(Pcamera_pre, Pcamera, ray->time * 2.0f);
63 }
64 else {
65 const ProjectionTransform rastertocamera_post = kernel_data.cam.perspective_post;
66 const float3 Pcamera_post = transform_perspective(&rastertocamera_post, raster);
67 Pcamera = interp(Pcamera, Pcamera_post, (ray->time - 0.5f) * 2.0f);
68 }
69 }
70
72 float3 D = Pcamera;
73
74 /* modify ray for depth of field */
75 const float aperturesize = kernel_data.cam.aperturesize;
76
77 if (aperturesize > 0.0f) {
78 /* sample point on aperture */
79 const float2 lens_uv = camera_sample_aperture(&kernel_data.cam, rand_lens) * aperturesize;
80
81 /* compute point on plane of focus */
82 const float ft = kernel_data.cam.focaldistance / D.z;
83 const float3 Pfocus = D * ft;
84
85 /* update ray for effect of lens */
86 P = make_float3(lens_uv);
87 D = normalize(Pfocus - P);
88 }
89
90 /* transform ray from camera to world */
91 Transform cameratoworld = kernel_data.cam.cameratoworld;
92
93 if (kernel_data.cam.num_motion_steps) {
95 kernel_data_array(camera_motion),
96 kernel_data.cam.num_motion_steps,
97 ray->time);
98 }
99
100 P = transform_point(&cameratoworld, P);
101 D = normalize(transform_direction(&cameratoworld, D));
102
103 const bool use_stereo = kernel_data.cam.interocular_offset != 0.0f;
104 if (!use_stereo) {
105 /* No stereo */
106 ray->P = P;
107 ray->D = D;
108
109#ifdef __RAY_DIFFERENTIALS__
110 const float3 Dcenter = transform_direction(&cameratoworld, Pcamera);
111 const float3 Dcenter_normalized = normalize(Dcenter);
112
113 /* TODO: can this be optimized to give compact differentials directly? */
114 ray->dP = differential_zero_compact();
115 differential3 dD;
116 dD.dx = normalize(Dcenter + make_float3(kernel_data.cam.dx)) - Dcenter_normalized;
117 dD.dy = normalize(Dcenter + make_float3(kernel_data.cam.dy)) - Dcenter_normalized;
118 ray->dD = differential_make_compact(dD) * kernel_data.cam.differential_scale;
119#endif
120 }
121 else {
122 /* Spherical stereo */
124 ray->P = P;
125 ray->D = D;
126
127#ifdef __RAY_DIFFERENTIALS__
128 /* Ray differentials, computed from scratch using the raster coordinates
129 * because we don't want to be affected by depth of field. We compute
130 * ray origin and direction for the center and two neighboring pixels
131 * and simply take their differences. */
132 const float3 Pnostereo = transform_point(&cameratoworld, zero_float3());
133
134 float3 Pcenter = Pnostereo;
135 float3 Dcenter = Pcamera;
136 Dcenter = normalize(transform_direction(&cameratoworld, Dcenter));
137 spherical_stereo_transform(&kernel_data.cam, &Pcenter, &Dcenter);
138
139 float3 Px = Pnostereo;
140 float3 Dx = transform_perspective(&rastertocamera,
141 make_float3(raster.x + 1.0f, raster.y, 0.0f));
142 Dx = normalize(transform_direction(&cameratoworld, Dx));
144
145 differential3 dP;
146 differential3 dD;
147
148 dP.dx = Px - Pcenter;
149 dD.dx = Dx - Dcenter;
150
151 float3 Py = Pnostereo;
152 float3 Dy = transform_perspective(&rastertocamera,
153 make_float3(raster.x, raster.y + 1.0f, 0.0f));
154 Dy = normalize(transform_direction(&cameratoworld, Dy));
156
157 dP.dy = Py - Pcenter;
158 dD.dy = Dy - Dcenter;
159 ray->dD = differential_make_compact(dD) * kernel_data.cam.differential_scale;
160 ray->dP = differential_make_compact(dP) * kernel_data.cam.differential_scale;
161#endif
162 }
163
164 /* clipping */
165 const float z_inv = 1.0f / normalize(Pcamera).z;
166 const float nearclip = kernel_data.cam.nearclip * z_inv;
167 ray->P += nearclip * ray->D;
168 ray->dP += nearclip * ray->dD;
169 ray->tmin = 0.0f;
170 ray->tmax = kernel_data.cam.cliplength * z_inv;
171
172 return one_spectrum();
173}
174
175/* Orthographic Camera */
177 const float2 raster_xy,
178 const float2 rand_lens,
179 ccl_private Ray *ray)
180{
181 /* create ray form raster position */
182 const ProjectionTransform rastertocamera = kernel_data.cam.rastertocamera;
183 const float3 Pcamera = transform_perspective(&rastertocamera, make_float3(raster_xy));
184
185 float3 P;
186 float3 D = make_float3(0.0f, 0.0f, 1.0f);
187
188 /* modify ray for depth of field */
189 const float aperturesize = kernel_data.cam.aperturesize;
190
191 if (aperturesize > 0.0f) {
192 /* sample point on aperture */
193 const float2 lens_uv = camera_sample_aperture(&kernel_data.cam, rand_lens) * aperturesize;
194
195 /* compute point on plane of focus */
196 const float3 Pfocus = D * kernel_data.cam.focaldistance;
197
198 /* Update ray for effect of lens */
199 const float3 lens_uvw = make_float3(lens_uv);
200
201 D = normalize(Pfocus - lens_uvw);
202 /* Compute position the ray will be if it traveled until it intersected the near clip plane.
203 * This allows for correct DOF while allowing near clipping. */
204 P = Pcamera + lens_uvw + (D * (kernel_data.cam.nearclip / D.z));
205 }
206 else {
207 P = Pcamera + make_float3(0.0f, 0.0f, kernel_data.cam.nearclip);
208 }
209 /* transform ray from camera to world */
210 Transform cameratoworld = kernel_data.cam.cameratoworld;
211
212 if (kernel_data.cam.num_motion_steps) {
214 kernel_data_array(camera_motion),
215 kernel_data.cam.num_motion_steps,
216 ray->time);
217 }
218
219 ray->P = transform_point(&cameratoworld, P);
220 ray->D = normalize(transform_direction(&cameratoworld, D));
221
222#ifdef __RAY_DIFFERENTIALS__
223 /* ray differential */
224 differential3 dP;
225 dP.dx = make_float3(kernel_data.cam.dx);
226 dP.dy = make_float3(kernel_data.cam.dy);
227
228 ray->dP = differential_make_compact(dP) * kernel_data.cam.differential_scale;
229 ray->dD = differential_zero_compact();
230#endif
231
232 /* clipping */
233 ray->tmin = 0.0f;
234 ray->tmax = kernel_data.cam.cliplength;
235
236 return one_spectrum();
237}
238
239/* Custom Camera */
240
242 const ccl_global DecomposedTransform *cam_motion,
243 float3 P,
244 float3 D,
246 float3 Pcenter,
247 float3 Dcenter,
248 float3 Px,
249 float3 Dx,
250 float3 Py,
251 float3 Dy,
252#endif
253 ccl_private Ray *ray)
254{
255 /* Transform the ray from camera to world. */
256 Transform cameratoworld = cam->cameratoworld;
257
258 if (cam->num_motion_steps) {
260 &cameratoworld, cam_motion, cam->num_motion_steps, ray->time);
261 }
262
263 /* Stereo transform */
264 const bool use_stereo = cam->interocular_offset != 0.0f;
265 if (use_stereo) {
267 }
268
269 P = transform_point(&cameratoworld, P);
270 D = normalize(transform_direction(&cameratoworld, D));
271
272 ray->P = P;
273 ray->D = D;
274
275#ifdef __RAY_DIFFERENTIALS__
276 if (use_stereo) {
277 spherical_stereo_transform(cam, &Pcenter, &Dcenter);
278 spherical_stereo_transform(cam, &Px, &Dx);
279 spherical_stereo_transform(cam, &Py, &Dy);
280
281 differential3 dP;
282 Pcenter = transform_point(&cameratoworld, Pcenter);
283 dP.dx = transform_point(&cameratoworld, Px) - Pcenter;
284 dP.dy = transform_point(&cameratoworld, Py) - Pcenter;
285 ray->dP = differential_make_compact(dP) * cam->differential_scale;
286 }
287 else {
288 ray->dP = differential_zero_compact();
289 }
290
291 differential3 dD;
292 Dcenter = normalize(transform_direction(&cameratoworld, Dcenter));
293 dD.dx = normalize(transform_direction(&cameratoworld, Dx)) - Dcenter;
294 dD.dy = normalize(transform_direction(&cameratoworld, Dy)) - Dcenter;
295 ray->dD = differential_make_compact(dD) * cam->differential_scale;
296#endif
297
298 /* clipping */
299 const float nearclip = cam->nearclip;
300 ray->P += nearclip * ray->D;
301 ray->dP += nearclip * ray->dD;
302 ray->tmin = 0.0f;
303 ray->tmax = cam->cliplength;
304}
305
308 const ccl_global DecomposedTransform *cam_motion,
309 const float2 raster,
310 const float2 rand_lens,
311 ccl_private Ray *ray,
312 ccl_private int &r_cache_miss)
313{
314#ifdef WITH_OSL
315 /* Transform raster position to camera space. */
316 const ProjectionTransform rastertocamera = cam->rastertocamera;
317 float3 sensor = transform_perspective(&rastertocamera, make_float3(raster.x, raster.y, 0.0f));
318 float3 dSdx = transform_perspective_direction(&rastertocamera, make_float3(1.0f, 0.0f, 0.0f));
319 float3 dSdy = transform_perspective_direction(&rastertocamera, make_float3(0.0f, 1.0f, 0.0f));
320
321 ShaderDataTinyStorage sd_storage = {};
322 ccl_private ShaderData *sd = AS_SHADER_DATA(&sd_storage);
323 sd->object = OBJECT_NONE;
324 sd->prim = PRIM_NONE;
325 sd->shader = SHADER_NONE;
326 sd->type = PRIMITIVE_NONE;
327 sd->runtime_flag = 0;
328 sd->shader_flag = 0;
329
330 /* Execute OSL shader to sample position, direction and transmission. */
331 packed_float3 P, dPdx, dPdy, D, dDdx, dDdy, throughput;
332 r_cache_miss = false;
333 throughput = osl_eval_camera(
334 kg, sd, sensor, dSdx, dSdy, rand_lens, P, dPdx, dPdy, D, dDdx, dDdy);
335 if (sd->runtime_flag & SR_CACHE_MISS) {
336 r_cache_miss = true;
337 return zero_spectrum();
338 }
339 /* Zero throughput indicates failed sampling. */
340 if (is_zero(throughput)) {
341 return zero_spectrum();
342 }
343
345 cam_motion,
346 P,
347 D,
349 P,
350 D,
351 P + dPdx,
352 D + dDdx,
353 P + dPdy,
354 D + dDdy,
355# endif
356 ray);
357
358 return throughput;
359#else
360 (void)kg;
361 (void)cam;
362 (void)cam_motion;
363 (void)raster;
364 (void)rand_lens;
365 (void)ray;
366 (void)r_cache_miss;
367 return zero_spectrum();
368#endif
369}
370
371/* Panorama Camera */
372
374 const float x,
375 const float y)
376{
377 const ProjectionTransform rastertocamera = cam->rastertocamera;
378 const float3 Pcamera = transform_perspective(&rastertocamera, make_float3(x, y, 0.0f));
379 return panorama_to_direction(cam, Pcamera.x, Pcamera.y);
380}
381
383 const ccl_global DecomposedTransform *cam_motion,
384 const float2 raster,
385 const float2 rand_lens,
386 ccl_private Ray *ray)
387{
388 /* Create ray from raster position. */
389 float3 P = zero_float3();
390 float3 D = camera_panorama_direction(cam, raster.x, raster.y);
391
392#ifdef __RAY_DIFFERENTIALS__
393 /* Ray differentials, computed from scratch using the raster coordinates
394 * because we don't want to be affected by depth of field. We compute
395 * ray origin and direction for the center and two neighboring pixels
396 * and simply take their differences. */
397 float3 Dcenter = D;
398 float3 Dx = camera_panorama_direction(cam, raster.x + 1.0f, raster.y);
399 float3 Dy = camera_panorama_direction(cam, raster.x, raster.y + 1.0f);
400#endif
401
402 /* Here, zero indicates failed sampling, e.g. when the raster position is outside
403 * the fisheye lens. */
404 if (is_zero(D)) {
405 return zero_spectrum();
406 }
407
408 /* Perform depth-of-field sampling. */
409 const float aperturesize = cam->aperturesize;
410
411 if (aperturesize > 0.0f) {
412 /* Sample a point on the aperture. */
413 const float2 lens_uv = camera_sample_aperture(cam, rand_lens) * aperturesize;
414
415 /* Compute the intersection of the original ray with the focal plane. */
416 const float3 Dfocus = normalize(D);
417 const float3 Pfocus = Dfocus * cam->focaldistance;
418
419 /* Calculate orthonormal coordinate system perpendicular to Dfocus. */
420 const float3 U = normalize(make_float3(1.0f, 0.0f, 0.0f) - Dfocus.x * Dfocus);
421 const float3 V = normalize(cross(Dfocus, U));
422
423 /* Compute new ray by shifting its origin (to account for aperture position) and
424 * setting its direction to meet the original ray at the focal plane. */
425 P = U * lens_uv.x + V * lens_uv.y;
426 D = normalize(Pfocus - P);
427 }
428
430 cam_motion,
431 P,
432 D,
434 zero_float3(),
435 Dcenter,
436 zero_float3(),
437 Dx,
438 zero_float3(),
439 Dy,
440#endif
441 ray);
442
443 return one_spectrum();
444}
445
446/* Common */
447
448/* Generates an outgoing camera ray for the given raster position and random inputs.
449 * Returns camera sensitivity (used to initialize path throughput). */
451 const int x,
452 const int y,
453 const float2 filter_uv,
454 const float time,
455 const float2 lens_uv,
456 ccl_private Ray *ray,
457 ccl_private int &r_cache_miss)
458{
459 float2 raster = make_float2(x, y);
460
461 /* pixel filter */
462 if (kernel_data.integrator.pixel_jitter.x == FLT_MAX) {
463 const int filter_table_offset = kernel_data.tables.filter_table_offset;
464 raster.x += lookup_table_read(kg, filter_uv.x, filter_table_offset, FILTER_TABLE_SIZE);
465 raster.y += lookup_table_read(kg, filter_uv.y, filter_table_offset, FILTER_TABLE_SIZE);
466 }
467 else {
468 raster += -kernel_data.integrator.pixel_jitter;
469 }
470
471 /* motion blur */
472 if (kernel_data.cam.shuttertime == -1.0f) {
473 ray->time = 0.5f;
474 }
475 else {
476 /* TODO(sergey): Such lookup is unneeded when there's rolling shutter
477 * effect in use but rolling shutter duration is set to 0.0.
478 */
479 const int shutter_table_offset = kernel_data.cam.shutter_table_offset;
480 ray->time = lookup_table_read(kg, time, shutter_table_offset, SHUTTER_TABLE_SIZE);
481 /* TODO(sergey): Currently single rolling shutter effect type only
482 * where scan-lines are acquired from top to bottom and whole scan-line
483 * is acquired at once (no delay in acquisition happens between pixels
484 * of single scan-line).
485 *
486 * Might want to support more models in the future.
487 */
488 if (kernel_data.cam.rolling_shutter_type) {
489 /* Time corresponding to a fully rolling shutter only effect:
490 * top of the frame is time 0.0, bottom of the frame is time 1.0.
491 */
492 const float time = 1.0f - (float)y / kernel_data.cam.height;
493 const float duration = kernel_data.cam.rolling_shutter_duration;
494 if (duration != 0.0f) {
495 /* This isn't fully physical correct, but lets us to have simple
496 * controls in the interface. The idea here is basically sort of
497 * linear interpolation between how much rolling shutter effect
498 * exist on the frame and how much of it is a motion blur effect.
499 */
500 ray->time = (ray->time - 0.5f) * duration;
501 ray->time += (time - 0.5f) * (1.0f - duration) + 0.5f;
502 }
503 else {
504 ray->time = time;
505 }
506 }
507 }
508
509 /* sample */
510 r_cache_miss = false;
511 if (kernel_data.cam.type == CAMERA_PERSPECTIVE) {
512 return camera_sample_perspective(kg, raster, lens_uv, ray);
513 }
514 if (kernel_data.cam.type == CAMERA_ORTHOGRAPHIC) {
515 return camera_sample_orthographic(kg, raster, lens_uv, ray);
516 }
517 if (kernel_data.cam.type == CAMERA_PANORAMA) {
518 const ccl_global DecomposedTransform *cam_motion = kernel_data_array(camera_motion);
519 return camera_sample_panorama(&kernel_data.cam, cam_motion, raster, lens_uv, ray);
520 }
521 if (kernel_data.cam.type == CAMERA_CUSTOM) {
522 const ccl_global DecomposedTransform *cam_motion = kernel_data_array(camera_motion);
524 kg, &kernel_data.cam, cam_motion, raster, lens_uv, ray, r_cache_miss);
525 }
526 kernel_assert(false);
527 return zero_spectrum();
528}
529
530/* Utilities */
531
533{
534 const Transform cameratoworld = kernel_data.cam.cameratoworld;
535 return make_float3(cameratoworld.x.w, cameratoworld.y.w, cameratoworld.z.w);
536}
537
539{
540 const Transform cameratoworld = kernel_data.cam.cameratoworld;
541 const float3 camP = make_float3(cameratoworld.x.w, cameratoworld.y.w, cameratoworld.z.w);
542
543 if (kernel_data.cam.type == CAMERA_ORTHOGRAPHIC) {
544 const float3 camD = make_float3(cameratoworld.x.z, cameratoworld.y.z, cameratoworld.z.z);
545 return fabsf(dot((P - camP), camD));
546 }
547 return len(P - camP);
548}
549
551{
552 if (kernel_data.cam.type == CAMERA_PERSPECTIVE || kernel_data.cam.type == CAMERA_ORTHOGRAPHIC) {
553 const Transform worldtocamera = kernel_data.cam.worldtocamera;
554 return transform_point(&worldtocamera, P).z;
555 }
556 const Transform cameratoworld = kernel_data.cam.cameratoworld;
557 const float3 camP = make_float3(cameratoworld.x.w, cameratoworld.y.w, cameratoworld.z.w);
558 return len(P - camP);
559}
560
562{
563 const Transform cameratoworld = kernel_data.cam.cameratoworld;
564
565 if (kernel_data.cam.type == CAMERA_ORTHOGRAPHIC) {
566 const float3 camD = make_float3(cameratoworld.x.z, cameratoworld.y.z, cameratoworld.z.z);
567 return -camD;
568 }
569 const float3 camP = make_float3(cameratoworld.x.w, cameratoworld.y.w, cameratoworld.z.w);
570 return normalize(camP - P);
571}
572
574 ccl_private ShaderData *sd,
575 float3 P)
576{
577 if (kernel_data.cam.type == CAMERA_PERSPECTIVE || kernel_data.cam.type == CAMERA_ORTHOGRAPHIC) {
578 /* perspective / ortho */
579 if (sd->object == PRIM_NONE && kernel_data.cam.type == CAMERA_PERSPECTIVE) {
580 P += camera_position(kg);
581 }
582
583 const ProjectionTransform tfm = kernel_data.cam.worldtondc;
584 return transform_perspective(&tfm, P);
585 }
586 /* panorama or custom */
587 const Transform tfm = kernel_data.cam.worldtocamera;
588
589 if (sd->object != OBJECT_NONE) {
590 P = normalize(transform_point(&tfm, P));
591 }
592 else {
594 }
595
596 if (kernel_data.cam.type == CAMERA_PANORAMA) {
598 }
599 /* TODO: Fall back to camera coordinates until we have inverse mappings for custom cameras. */
600 return P;
601}
602
603/* Motion vector for motion pass */
604
606 float3 motion_center,
607 float3 motion_pre,
608 float3 motion_post)
609{
610 Transform tfm;
611
612 /* camera motion, for perspective/orthographic motion.pre/post will be a
613 * world-to-raster matrix, for panorama it's world-to-camera, for custom
614 * we fall back to the world position until we have inverse mapping for it */
615 if (kernel_data.cam.type == CAMERA_CUSTOM) {
616 /* TODO: Custom cameras don't have inverse mappings yet, so we fall back to
617 * camera-space vectors here for now. */
618 tfm = kernel_data.cam.worldtocamera;
619 motion_center = normalize(transform_point(&tfm, motion_center));
620
621 tfm = kernel_data.cam.motion_pass_pre;
622 motion_pre = normalize(transform_point(&tfm, motion_pre));
623
624 tfm = kernel_data.cam.motion_pass_post;
625 motion_post = normalize(transform_point(&tfm, motion_post));
626 }
627 else if (kernel_data.cam.type != CAMERA_PANORAMA) {
628 /* Perspective and orthographics camera use the world-to-raster matrix. */
629 ProjectionTransform projection = kernel_data.cam.worldtoraster;
630 motion_center = transform_perspective(&projection, motion_center);
631
632 projection = kernel_data.cam.perspective_pre;
633 motion_pre = transform_perspective(&projection, motion_pre);
634
635 projection = kernel_data.cam.perspective_post;
636 motion_post = transform_perspective(&projection, motion_post);
637 }
638 else {
639 /* Panorama cameras have their own inverse mappings. */
640 tfm = kernel_data.cam.worldtocamera;
641 motion_center = normalize(transform_point(&tfm, motion_center));
642 motion_center = make_float3(direction_to_panorama(&kernel_data.cam, motion_center));
643 motion_center.x *= kernel_data.cam.width;
644 motion_center.y *= kernel_data.cam.height;
645
646 tfm = kernel_data.cam.motion_pass_pre;
647 motion_pre = normalize(transform_point(&tfm, motion_pre));
648 motion_pre = make_float3(direction_to_panorama(&kernel_data.cam, motion_pre));
649 motion_pre.x *= kernel_data.cam.width;
650 motion_pre.y *= kernel_data.cam.height;
651
652 tfm = kernel_data.cam.motion_pass_post;
653 motion_post = normalize(transform_point(&tfm, motion_post));
654 motion_post = make_float3(direction_to_panorama(&kernel_data.cam, motion_post));
655 motion_post.x *= kernel_data.cam.width;
656 motion_post.y *= kernel_data.cam.height;
657 }
658
659 motion_pre = motion_pre - motion_center;
660 motion_post = motion_center - motion_post;
661
662 return make_float4(motion_pre.x, motion_pre.y, motion_post.x, motion_post.y);
663}
664
666 const float3 P,
667 const float3 D)
668{
669 Transform tfm;
670 float3 motion_center;
671 float3 motion_pre;
672 float3 motion_post;
673
674 /* Camera motion, for perspective/orthographic motion.pre/post will be a
675 * world-to-raster matrix, for panorama it's world-to-camera, for custom
676 * we fall back to the world position until we have inverse mapping for it */
677 if (kernel_data.cam.type == CAMERA_CUSTOM) {
678 /* TODO: Custom cameras don't have inverse mappings yet, so we fall back to
679 * camera-space vectors here for now. */
680 tfm = kernel_data.cam.worldtocamera;
681 motion_center = normalize(transform_direction(&tfm, D));
682
683 tfm = kernel_data.cam.motion_pass_pre;
684 motion_pre = normalize(transform_direction(&tfm, D));
685
686 tfm = kernel_data.cam.motion_pass_post;
687 motion_post = normalize(transform_direction(&tfm, D));
688 }
689 else if (kernel_data.cam.type == CAMERA_ORTHOGRAPHIC) {
690 /* For one orthographic camera matrix, all rays meet at the same point at infinity. When
691 * rotating the camera, the motion vectors become infinite. To get reasonable values for both
692 * translation/zoom and rotation, we use points far away:
693 * - Rotation produces very large motion vectors pointing to outside the image, leading to
694 * rejection of the history.
695 * - Translation/zoom produce valid background motion vectors. */
696 float3 point_far = P + D * 1e4f;
697
698 ProjectionTransform projection = kernel_data.cam.worldtoraster;
699 motion_center = transform_perspective(&projection, point_far);
700
701 projection = kernel_data.cam.perspective_pre;
702 motion_pre = transform_perspective(&projection, point_far);
703
704 projection = kernel_data.cam.perspective_post;
705 motion_post = transform_perspective(&projection, point_far);
706 }
707 else if (kernel_data.cam.type != CAMERA_PANORAMA) {
708 /* Perspective and orthographics camera use the world-to-raster matrix. */
709 ProjectionTransform projection = kernel_data.cam.worldtoraster;
710 motion_center = transform_perspective_direction(&projection, D);
711
712 projection = kernel_data.cam.perspective_pre;
713 motion_pre = transform_perspective_direction(&projection, D);
714
715 projection = kernel_data.cam.perspective_post;
716 motion_post = transform_perspective_direction(&projection, D);
717 }
718 else {
719 /* Panorama cameras have their own inverse mappings. */
720 tfm = kernel_data.cam.worldtocamera;
721 motion_center = normalize(transform_direction(&tfm, D));
722 motion_center = make_float3(direction_to_panorama(&kernel_data.cam, motion_center));
723 motion_center.x *= kernel_data.cam.width;
724 motion_center.y *= kernel_data.cam.height;
725
726 tfm = kernel_data.cam.motion_pass_pre;
727 motion_pre = normalize(transform_direction(&tfm, D));
728 motion_pre = make_float3(direction_to_panorama(&kernel_data.cam, motion_pre));
729 motion_pre.x *= kernel_data.cam.width;
730 motion_pre.y *= kernel_data.cam.height;
731
732 tfm = kernel_data.cam.motion_pass_post;
733 motion_post = normalize(transform_direction(&tfm, D));
734 motion_post = make_float3(direction_to_panorama(&kernel_data.cam, motion_post));
735 motion_post.x *= kernel_data.cam.width;
736 motion_post.y *= kernel_data.cam.height;
737 }
738
739 motion_pre = motion_pre - motion_center;
740 motion_post = motion_center - motion_post;
741
742 return make_float4(motion_pre.x, motion_pre.y, motion_post.x, motion_post.y);
743}
744
#define D
#define U
ccl_device_inline float2 direction_to_panorama(ccl_constant KernelCamera *cam, const float3 dir)
ccl_device_inline void spherical_stereo_transform(ccl_constant KernelCamera *cam, ccl_private float3 *P, ccl_private float3 *D)
ccl_device_inline float3 panorama_to_direction(ccl_constant KernelCamera *cam, const float u, float v)
ccl_device_forceinline float3 dPdx(const ccl_private ShaderData *sd)
ccl_device_forceinline float3 dPdy(const ccl_private ShaderData *sd)
ccl_device_inline float3 transform_perspective_direction(const ccl_private ProjectionTransform *t, const float3 a)
CCL_NAMESPACE_END CCL_NAMESPACE_BEGIN ccl_device_inline float3 transform_perspective(const ccl_private ProjectionTransform *t, const float3 a)
#define kernel_assert(cond)
#define kernel_data
#define ccl_device_forceinline
#define AS_SHADER_DATA(shader_data_tiny_storage)
#define SHADER_NONE
#define one_spectrum
#define FILTER_TABLE_SIZE
#define PRIM_NONE
#define ccl_constant
#define zero_spectrum
#define OBJECT_NONE
#define ccl_private
#define ccl_device_inline
#define __RAY_DIFFERENTIALS__
#define SHUTTER_TABLE_SIZE
#define ccl_global
#define kernel_data_array(name)
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
ccl_device_forceinline float differential_make_compact(const float dD)
ccl_device_forceinline float differential_zero_compact()
#define FLT_MAX
VecBase< float, D > normalize(VecOp< float, D >) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
bool is_zero(float3x3 a)
float3 transform_direction(float3x3 mat, float3 direction)
float3 transform_point(float3x3 mat, float3 point)
ccl_device_forceinline float4 camera_motion_vector_direction(KernelGlobals kg, const float3 P, const float3 D)
ccl_device_inline Spectrum camera_sample(KernelGlobals kg, const int x, const int y, const float2 filter_uv, const float time, const float2 lens_uv, ccl_private Ray *ray, ccl_private int &r_cache_miss)
ccl_device_inline void camera_sample_to_ray(ccl_constant KernelCamera *cam, const ccl_global DecomposedTransform *cam_motion, float3 P, float3 D, ccl_private Ray *ray)
CCL_NAMESPACE_BEGIN ccl_device float2 camera_sample_aperture(ccl_constant KernelCamera *cam, const float2 rand)
ccl_device Spectrum camera_sample_perspective(KernelGlobals kg, const float2 raster_xy, const float2 rand_lens, ccl_private Ray *ray)
ccl_device_inline float3 camera_position(KernelGlobals kg)
ccl_device_inline float3 camera_panorama_direction(ccl_constant KernelCamera *cam, const float x, const float y)
ccl_device_inline Spectrum camera_sample_panorama(ccl_constant KernelCamera *cam, const ccl_global DecomposedTransform *cam_motion, const float2 raster, const float2 rand_lens, ccl_private Ray *ray)
ccl_device_inline float camera_z_depth(KernelGlobals kg, const float3 P)
ccl_device_inline float3 camera_world_to_ndc(KernelGlobals kg, ccl_private ShaderData *sd, float3 P)
ccl_device_forceinline float4 camera_motion_vector(KernelGlobals kg, float3 motion_center, float3 motion_pre, float3 motion_post)
ccl_device_inline float camera_distance(KernelGlobals kg, const float3 P)
ccl_device Spectrum camera_sample_orthographic(KernelGlobals kg, const float2 raster_xy, const float2 rand_lens, ccl_private Ray *ray)
ccl_device_inline float3 camera_direction_from_point(KernelGlobals kg, const float3 P)
ccl_device_inline Spectrum camera_sample_custom(KernelGlobals kg, ccl_constant KernelCamera *cam, const ccl_global DecomposedTransform *cam_motion, const float2 raster, const float2 rand_lens, ccl_private Ray *ray, ccl_private int &r_cache_miss)
packed_float3 osl_eval_camera(KernelGlobals kg, ccl_private ShaderData *sd, const packed_float3 sensor, const packed_float3 dSdx, const packed_float3 dSdy, const float2 rand_lens, packed_float3 &P, packed_float3 &dPdx, packed_float3 &dPdy, packed_float3 &D, packed_float3 &dDdx, packed_float3 &dDdy)
@ SR_CACHE_MISS
@ PRIMITIVE_NONE
ShaderData ShaderDataTinyStorage
@ CAMERA_PERSPECTIVE
@ CAMERA_PANORAMA
@ CAMERA_CUSTOM
@ CAMERA_ORTHOGRAPHIC
CCL_NAMESPACE_BEGIN ccl_device float lookup_table_read(KernelGlobals kg, float x, const int offset, const int size)
ccl_device_inline float interp(const float a, const float b, const float t)
Definition math_base.h:549
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
Definition math_float3.h:17
#define fabsf
#define ccl_device
#define make_float2
#define make_float4
CCL_NAMESPACE_BEGIN ccl_device float2 sample_uniform_disk(const float2 rand)
ccl_device float2 regular_polygon_sample(const float corners, float rotation, const float2 rand)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
float4 y
Definition transform.h:53
float4 x
Definition transform.h:53
float4 z
Definition transform.h:53
float x
float y
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136
float z
Definition sky_math.h:225
float w
Definition sky_math.h:225
ccl_device void transform_motion_array_interpolate(ccl_private Transform *tfm, const ccl_global DecomposedTransform *motion, const int numsteps, const float time)
Definition transform.h:629
float3 Spectrum
CCL_NAMESPACE_BEGIN struct Window V