32 if (shutter_curve.
size() == 0) {
38 float frac = x - index;
39 if (index < shutter_curve.
size() - 1) {
40 return mix(shutter_curve[index], shutter_curve[index + 1],
frac);
43 return shutter_curve[shutter_curve.
size() - 1];
53 static NodeEnum motion_position_enum;
59 static NodeEnum rolling_shutter_type_enum;
60 rolling_shutter_type_enum.
insert(
"none", ROLLING_SHUTTER_NONE);
61 rolling_shutter_type_enum.
insert(
"top", ROLLING_SHUTTER_TOP);
63 "Rolling Shutter Type",
64 rolling_shutter_type_enum,
65 ROLLING_SHUTTER_NONE);
66 SOCKET_FLOAT(rolling_shutter_duration,
"Rolling Shutter Duration", 0.1f);
106 SOCKET_FLOAT(fisheye_polynomial_k0,
"Fisheye Polynomial K0", 0.0f);
107 SOCKET_FLOAT(fisheye_polynomial_k1,
"Fisheye Polynomial K1", 0.0f);
108 SOCKET_FLOAT(fisheye_polynomial_k2,
"Fisheye Polynomial K2", 0.0f);
109 SOCKET_FLOAT(fisheye_polynomial_k3,
"Fisheye Polynomial K3", 0.0f);
110 SOCKET_FLOAT(fisheye_polynomial_k4,
"Fisheye Polynomial K4", 0.0f);
112 SOCKET_FLOAT(central_cylindrical_range_u_min,
"Central Cylindrical Range U Min", -
M_PI_F);
113 SOCKET_FLOAT(central_cylindrical_range_u_max,
"Central Cylindrical Range U Max",
M_PI_F);
114 SOCKET_FLOAT(central_cylindrical_range_v_min,
"Central Cylindrical Range V Min", -1.0f);
115 SOCKET_FLOAT(central_cylindrical_range_v_max,
"Central Cylindrical Range V Max", 1.0f);
118 stereo_eye_enum.
insert(
"none", STEREO_NONE);
119 stereo_eye_enum.
insert(
"left", STEREO_LEFT);
120 stereo_eye_enum.
insert(
"right", STEREO_RIGHT);
121 SOCKET_ENUM(stereo_eye,
"Stereo Eye", stereo_eye_enum, STEREO_NONE);
123 SOCKET_BOOLEAN(use_spherical_stereo,
"Use Spherical Stereo",
false);
125 SOCKET_FLOAT(interocular_distance,
"Interocular Distance", 0.065f);
126 SOCKET_FLOAT(convergence_distance,
"Convergence Distance", 30.0f * 0.065f);
129 SOCKET_FLOAT(pole_merge_angle_from,
"Pole Merge Angle From", 60.0f *
M_PI_F / 180.0f);
148 SOCKET_FLOAT(viewport_camera_border.left,
"Viewport Border Left", 0);
149 SOCKET_FLOAT(viewport_camera_border.right,
"Viewport Border Right", 0);
150 SOCKET_FLOAT(viewport_camera_border.bottom,
"Viewport Border Bottom", 0);
151 SOCKET_FLOAT(viewport_camera_border.top,
"Viewport Border Top", 0);
153 SOCKET_FLOAT(offscreen_dicing_scale,
"Offscreen Dicing Scale", 1.0f);
158 SOCKET_BOOLEAN(use_perspective_motion,
"Use Perspective Motion",
false);
170 use_perspective_motion =
false;
173 for (
int i = 0; i < shutter_curve.size(); ++i) {
174 shutter_curve[i] = 1.0f;
209 float aspect = (
float)full_width / (
float)full_height;
210 if (full_width >= full_height) {
241 if (scene->update_stats) {
242 scene->update_stats->camera.times.add_entry({
"update", time});
257 Transform screentoraster = ndctoraster * screentondc;
259 Transform full_screentoraster = full_ndctoraster * screentondc;
276 rastertocamera = screentocamera * rastertoscreen;
277 full_rastertocamera = screentocamera * full_rastertoscreen;
279 cameratoworld = matrix;
280 screentoworld = cameratoworld * screentocamera;
281 rastertoworld = cameratoworld * rastertocamera;
282 ndctoworld = rastertoworld * ndctoraster;
288 worldtoscreen = cameratoscreen * worldtocamera;
289 worldtondc = screentondc * worldtoscreen;
290 worldtoraster = ndctoraster * worldtondc;
347 kernel_camera_motion.clear();
350 bool have_motion =
false;
351 for (
size_t i = 0; i < motion.size(); i++) {
352 have_motion = have_motion || motion[i] != matrix;
367 if (have_motion || fov != fov_pre || fov != fov_post) {
372 fov_pre, nearclip, farclip);
374 fov_post, nearclip, farclip);
389 kernel_camera_motion.resize(motion.size());
410 kcam->
blades = (blades < 3) ? 0.0f : blades;
418 kcam->
type = camera_type;
429 latitude_min - latitude_max,
433 fisheye_polynomial_k1, fisheye_polynomial_k2, fisheye_polynomial_k3, fisheye_polynomial_k4);
435 -central_cylindrical_range_u_max,
436 central_cylindrical_range_v_min,
437 central_cylindrical_range_v_max);
439 switch (stereo_eye) {
453 if (use_pole_merge) {
487 need_device_update =
true;
488 need_flags_update =
true;
489 previous_need_motion = need_motion;
501 if (scene->update_stats) {
502 scene->update_stats->camera.times.add_entry({
"device_update", time});
506 scene->lookup_tables->remove_table(&shutter_table_offset);
507 if (kernel_camera.shuttertime != -1.0f) {
515 shutter_table_offset = scene->lookup_tables->add_table(dscene, shutter_table);
516 kernel_camera.shutter_table_offset = (
int)shutter_table_offset;
519 dscene->data.cam = kernel_camera;
521 size_t num_motion_steps = kernel_camera_motion.size();
522 if (num_motion_steps) {
524 memcpy(camera_motion, kernel_camera_motion.data(),
sizeof(*camera_motion) * num_motion_steps);
525 dscene->camera_motion.copy_to_device();
528 dscene->camera_motion.free();
538 KernelIntegrator *kintegrator = &dscene->
data.integrator;
539 if (kintegrator->use_volumes) {
545 static const int OBJECTS_PER_TASK = 32;
546 parallel_for(blocked_range<size_t>(0, scene->objects.size(), OBJECTS_PER_TASK),
547 [&](
const blocked_range<size_t> &r) {
548 for (size_t i = r.begin(); i != r.end(); i++) {
549 Object *object = scene->objects[i];
550 if (object->get_geometry()->has_volume &&
551 viewplane_boundbox.intersects(object->bounds)) {
553 VLOG_INFO <<
"Detected camera inside volume.";
554 kcam->is_inside_volume = 1;
555 parallel_for_cancel();
562 VLOG_INFO <<
"Camera is outside of the volume.";
566 need_device_update =
false;
567 need_flags_update =
false;
576float3 Camera::transform_raster_to_world(
float raster_x,
float raster_y)
590 P += nearclip * D / Pclip.
z;
600 assert(!
"unsupported camera type");
611 const float max_aperture_size = aperture_ratio < 1.0f ? aperturesize / aperture_ratio :
615 const float extend = max_aperture_size + nearclip;
616 if (use_spherical_stereo ==
false) {
620 float half_eye_distance = interocular_distance * 0.5f;
661 const float scaled_horz_dof_ray = (max_aperture_size > 0.0f) ?
662 max_aperture_size * (nearclip / focaldistance) :
664 const float extend = max_aperture_size +
max(nearclip, scaled_horz_dof_ray);
666 bounds.grow(transform_raster_to_world(0.0f, 0.0f), extend);
667 bounds.grow(transform_raster_to_world(0.0f, (
float)height), extend);
668 bounds.grow(transform_raster_to_world((
float)width, (
float)height), extend);
669 bounds.grow(transform_raster_to_world((
float)width, 0.0f), extend);
674 bounds.grow(transform_raster_to_world(0.5f * width, 0.5f * height), extend);
687 if (offscreen_dicing_scale > 1.0f) {
697 c.
z =
max(0.0f, p.
z);
700 float f_dist =
len(p - c) /
sqrtf((v1.
x * v1.
x + v1.
y * v1.
y) * 0.5f);
706 res += res * f_dist * (offscreen_dicing_scale - 1.0f);
723 res =
len(dist * dDdx -
dot(dist * dDdx, D) * D);
729 if (offscreen_dicing_scale > 1.0f) {
738 if (r <= 0.0f &&
l <= 0.0f && t <= 0.0f &&
b <= 0.0f) {
742 else if (r > 0.0f &&
l > 0.0f && t > 0.0f &&
b > 0.0f) {
753 float dist[] = {r,
l, t,
b};
754 float3 along[] = {along_right, along_left, along_top, along_bottom};
760 for (
int i = 0; i < 4; i++, d++, a++) {
763 if (
dot(p, *a) >= 0.0f) {
765 f_dist =
max(f_dist, *d);
776 f_dist = (f_dist > 0) ?
min(f_dist,
len(p)) :
len(p);
781 res +=
len(dDdx -
dot(dDdx, D) * D) * f_dist * (offscreen_dicing_scale - 1.0f);
790 memset(&ray, 0,
sizeof(ray));
827 return motion.size() > 1;
832 if (width_ != width || height_ != height) {
841 return (
use_motion()) ? 2.0f * step / (motion.size() - 1) - 1.0f : 0.0f;
847 for (
int step = 0; step < motion.size(); step++) {
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMLoop * l
ATTR_WARN_UNUSED_RESULT const BMVert * v
static btDbvtVolume bounds(btDbvtNode **leaves, int count)
SIMD_FORCE_INLINE btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
device_vector< DecomposedTransform > camera_motion
local_group_size(16, 16) .push_constant(Type b
additional_info("compositor_sum_squared_difference_float_shared") .push_constant(Type output_img float dot(value.rgb, luminance_coefficients)") .define("LOAD(value)"
ccl_device_inline float2 direction_to_panorama(ccl_constant KernelCamera *cam, float3 dir)
CCL_NAMESPACE_BEGIN ccl_device_inline float frac(float x, ccl_private int *ix)
ccl_device_inline float3 transform_perspective(ccl_private const ProjectionTransform *t, const float3 a)
ccl_device_inline ProjectionTransform projection_perspective(float fov, float n, float f)
ccl_device_inline float3 transform_perspective_direction(ccl_private const ProjectionTransform *t, const float3 a)
ccl_device_inline ProjectionTransform projection_identity()
ProjectionTransform projection_inverse(const ProjectionTransform &a)
ccl_device_inline ProjectionTransform projection_orthographic(float znear, float zfar)
#define CCL_NAMESPACE_END
ccl_device_forceinline float differential_transfer_compact(const float ray_dP, const float3, const float ray_dD, const float ray_t)
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
ccl_device_inline void camera_sample_panorama(ccl_constant KernelCamera *cam, ccl_global const DecomposedTransform *cam_motion, const float2 raster, const float2 rand_lens, ccl_private Ray *ray)
#define SHUTTER_TABLE_SIZE
@ PANORAMA_FISHEYE_EQUISOLID
@ PANORAMA_CENTRAL_CYLINDRICAL
@ PANORAMA_EQUIANGULAR_CUBEMAP_FACE
@ PANORAMA_FISHEYE_EQUIDISTANT
@ PANORAMA_FISHEYE_LENS_POLYNOMIAL
@ PANORAMA_EQUIRECTANGULAR
void util_cdf_inverted(const int resolution, const float from, const float to, Functor functor, const bool make_symmetric, vector< float > &inv_cdf)
CCL_NAMESPACE_BEGIN ccl_device_inline float2 zero_float2()
ccl_device_inline float len_squared(const float2 a)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
#define SOCKET_FLOAT(name, ui_name, default_value,...)
#define SOCKET_INT(name, ui_name, default_value,...)
#define SOCKET_FLOAT_ARRAY(name, ui_name, default_value,...)
#define SOCKET_TRANSFORM(name, ui_name, default_value,...)
#define SOCKET_UINT(name, ui_name, default_value,...)
#define NODE_DEFINE(structname)
#define SOCKET_TRANSFORM_ARRAY(name, ui_name, default_value,...)
#define SOCKET_BOOLEAN(name, ui_name, default_value,...)
#define SOCKET_ENUM(name, ui_name, values, default_value,...)
static CCL_NAMESPACE_BEGIN float shutter_curve_eval(float x, array< float > &shutter_curve)
ProjectionTransform worldtoraster
float3 frustum_right_normal
void set_screen_size(int width_, int height_)
ProjectionTransform rastertoworld
BoundBox viewplane_bounds_get()
float motion_time(int step) const
void update(Scene *scene)
ProjectionTransform rastertocamera
ProjectionTransform screentoworld
size_t shutter_table_offset
void device_update_volume(Device *device, DeviceScene *dscene, Scene *scene)
void device_free(Device *device, DeviceScene *dscene, Scene *scene)
ProjectionTransform ndctoworld
void device_update(Device *device, DeviceScene *dscene, Scene *scene)
float3 frustum_left_normal
float world_to_raster_size(float3 P)
int motion_step(float time) const
void compute_auto_viewplane()
float3 frustum_top_normal
ProjectionTransform full_rastertocamera
float3 frustum_bottom_normal
KernelCamera kernel_camera
array< DecomposedTransform > kernel_camera_motion
ProjectionTransform ndctoworld
float pole_merge_angle_to
int have_perspective_motion
ProjectionTransform rastertocamera
float pole_merge_angle_from
float4 central_cylindrical_range
ProjectionTransform worldtoraster
float fisheye_lens_polynomial_bias
Transform motion_pass_post
float4 equirectangular_range
ProjectionTransform screentoworld
ProjectionTransform perspective_post
float rolling_shutter_duration
ProjectionTransform perspective_pre
ProjectionTransform worldtoscreen
Transform motion_pass_pre
ProjectionTransform worldtondc
float convergence_distance
ProjectionTransform rastertoworld
float4 fisheye_lens_polynomial_coefficients
void insert(const char *x, int y)
static NodeType * add(const char *name, CreateFunc create, Type type=NONE, const NodeType *base=NULL)
ccl_device_inline float4 float3_to_float4(const float3 a)