32 const Object *camera_eval = inst_.camera_eval_object;
37 const ::Camera *cam =
reinterpret_cast<const ::
Camera *
>(camera_eval->
data);
48 switch (cam->panorama_type) {
50 case CAM_PANO_EQUIRECTANGULAR:
53 case CAM_PANO_FISHEYE_EQUIDISTANT:
56 case CAM_PANO_FISHEYE_EQUISOLID:
59 case CAM_PANO_MIRRORBALL:
67 else if (inst_.drw_view) {
76 if ((inst_.scene->eevee.flag &
SCE_EEVEE_OVERSCAN) && (inst_.drw_view || inst_.render)) {
77 overscan = inst_.scene->eevee.overscan / 100.0f;
78 if (inst_.drw_view && (inst_.rv3d->dist == 0.0f || v3d_camera_params_get().lens == 0.0f)) {
89 const Object *camera_eval = inst_.camera_eval_object;
93 int2 display_extent = inst_.film.display_extent_get();
94 int2 film_extent = inst_.film.film_extent_get();
95 int2 film_offset = inst_.film.film_offset_get();
102 film_offset.x + film_extent.x,
104 film_offset.y + film_extent.y);
107 if (inst_.drw_view) {
111 uv_region.
min = (-uv_bias *
float2(display_extent)) / uv_scale;
112 uv_region.
max = uv_region.
min + (
float2(display_extent) / uv_scale);
115 data.uv_scale =
float2(film_extent + film_overscan * 2) / uv_region.
size();
116 data.uv_bias = (
float2(film_offset - film_overscan) - uv_region.
min) / uv_region.
size();
118 if (inst_.is_baking()) {
129 data.fisheye_fov =
data.fisheye_lens = -1.0f;
135 else if (inst_.drw_view) {
136 data.viewmat = inst_.drw_view->viewmat();
137 data.viewinv = inst_.drw_view->viewinv();
141 if (inst_.rv3d->dist > 0.0f &&
params.lens > 0.0f) {
159 data.winmat = inst_.drw_view->winmat();
162 else if (inst_.render) {
163 const Render *re = inst_.render->re;
189 float bottom = (-
data.winmat[3][1] - 1.f) /
data.winmat[1][1];
190 if (std::isnan(bottom) || std::isinf(std::abs(bottom))) {
198 is_camera_object_ =
false;
200 const ::Camera *cam =
reinterpret_cast<const ::
Camera *
>(camera_eval->
data);
201 data.clip_near = cam->clip_start;
202 data.clip_far = cam->clip_end;
204 data.fisheye_fov = cam->fisheye_fov;
205 data.fisheye_lens = cam->fisheye_lens;
206 data.equirect_bias.x = -cam->longitude_min +
M_PI_2;
207 data.equirect_bias.y = -cam->latitude_min +
M_PI_2;
208 data.equirect_scale.x = cam->longitude_min - cam->longitude_max;
209 data.equirect_scale.y = cam->latitude_min - cam->latitude_max;
211 data.equirect_bias +=
data.uv_bias *
data.equirect_scale;
212 data.equirect_scale *=
data.uv_scale;
214 data.equirect_scale_inv = 1.0f /
data.equirect_scale;
216 data.fisheye_fov =
data.fisheye_lens = -1.0f;
220 is_camera_object_ =
true;
222 else if (inst_.drw_view) {
224 data.clip_near = -inst_.drw_view->near_clip();
225 data.clip_far = -inst_.drw_view->far_clip();
226 data.fisheye_fov =
data.fisheye_lens = -1.0f;
231 data_.initialized =
true;
236void Camera::update_bounds()
238 float left, right, bottom,
top, near, far;
242 bbox.
vec[0][2] = bbox.
vec[3][2] = bbox.
vec[7][2] = bbox.
vec[4][2] = -near;
244 bbox.
vec[4][0] = bbox.
vec[7][0] = right;
245 bbox.
vec[0][1] = bbox.
vec[4][1] = bottom;
250 float sca_far = far / near;
257 bbox.
vec[1][2] = bbox.
vec[2][2] = bbox.
vec[6][2] = bbox.
vec[5][2] = -far;
259 bbox.
vec[6][0] = bbox.
vec[5][0] = right;
260 bbox.
vec[1][1] = bbox.
vec[5][1] = bottom;
263 bound_sphere.center = {0.0f, 0.0f, 0.0f};
264 bound_sphere.radius = 0.0f;
269 bound_sphere.center /= 8.0f;
270 for (
auto i : IndexRange(8)) {
272 bound_sphere.radius =
max_ff(bound_sphere.radius, dist_sqr);
274 bound_sphere.radius =
sqrtf(bound_sphere.radius);
void BKE_camera_params_init(CameraParams *params)
void BKE_camera_params_crop_viewplane(rctf *viewplane, int winx, int winy, const rcti *region)
void BKE_camera_params_from_view3d(CameraParams *params, const struct Depsgraph *depsgraph, const struct View3D *v3d, const struct RegionView3D *rv3d)
void BKE_camera_params_from_object(CameraParams *params, const struct Object *cam_ob)
void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int winy, float aspx, float aspy)
struct CameraParams CameraParams
MINLINE float max_ff(float a, float b)
void projmat_dimensions(const float winmat[4][4], float *r_left, float *r_right, float *r_bottom, float *r_top, float *r_near, float *r_far)
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
BMesh const char void * data
bool is_orthographic() const
Camera(Instance &inst, CameraData &data)
bool is_perspective() const
static int overscan_pixels_get(float overscan, int2 extent)
Object * camera_eval_object
bool is_viewport_image_render
const RegionView3D * rv3d
void RE_GetCameraModelMatrix(const Render *re, const Object *camera, float r_modelmat[4][4])
void RE_GetCameraWindow(Render *re, const Object *camera, float r_winmat[4][4])
void RE_GetWindowMatrixWithOverscan(bool is_ortho, float clip_start, float clip_end, rctf viewplane, float overscan, float r_winmat[4][4])
@ CAMERA_PANO_EQUIDISTANT
MatBase< T, 4, 4 > orthographic(T left, T right, T bottom, T top, T near_clip, T far_clip)
Create an orthographic projection matrix using OpenGL coordinate convention: Maps each axis range to ...
MatBase< T, 4, 4 > perspective(T left, T right, T bottom, T top, T near_clip, T far_clip)
Create a perspective projection matrix using OpenGL coordinate convention: Maps each axis range to [-...
T distance(const T &a, const T &b)
CartesianBasis invert(const CartesianBasis &basis)
T distance_squared(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
bool assign_if_different(T &old_value, T new_value)
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< float, 3 > float3
const c_style_mat & ptr() const
static MatBase identity()
VecBase< T, 2 > zw() const
VecBase< T, 2 > xy() const
float screen_diagonal_length