22 data_[view_id].viewmat = view_mat;
24 data_[view_id].winmat = win_mat;
41 this->
sync(view_mat, win_mat);
49 for (
int i = 0; i < 8; i++) {
57 float left, right, bottom,
top, near, far;
62 corners[0][2] = corners[3][2] = corners[7][2] = corners[4][2] = -near;
63 corners[0][0] = corners[3][0] =
left;
64 corners[4][0] = corners[7][0] = right;
65 corners[0][1] = corners[4][1] = bottom;
66 corners[7][1] = corners[3][1] =
top;
70 float sca_far = far / near;
77 corners[1][2] = corners[2][2] = corners[6][2] = corners[5][2] = -far;
78 corners[1][0] = corners[2][0] =
left;
79 corners[6][0] = corners[5][0] = right;
80 corners[1][1] = corners[5][1] = bottom;
81 corners[2][1] = corners[6][1] =
top;
85 for (
float4 &corner : corners) {
94 culling_[view_id].frustum_planes.planes[0],
95 culling_[view_id].frustum_planes.planes[5],
96 culling_[view_id].frustum_planes.planes[1],
97 culling_[view_id].frustum_planes.planes[3],
98 culling_[view_id].frustum_planes.planes[4],
99 culling_[view_id].frustum_planes.planes[2]);
116 const float *nearpoint = corners[0];
117 const float *farpoint = corners[6];
130 float mid_min[3], mid_max[3];
141 float fac = (4 * h_sq + b_sq - a_sq) / (8 * h_sq);
145 CLAMP(fac, 0.0f, 1.0f);
161 float farpoint[3] = {0.0f};
163 float farcenter[3] = {0.0f};
172 float corner[3] = {1.0f, 1.0f, 1.0f};
173 for (
int i = 0; i < 4; i++) {
184 float tmp = corner[0];
185 corner[0] = -corner[1];
204 n = f * s /
e -
len_v2(nearpoint);
207 z = (F -
N) / (2.0f * (
e - s + c * (f - n)));
209 bsphere.
center[0] = farcenter[0] *
z /
e;
210 bsphere.
center[1] = farcenter[1] *
z /
e;
252 if (debug_freeze &&
frozen_ ==
false) {
273 resource_len * word_per_draw;
void BKE_boundbox_init_from_minmax(BoundBox *bb, const float min[3], const float max[3])
MINLINE uint ceil_to_multiple_u(uint a, uint b)
MINLINE uint divide_ceil_u(uint a, uint b)
MINLINE int max_ii(int a, int 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 planes_from_projmat(const float mat[4][4], float left[4], float right[4], float bottom[4], float top[4], float near[4], float far[4])
void mul_v3_project_m4_v3(float r[3], const float mat[4][4], const float vec[3])
void mul_project_m4_v3(const float mat[4][4], float vec[3])
void mul_m4_v3(const float M[4][4], float r[3])
bool is_negative_m4(const float mat[4][4])
MINLINE float len_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
MINLINE float len_squared_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void sub_v2_v2(float r[2], const float a[2])
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void copy_v3_fl3(float v[3], float x, float y, float z)
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v2_v2fl(float r[2], const float a[2], float f)
MINLINE void add_v3_v3(float r[3], const float a[3])
void GPU_compute_dispatch(GPUShader *shader, uint groups_x_len, uint groups_y_len, uint groups_z_len)
void GPU_debug_group_end()
void GPU_debug_group_begin(const char *name)
void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value)
int GPU_shader_get_ssbo_binding(GPUShader *shader, const char *name)
void GPU_shader_bind(GPUShader *shader)
void GPU_memory_barrier(eGPUBarrier barrier)
@ GPU_BARRIER_SHADER_STORAGE
void GPU_storagebuf_bind(GPUStorageBuf *ssbo, int slot)
void GPU_storagebuf_clear(GPUStorageBuf *ssbo, uint32_t clear_value)
struct GPUShader GPUShader
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
void resize(int64_t new_size)
UniformArrayBuffer< ViewCullingData, DRW_VIEW_MAX > culling_
VisibilityBuf visibility_buf_
bool is_persp(int view_id=0) const
const float4x4 & winmat(int view_id=0) const
const float4x4 persmat(int view_id=0) const
void compute_procedural_bounds()
UniformArrayBuffer< ViewMatrices, DRW_VIEW_MAX > data_freeze_
virtual void compute_visibility(ObjectBoundsBuf &bounds, ObjectInfosBuf &infos, uint resource_len, bool debug_freeze)
UniformArrayBuffer< ViewMatrices, DRW_VIEW_MAX > data_
UniformArrayBuffer< ViewCullingData, DRW_VIEW_MAX > culling_freeze_
const float4x4 & viewinv(int view_id=0) const
virtual VisibilityBuf & get_visibility_buffer()
void frustum_culling_sphere_calc(int view_id)
const float4x4 & wininv(int view_id=0) const
int visibility_word_per_draw() const
void frustum_boundbox_calc(int view_id)
void sync(const float4x4 &view_mat, const float4x4 &win_mat, int view_id=0)
void frustum_culling_planes_calc(int view_id)
Simple API to draw debug shapes and log in the viewport.
#define drw_debug_matrix_as_bbox(...)
#define DRW_VISIBILITY_GROUP_SIZE
#define DRW_VIEW_CULLING_UBO_SLOT
#define DRW_VIEW_UBO_SLOT
void DRW_view_winmat_get(const DRWView *view, float mat[4][4], bool inverse)
void DRW_view_viewmat_get(const DRWView *view, float mat[4][4], bool inverse)
GPUShader * DRW_shader_draw_visibility_compute_get()
GPUShader * DRW_shader_draw_view_finalize_get()
T length(const VecBase< T, Size > &a)
CartesianBasis invert(const CartesianBasis &basis)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
VecBase< float, 4 > float4
VecBase< float, 3 > float3
const c_style_mat & ptr() const