28#define FIX_CUSTOM_CAMERA_CRASH
34 if (shutter_curve.
size() == 0) {
39 const int index = (int)
x;
40 const float frac =
x - index;
41 if (index < shutter_curve.
size() - 1) {
42 return mix(shutter_curve[index], shutter_curve[index + 1],
frac);
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);
149 SOCKET_FLOAT(viewport_camera_border.left,
"Viewport Border Left", 0);
150 SOCKET_FLOAT(viewport_camera_border.right,
"Viewport Border Right", 0);
151 SOCKET_FLOAT(viewport_camera_border.bottom,
"Viewport Border Bottom", 0);
152 SOCKET_FLOAT(viewport_camera_border.top,
"Viewport Border Top", 0);
154 SOCKET_FLOAT(offscreen_dicing_scale,
"Offscreen Dicing Scale", 1.0f);
159 SOCKET_BOOLEAN(use_perspective_motion,
"Use Perspective Motion",
false);
171 use_perspective_motion =
false;
174 for (
int i = 0;
i < shutter_curve.size(); ++
i) {
175 shutter_curve[
i] = 1.0f;
207 const float aspect = (
float)full_width / (
float)full_height;
208 if (full_width >= full_height) {
234 scene->
update_stats->camera.times.add_entry({
"update", time});
249 const Transform screentoraster = ndctoraster * screentondc;
251 const Transform full_screentoraster = full_ndctoraster * screentondc;
271#ifdef FIX_CUSTOM_CAMERA_CRASH
310#ifdef FIX_CUSTOM_CAMERA_CRASH
327#ifdef FIX_CUSTOM_CAMERA_CRASH
362 bool have_motion =
false;
363 for (
size_t i = 0;
i < motion.size();
i++) {
364 have_motion = have_motion || motion[
i] != matrix;
379 if (have_motion || fov != fov_pre || fov != fov_post) {
384 fov_pre, nearclip, farclip);
386 fov_post, nearclip, farclip);
422 kcam->
blades = (blades < 3) ? 0.0f : blades;
430 kcam->
type = camera_type;
451 switch (stereo_eye) {
465 if (use_pole_merge) {
511 scene->
update_stats->camera.times.add_entry({
"device_update", time});
532 if (num_motion_steps) {
550 KernelIntegrator *kintegrator = &dscene->
data.integrator;
551 if (kintegrator->use_volumes) {
554 LOG_INFO <<
"Considering custom camera to be inside volume.";
561 static const int OBJECTS_PER_TASK = 32;
562 parallel_for(blocked_range<size_t>(0, scene->
objects.
size(), OBJECTS_PER_TASK),
563 [&](
const blocked_range<size_t> &r) {
564 for (size_t i = r.begin(); i != r.end(); i++) {
565 Object *object = scene->objects[i];
566 if (object->get_geometry()->has_volume &&
567 viewplane_boundbox.intersects(object->bounds)) {
569 LOG_INFO <<
"Detected camera inside volume.";
570 kernel_camera.is_inside_volume = 1;
571 parallel_for_cancel();
578 LOG_INFO <<
"Camera is outside of the volume.";
595float3 Camera::transform_full_raster_to_world(
const float raster_x,
const float raster_y)
610 P += nearclip *
D / Pclip.
z;
620 assert(!
"unsupported camera type");
631 const float max_aperture_size = aperture_ratio < 1.0f ? aperturesize / aperture_ratio :
635 const float extend = max_aperture_size + nearclip;
636 if (use_spherical_stereo ==
false) {
640 const float half_eye_distance = interocular_distance * 0.5f;
681 const float scaled_horz_dof_ray = (max_aperture_size > 0.0f) ?
682 max_aperture_size * (nearclip / focaldistance) :
684 const float extend = max_aperture_size +
max(nearclip, scaled_horz_dof_ray);
686 bounds.grow(transform_full_raster_to_world(0.0f, 0.0f), extend);
687 bounds.grow(transform_full_raster_to_world(0.0f, (
float)full_height), extend);
688 bounds.grow(transform_full_raster_to_world((
float)full_width, (
float)full_height), extend);
689 bounds.grow(transform_full_raster_to_world((
float)full_width, 0.0f), extend);
694 bounds.grow(transform_full_raster_to_world(0.5f * full_width, 0.5f * full_height), extend);
707 if (offscreen_dicing_scale > 1.0f) {
717 c.
z =
max(0.0f, p.
z);
720 float f_dist =
len(p - c) /
sqrtf((v1.
x * v1.
x + v1.
y * v1.
y) * 0.5f);
726 res += res * f_dist * (offscreen_dicing_scale - 1.0f);
730#ifdef FIX_CUSTOM_CAMERA_CRASH
747 res =
len(dist * dDdx -
dot(dist * dDdx,
D) *
D);
753 if (offscreen_dicing_scale > 1.0f) {
762 if (r <= 0.0f &&
l <= 0.0f && t <= 0.0f &&
b <= 0.0f) {
766 else if (r > 0.0f &&
l > 0.0f && t > 0.0f &&
b > 0.0f) {
779 float dist[] = {r,
l, t,
b};
780 float3 along[] = {along_right, along_left, along_top, along_bottom};
786 for (
int i = 0;
i < 4;
i++, d++, a++) {
789 if (
dot(p, *a) >= 0.0f) {
791 f_dist =
max(f_dist, *d);
802 f_dist = (f_dist > 0) ?
min(f_dist,
len(p)) :
len(p);
807 res +=
len(dDdx -
dot(dDdx,
D) *
D) * f_dist * (offscreen_dicing_scale - 1.0f);
813 const float dist =
len(
D);
862 return motion.size() > 1;
867 if (width_ != width || height_ != height) {
879 return (
use_motion()) ? 2.0f *
step / (motion.size() - 1) - 1.0f : 0.0f;
897 const std::string &filepath,
898 const std::string &bytecode_hash,
899 const std::string &bytecode)
908 if (!filepath.empty()) {
914 hash = scene->
osl_manager->shader_load_bytecode(bytecode_hash, bytecode);
918 bool changed =
false;
932 std::set<ustring> used_params;
933 for (
int i = 0;
i < info->query.nparams();
i++) {
934 const OSL::OSLQuery::Parameter *param = info->query.getparam(
i);
937 if (param->varlenarray || param->isstruct || param->type.arraylen > 1 || param->isoutput ||
942 int vec_size = (int)param->type.aggregate;
943 if (param->type.basetype == TypeDesc::INT) {
945 if (!
params.get_int(param->name,
data) ||
data.size() != vec_size) {
948 raw_data.resize(
sizeof(
int) * vec_size);
949 memcpy(raw_data.data(),
data.data(),
sizeof(
int) * vec_size);
951 else if (param->type.basetype == TypeDesc::FLOAT) {
953 if (!
params.get_float(param->name,
data) ||
data.size() != vec_size) {
956 raw_data.resize(
sizeof(
float) * vec_size);
957 memcpy(raw_data.data(),
data.data(),
sizeof(
float) * vec_size);
959 else if (param->type.basetype == TypeDesc::STRING) {
964 raw_data.resize(
data.length() + 1);
965 memcpy(raw_data.data(),
data.c_str(),
data.length() + 1);
970 auto entry = std::make_pair(raw_data, param->type);
976 else if (it->second != entry) {
981 used_params.insert(param->name);
986 if (used_params.count(it->first)) {
1004 (void)bytecode_hash;
1027 uint kernel_features = 0;
1033 return kernel_features;
BMesh const char void * data
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)
device_vector< DecomposedTransform > camera_motion
T * alloc(const size_t width, const size_t height=0)
dot(value.rgb, luminance_coefficients)") DEFINE_VALUE("REDUCE(lhs
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)
ccl_device_inline ProjectionTransform projection_perspective(const float fov, const float n, float f)
ccl_device_inline ProjectionTransform projection_orthographic(const float znear, const float zfar)
#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
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
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_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)
@ 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)
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()
float central_cylindrical_range_v_min
uint get_kernel_features() const
float fisheye_polynomial_k3
ProjectionTransform worldtoscreen
ProjectionTransform worldtondc
float central_cylindrical_range_u_min
void update(Scene *scene)
ProjectionTransform rastertocamera
float fisheye_polynomial_k1
float central_cylindrical_range_u_max
ProjectionTransform screentoworld
float fisheye_polynomial_k2
size_t shutter_table_offset
void device_update_volume(Device *device, DeviceScene *dscene, Scene *scene)
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)
bool set_screen_size(const int width_, int height_)
float3 frustum_left_normal
void clear_osl_camera(Scene *scene)
float fisheye_polynomial_k0
void compute_auto_viewplane()
float3 frustum_top_normal
float fisheye_polynomial_k4
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
float central_cylindrical_range_v_max
map< ustring, pair< vector< uint8_t >, TypeDesc > > script_params
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, 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())
MotionType need_motion() const
unique_ptr< SceneUpdateStats > update_stats
unique_ptr< ShaderManager > shader_manager
unique_ptr< OSLManager > osl_manager
unique_ptr_vector< Object > objects
unique_ptr< LookupTables > lookup_tables