28#define FIX_CUSTOM_CAMERA_CRASH
34 if (shutter_curve.
size() == 0) {
44 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);
107 SOCKET_FLOAT(fisheye_polynomial_k0,
"Fisheye Polynomial K0", 0.0f);
108 SOCKET_FLOAT(fisheye_polynomial_k1,
"Fisheye Polynomial K1", 0.0f);
109 SOCKET_FLOAT(fisheye_polynomial_k2,
"Fisheye Polynomial K2", 0.0f);
110 SOCKET_FLOAT(fisheye_polynomial_k3,
"Fisheye Polynomial K3", 0.0f);
111 SOCKET_FLOAT(fisheye_polynomial_k4,
"Fisheye Polynomial K4", 0.0f);
113 SOCKET_FLOAT(central_cylindrical_range_u_min,
"Central Cylindrical Range U Min", -
M_PI_F);
114 SOCKET_FLOAT(central_cylindrical_range_u_max,
"Central Cylindrical Range U Max",
M_PI_F);
115 SOCKET_FLOAT(central_cylindrical_range_v_min,
"Central Cylindrical Range V Min", -1.0f);
116 SOCKET_FLOAT(central_cylindrical_range_v_max,
"Central Cylindrical Range V Max", 1.0f);
119 stereo_eye_enum.
insert(
"none", STEREO_NONE);
120 stereo_eye_enum.
insert(
"left", STEREO_LEFT);
121 stereo_eye_enum.
insert(
"right", STEREO_RIGHT);
122 SOCKET_ENUM(stereo_eye,
"Stereo Eye", stereo_eye_enum, STEREO_NONE);
124 SOCKET_BOOLEAN(use_spherical_stereo,
"Use Spherical Stereo",
false);
126 SOCKET_FLOAT(interocular_distance,
"Interocular Distance", 0.065f);
127 SOCKET_FLOAT(convergence_distance,
"Convergence Distance", 30.0f * 0.065f);
130 SOCKET_FLOAT(pole_merge_angle_from,
"Pole Merge Angle From", 60.0f *
M_PI_F / 180.0f);
144 SOCKET_FLOAT(viewplane_pre.left,
"Viewplane Pre Left", 0);
145 SOCKET_FLOAT(viewplane_pre.right,
"Viewplane Pre Right", 0);
146 SOCKET_FLOAT(viewplane_pre.bottom,
"Viewplane Pre Bottom", 0);
147 SOCKET_FLOAT(viewplane_pre.top,
"Viewplane Pre Top", 0);
149 SOCKET_FLOAT(viewplane_post.left,
"Viewplane Post Left", 0);
150 SOCKET_FLOAT(viewplane_post.right,
"Viewplane Post Right", 0);
151 SOCKET_FLOAT(viewplane_post.bottom,
"Viewplane Post Bottom", 0);
152 SOCKET_FLOAT(viewplane_post.top,
"Viewplane Post Top", 0);
160 SOCKET_FLOAT(border_pre_bottom,
"Border Pre Bottom", -1);
162 SOCKET_FLOAT(viewport_camera_border.left,
"Viewport Border Left", 0);
163 SOCKET_FLOAT(viewport_camera_border.right,
"Viewport Border Right", 1);
164 SOCKET_FLOAT(viewport_camera_border.bottom,
"Viewport Border Bottom", 0);
165 SOCKET_FLOAT(viewport_camera_border.top,
"Viewport Border Top", 1);
167 SOCKET_FLOAT(offscreen_dicing_scale,
"Offscreen Dicing Scale", 1.0f);
172 SOCKET_BOOLEAN(use_perspective_motion,
"Use Perspective Motion",
false);
181 use_perspective_motion =
false;
184 for (
int i = 0; i < shutter_curve.size(); ++i) {
185 shutter_curve[i] = 1.0f;
217 const float aspect = (
float)full_width / (
float)full_height;
218 if (full_width >= full_height) {
244 scene->
update_stats->camera.times.add_entry({
"update", time});
259 const Transform screentoraster = ndctoraster * screentondc;
261 const Transform full_screentoraster = full_ndctoraster * screentondc;
281#ifdef FIX_CUSTOM_CAMERA_CRASH
320#ifdef FIX_CUSTOM_CAMERA_CRASH
337#ifdef FIX_CUSTOM_CAMERA_CRASH
372 bool have_motion =
false;
373 for (
size_t i = 0; i < motion.size(); i++) {
374 have_motion = have_motion || motion[i] != matrix;
389 if (border_pre_left >= 0 && border_pre_bottom >= 0) {
392 motion_viewplane_pre = motion_viewplane_pre.
offset(
397 if (have_motion || fov != fov_pre || fov != fov_post ||
viewplane != motion_viewplane_pre ||
410 const Transform screentoraster_pre = ndctoraster * fulltoborder *
412 const Transform screentoraster_post = ndctoraster * fulltoborder *
456 kcam->
blades = (blades < 3) ? 0.0f : blades;
464 kcam->
type = camera_type;
475 latitude_min - latitude_max,
479 fisheye_polynomial_k1, fisheye_polynomial_k2, fisheye_polynomial_k3, fisheye_polynomial_k4);
481 -central_cylindrical_range_u_max,
482 central_cylindrical_range_v_min,
483 central_cylindrical_range_v_max);
485 switch (stereo_eye) {
499 if (use_pole_merge) {
542 if (!motion.
empty()) {
569 scene->
update_stats->camera.times.add_entry({
"device_update", time});
590 if (num_motion_steps) {
608 KernelIntegrator *kintegrator = &dscene->
data.integrator;
609 if (kintegrator->use_volumes) {
612 LOG_INFO <<
"Considering custom camera to be inside volume.";
619 static const int OBJECTS_PER_TASK = 32;
620 parallel_for(blocked_range<size_t>(0, scene->
objects.
size(), OBJECTS_PER_TASK),
621 [&](
const blocked_range<size_t> &r) {
622 for (size_t i = r.begin(); i != r.end(); i++) {
623 Object *object = scene->objects[i];
624 if (object->get_geometry()->has_volume &&
625 viewplane_boundbox.intersects(object->bounds))
628 LOG_INFO <<
"Detected camera inside volume.";
629 kernel_camera.is_inside_volume = 1;
630 parallel_for_cancel();
637 LOG_INFO <<
"Camera is outside of the volume.";
654float3 Camera::transform_full_raster_to_world(
const float raster_x,
const float raster_y)
669 P += nearclip *
D / Pclip.
z;
679 assert(!
"unsupported camera type");
690 const float max_aperture_size = aperture_ratio < 1.0f ? aperturesize / aperture_ratio :
694 const float extend = max_aperture_size + nearclip;
695 if (use_spherical_stereo ==
false) {
699 const float half_eye_distance = interocular_distance * 0.5f;
740 const float scaled_horz_dof_ray = (max_aperture_size > 0.0f) ?
741 max_aperture_size * (nearclip / focaldistance) :
743 const float extend = max_aperture_size +
max(nearclip, scaled_horz_dof_ray);
745 bounds.
grow(transform_full_raster_to_world(0.0f, 0.0f), extend);
746 bounds.
grow(transform_full_raster_to_world(0.0f, (
float)full_height), extend);
747 bounds.
grow(transform_full_raster_to_world((
float)full_width, (
float)full_height), extend);
748 bounds.
grow(transform_full_raster_to_world((
float)full_width, 0.0f), extend);
753 bounds.
grow(transform_full_raster_to_world(0.5f * full_width, 0.5f * full_height), extend);
766 if (offscreen_dicing_scale > 1.0f) {
776 c.
z =
max(0.0f, p.
z);
779 float f_dist =
len(p - c) /
sqrtf((v1.
x * v1.
x + v1.
y * v1.
y) * 0.5f);
782 f_dist =
len(p - c) /
sqrtf((v2.x * v2.x + v2.y * v2.y) * 0.5f);
785 res += res * f_dist * (offscreen_dicing_scale - 1.0f);
789#ifdef FIX_CUSTOM_CAMERA_CRASH
806 res =
len(dist * dDdx -
dot(dist * dDdx,
D) *
D);
812 if (offscreen_dicing_scale > 1.0f) {
821 if (r <= 0.0f && l <= 0.0f && t <= 0.0f &&
b <= 0.0f) {
825 else if (r > 0.0f && l > 0.0f && t > 0.0f &&
b > 0.0f) {
838 float dist[] = {r, l, t,
b};
839 float3 along[] = {along_right, along_left, along_top, along_bottom};
845 for (
int i = 0; i < 4; i++, d++, a++) {
848 if (
dot(p, *a) >= 0.0f) {
850 f_dist =
max(f_dist, *d);
861 f_dist = (f_dist > 0) ?
min(f_dist,
len(p)) :
len(p);
866 res +=
len(dDdx -
dot(dDdx,
D) *
D) * f_dist * (offscreen_dicing_scale - 1.0f);
872 const float dist =
len(
D);
923 return motion.
size() > 1;
928 if (width_ != width || height_ != height) {
940 return (
use_motion()) ? 2.0f *
step / (motion.size() - 1) - 1.0f : 0.0f;
958 const std::string &filepath,
959 const std::string &bytecode_hash,
960 const std::string &bytecode)
969 if (!filepath.empty()) {
975 hash = scene->
osl_manager->shader_load_bytecode(bytecode_hash, bytecode);
979 bool changed =
false;
993 std::set<ustring> used_params;
994 for (
int i = 0; i < info->query.nparams(); i++) {
995 const OSL::OSLQuery::Parameter *param = info->query.getparam(i);
998 if (param->varlenarray || param->isstruct || param->type.arraylen > 1 || param->isoutput ||
1005 int vec_size = (int)param->type.aggregate;
1006 if (param->type.basetype == TypeDesc::INT) {
1008 if (!params.
get_int(param->name, data) || data.size() != vec_size) {
1011 raw_data.resize(
sizeof(
int) * vec_size);
1012 memcpy(raw_data.data(), data.data(),
sizeof(
int) * vec_size);
1014 else if (param->type.basetype == TypeDesc::FLOAT) {
1016 if (!params.
get_float(param->name, data) || data.size() != vec_size) {
1019 raw_data.resize(
sizeof(
float) * vec_size);
1020 memcpy(raw_data.data(), data.data(),
sizeof(
float) * vec_size);
1022 else if (param->type.basetype == TypeDesc::STRING) {
1027 raw_data.resize(data.length() + 1);
1028 memcpy(raw_data.data(), data.c_str(), data.length() + 1);
1034 auto entry = std::make_pair(raw_data, param->type);
1040 else if (it->second != entry) {
1045 used_params.insert(param->name);
1050 if (used_params.contains(it->first)) {
1068 (void)bytecode_hash;
1097 return kernel_features;
unsigned long long int uint64_t
BoundBox2D offset(const float2 offset) const
__forceinline float3 size() const
__forceinline void grow(const float3 &pt)
float world_to_raster_size(const float3 P)
ProjectionTransform worldtoraster
float3 frustum_right_normal
float motion_time(const int step) const
ProjectionTransform rastertoworld
BoundBox viewplane_bounds_get()
void update_interactive_motion()
BoundBox2D viewplane_post
ProjectionTransform worldtoscreen
ProjectionTransform worldtondc
void update(Scene *scene)
ProjectionTransform rastertocamera
ProjectionTransform screentoworld
size_t shutter_table_offset
void device_update_volume(Device *device, DeviceScene *dscene, Scene *scene)
bool set_screen_size(int width, int height)
void device_free(Device *device, DeviceScene *dscene, Scene *scene)
int motion_step(const float time) const
ProjectionTransform ndctoworld
void device_update(Device *device, DeviceScene *dscene, Scene *scene)
float3 frustum_left_normal
void clear_osl_camera(Scene *scene)
uint64_t get_kernel_features() const
void compute_auto_viewplane()
float3 frustum_top_normal
ProjectionTransform full_rastertocamera
float3 frustum_bottom_normal
void set_osl_camera(Scene *scene, OSLCameraParamQuery ¶ms, const std::string &filepath, const std::string &bytecode_hash="", const std::string &bytecode="")
BoundBox2D viewport_camera_border
KernelCamera kernel_camera
map< ustring, pair< vector< uint8_t >, TypeDesc > > script_params
array< DecomposedTransform > kernel_camera_motion
device_vector< DecomposedTransform > camera_motion
virtual bool get_string(ustring name, std::string &data)=0
virtual bool get_int(ustring name, vector< int > &data)=0
virtual bool get_float(ustring name, vector< float > &data)=0
MotionType need_motion() const
unique_ptr< SceneUpdateStats > update_stats
@ MOTION_PASS_INTERACTIVE
unique_ptr< ShaderManager > shader_manager
unique_ptr< OSLManager > osl_manager
unique_ptr_vector< Object > objects
unique_ptr< LookupTables > lookup_tables
T * resize(const size_t newsize)
T * alloc(const size_t width, const size_t height=0)
ccl_device_inline float2 direction_to_panorama(ccl_constant KernelCamera *cam, const float3 dir)
CCL_NAMESPACE_BEGIN ccl_device_inline float frac(const float x, ccl_private int *ix)
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)
ccl_device_inline ProjectionTransform projection_identity()
ccl_device_inline ProjectionTransform projection_inverse(const ProjectionTransform tfm)
#define SHUTTER_TABLE_SIZE
#define KERNEL_FEATURE_OSL_CAMERA
#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)
#define assert(assertion)
VecBase< float, D > normalize(VecOp< float, D >) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
float4x4 projection_orthographic(float left, float right, float bottom, float top, float near_clip, float far_clip)
Create an orthographic projection matrix using OpenGL coordinate convention: Maps each axis range to ...
float4x4 projection_perspective(float left, float right, float bottom, float top, float near_clip, float far_clip)
Create a perspective projection matrix using OpenGL coordinate convention: Maps each axis range to [-...
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 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)
@ 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_device_inline dual1 len(const ccl_private dual< T > &a)
ccl_device_inline dual1 len_squared(const ccl_private dual< T > &a)
CCL_NAMESPACE_BEGIN ccl_device_inline float2 zero_float2()
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)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
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, const int y)
static NodeType * add(const char *name, CreateFunc create, Type type=NONE, const NodeType *base=nullptr)
Node(const NodeType *type, ustring name=ustring())