Blender V4.3
render/hydra/camera.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "camera.hh"
6
7#include "BKE_camera.h"
8
9#include "DNA_camera_types.h"
10#include "DNA_screen_types.h"
11#include "DNA_view3d_types.h"
12
13#include "hydra/object.hh"
14
16
17static pxr::GfCamera gf_camera(const CameraParams &params,
18 const pxr::GfVec2i &res,
19 const pxr::GfVec4f &border)
20{
21 pxr::GfCamera camera;
22
23 camera.SetProjection(params.is_ortho ? pxr::GfCamera::Projection::Orthographic :
24 pxr::GfCamera::Projection::Perspective);
25 camera.SetClippingRange(pxr::GfRange1f(params.clip_start, params.clip_end));
26 camera.SetFocalLength(params.lens);
27
28 pxr::GfVec2f b_pos(border[0], border[1]), b_size(border[2], border[3]);
29 float sensor_size = BKE_camera_sensor_size(params.sensor_fit, params.sensor_x, params.sensor_y);
30 pxr::GfVec2f sensor_scale = (BKE_camera_sensor_fit(params.sensor_fit, res[0], res[1]) ==
32 pxr::GfVec2f(1.0f, float(res[1]) / res[0]) :
33 pxr::GfVec2f(float(res[0]) / res[1], 1.0f);
34 pxr::GfVec2f aperture = pxr::GfVec2f((params.is_ortho) ? params.ortho_scale : sensor_size);
35 aperture = pxr::GfCompMult(aperture, sensor_scale);
36 aperture = pxr::GfCompMult(aperture, b_size);
37 aperture *= params.zoom;
38 if (params.is_ortho) {
39 /* Use tenths of a world unit according to USD docs
40 * https://graphics.pixar.com/usd/docs/api/class_gf_camera.html */
41 aperture *= 10.0f;
42 }
43 camera.SetHorizontalAperture(aperture[0]);
44 camera.SetVerticalAperture(aperture[1]);
45
46 pxr::GfVec2f lens_shift = pxr::GfVec2f(params.shiftx, params.shifty);
47 lens_shift = pxr::GfCompDiv(lens_shift, sensor_scale);
48 lens_shift += pxr::GfVec2f(params.offsetx, params.offsety);
49 lens_shift += b_pos + b_size * 0.5f - pxr::GfVec2f(0.5f);
50 lens_shift = pxr::GfCompDiv(lens_shift, b_size);
51 camera.SetHorizontalApertureOffset(lens_shift[0] * aperture[0]);
52 camera.SetVerticalApertureOffset(lens_shift[1] * aperture[1]);
53
54 return camera;
55}
56
57pxr::GfCamera gf_camera(const Depsgraph *depsgraph,
58 const View3D *v3d,
59 const ARegion *region,
60 const pxr::GfVec4f &border)
61{
62 const RegionView3D *region_data = (const RegionView3D *)region->regiondata;
63
67
68 pxr::GfCamera camera = gf_camera(params, pxr::GfVec2i(region->winx, region->winy), border);
69 camera.SetTransform(io::hydra::gf_matrix_from_transform(region_data->viewmat).GetInverse());
70
71 return camera;
72}
73
74pxr::GfCamera gf_camera(const Object *camera_obj,
75 const pxr::GfVec2i &res,
76 const pxr::GfVec4f &border)
77{
81
82 pxr::GfCamera camera = gf_camera(params, res, border);
83 camera.SetTransform(io::hydra::gf_matrix_from_transform(camera_obj->object_to_world().ptr()));
84
85 return camera;
86}
87
88} // namespace blender::render::hydra
Camera data-block and utility functions.
float BKE_camera_sensor_size(int sensor_fit, float sensor_x, float sensor_y)
int BKE_camera_sensor_fit(int sensor_fit, float sizex, float sizey)
void BKE_camera_params_init(CameraParams *params)
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)
@ CAMERA_SENSOR_FIT_HOR
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between camera
const Depsgraph * depsgraph
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
pxr::GfMatrix4d gf_matrix_from_transform(const float m[4][4])
static pxr::GfCamera gf_camera(const CameraParams &params, const pxr::GfVec2i &res, const pxr::GfVec4f &border)
float viewmat[4][4]