Blender V5.3
eevee_camera.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
10
11#include "BLI_math_geom_c.hh"
12#include "BLI_math_matrix.hh"
13#include "BLI_math_matrix_c.hh"
14#include "BLI_math_vector.hh"
15
16#include "BKE_camera.h"
17
19
20namespace blender::eevee {
21
22class Instance;
23
24inline float4x4 cubeface_mat(int face)
25{
26 switch (face) {
27 default:
28 case 0:
29 /* Pos X */
30 return float4x4({0.0f, 0.0f, -1.0f, 0.0f},
31 {0.0f, -1.0f, 0.0f, 0.0f},
32 {-1.0f, 0.0f, 0.0f, 0.0f},
33 {0.0f, 0.0f, 0.0f, 1.0f});
34 case 1:
35 /* Neg X */
36 return float4x4({0.0f, 0.0f, 1.0f, 0.0f},
37 {0.0f, -1.0f, 0.0f, 0.0f},
38 {1.0f, 0.0f, 0.0f, 0.0f},
39 {0.0f, 0.0f, 0.0f, 1.0f});
40 case 2:
41 /* Pos Y */
42 return float4x4({1.0f, 0.0f, 0.0f, 0.0f},
43 {0.0f, 0.0f, -1.0f, 0.0f},
44 {0.0f, 1.0f, 0.0f, 0.0f},
45 {0.0f, 0.0f, 0.0f, 1.0f});
46 case 3:
47 /* Neg Y */
48 return float4x4({1.0f, 0.0f, 0.0f, 0.0f},
49 {0.0f, 0.0f, 1.0f, 0.0f},
50 {0.0f, -1.0f, 0.0f, 0.0f},
51 {0.0f, 0.0f, 0.0f, 1.0f});
52 case 4:
53 /* Pos Z */
54 return float4x4({1.0f, 0.0f, 0.0f, 0.0f},
55 {0.0f, -1.0f, 0.0f, 0.0f},
56 {0.0f, 0.0f, -1.0f, 0.0f},
57 {0.0f, 0.0f, 0.0f, 1.0f});
58 case 5:
59 /* Neg Z */
60 return float4x4({-1.0f, 0.0f, 0.0f, 0.0f},
61 {0.0f, -1.0f, 0.0f, 0.0f},
62 {0.0f, 0.0f, 1.0f, 0.0f},
63 {0.0f, 0.0f, 0.0f, 1.0f});
64 }
65}
66
67inline void cubeface_winmat_get(float4x4 &winmat, float near, float far)
68{
69 /* Simple 90 degree FOV projection. */
70 perspective_m4(winmat.ptr(), -near, near, -near, near, near, far);
71}
72
73/* -------------------------------------------------------------------- */
76
77inline bool operator==(const CameraData &a, const CameraData &b)
78{
79 return compare_m4m4(a.persmat.ptr(), b.persmat.ptr(), FLT_MIN) && (a.uv_scale == b.uv_scale) &&
80 (a.uv_bias == b.uv_bias) && (a.equirect_scale == b.equirect_scale) &&
81 (a.equirect_bias == b.equirect_bias) && (a.fisheye_fov == b.fisheye_fov) &&
82 (a.fisheye_lens == b.fisheye_lens) && (a.fisheye_sensor == b.fisheye_sensor) &&
83 (a.fisheye_polynomial_bias == b.fisheye_polynomial_bias) &&
84 (a.fisheye_polynomial_coefficients == b.fisheye_polynomial_coefficients) &&
85 (a.central_cylindrical_range == b.central_cylindrical_range) &&
86 (a.panoramic_view_mask == b.panoramic_view_mask) && (a.type == b.type);
87}
88
89inline bool operator!=(const CameraData &a, const CameraData &b)
90{
91 return !(a == b);
92}
93
95
96/* -------------------------------------------------------------------- */
99
103class Camera {
104 private:
105 Instance &inst_;
106
107 CameraData &data_;
108
109 struct {
110 float3 center;
111 float radius;
112 } bound_sphere;
113
114 float overscan_ = -1.0f;
115 bool overscan_changed_;
117 bool is_camera_object_ = false;
119 Object *last_camera_object_ = nullptr;
120 bool camera_changed_ = false;
121
122 public:
123 Camera(Instance &inst, CameraData &data) : inst_(inst), data_(data) {};
125
126 void init();
127 void sync();
128
132 const CameraData &data_get() const
133 {
134 BLI_assert(data_.initialized);
135 return data_;
136 }
137 bool is_panoramic() const
138 {
139 return eevee::is_panoramic(data_.type);
140 }
141 bool is_orthographic() const
142 {
143 return data_.type == CAMERA_ORTHO;
144 }
145 bool is_perspective() const
146 {
147 return data_.type == CAMERA_PERSP;
148 }
149 bool is_camera_object() const
150 {
151 return is_camera_object_;
152 }
153 const float3 &position() const
154 {
155 return data_.viewinv.location();
156 }
157 const float3 &forward() const
158 {
159 return data_.viewinv.z_axis();
160 }
161 const float3 &bound_center() const
162 {
163 return bound_sphere.center;
164 }
165 const float &bound_radius() const
166 {
167 return bound_sphere.radius;
168 }
169 float overscan() const
170 {
171 return overscan_;
172 }
173 bool overscan_changed() const
174 {
175 return overscan_changed_;
176 }
177 bool camera_changed() const
178 {
179 return camera_changed_;
180 }
181
182 private:
183 void update_bounds();
184
185 float4x4 projection_crop_matrix(int2 film_offset, int2 film_extent, int2 display_extent);
186 float4x4 projection_overscan_matrix(int2 film_extent, int2 film_overscan);
187};
188
190
191} // namespace blender::eevee
Camera data-block and utility functions.
const float3 & forward() const
const float3 & position() const
bool is_orthographic() const
bool overscan_changed() const
const float & bound_radius() const
const CameraData & data_get() const
Camera(Instance &inst, CameraData &data)
bool is_perspective() const
bool camera_changed() const
const float3 & bound_center() const
bool is_camera_object() const
A running instance of the engine.
#define FLT_MIN
void cubeface_winmat_get(float4x4 &winmat, float near, float far)
bool operator!=(const CameraData &a, const CameraData &b)
float4x4 cubeface_mat(int face)
bool operator==(const CameraData &a, const CameraData &b)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
bool compare_m4m4(const float mat1[4][4], const float mat2[4][4], float limit)
MatBase< float, 4, 4 > float4x4
void perspective_m4(float mat[4][4], float left, float right, float bottom, float top, float nearClip, float farClip)
VecBase< int32_t, 2 > int2
BMesh const char void * data
VecBase< float, 3 > float3
const c_style_mat & ptr() const