25std::atomic<uint32_t> View::global_sync_counter_ = 1;
29 data_[view_id].viewmat = view_mat;
31 data_[view_id].winmat = win_mat;
43 sync_counter_ = (global_sync_counter_ += 2);
51 for (
int i = 0;
i < 8;
i++) {
59 float left, right, bottom,
top, near, far;
64 corners[0][2] = corners[3][2] = corners[7][2] = corners[4][2] = -near;
65 corners[0][0] = corners[3][0] =
left;
66 corners[4][0] = corners[7][0] = right;
67 corners[0][1] = corners[4][1] = bottom;
68 corners[7][1] = corners[3][1] =
top;
72 float sca_far = far / near;
79 corners[1][2] = corners[2][2] = corners[6][2] = corners[5][2] = -far;
80 corners[1][0] = corners[2][0] =
left;
81 corners[6][0] = corners[5][0] = right;
82 corners[1][1] = corners[5][1] = bottom;
83 corners[2][1] = corners[6][1] =
top;
87 for (
float4 &corner : corners) {
96 culling_[view_id].frustum_planes.planes[0],
97 culling_[view_id].frustum_planes.planes[5],
98 culling_[view_id].frustum_planes.planes[1],
99 culling_[view_id].frustum_planes.planes[3],
100 culling_[view_id].frustum_planes.planes[4],
101 culling_[view_id].frustum_planes.planes[2]);
121 const float *nearpoint = corners[0];
122 const float *farpoint = corners[6];
135 float mid_min[3], mid_max[3];
146 float fac = (4 * h_sq + b_sq - a_sq) / (8 * h_sq);
150 CLAMP(fac, 0.0f, 1.0f);
166 float farpoint[3] = {0.0f};
168 float farcenter[3] = {0.0f};
177 float corner[3] = {1.0f, 1.0f, 1.0f};
178 for (
int i = 0;
i < 4;
i++) {
189 float tmp = corner[0];
190 corner[0] = -corner[1];
209 n = f * s /
e -
len_v2(nearpoint);
212 z = (
F -
N) / (2.0f * (
e - s + c * (f - n)));
214 bsphere.
center[0] = farcenter[0] *
z /
e;
215 bsphere.
center[1] = farcenter[1] *
z /
e;
243 sync_counter_ = (global_sync_counter_ += 2);
262 if (debug_freeze &&
frozen_ ==
false) {
281 resource_len * word_per_draw;
286 const uint32_t
data = 0xFFFFFFFFu;
329 return {
culling_[view_id].frustum_planes.planes[0],
330 culling_[view_id].frustum_planes.planes[1],
331 culling_[view_id].frustum_planes.planes[2],
332 culling_[view_id].frustum_planes.planes[3],
333 culling_[view_id].frustum_planes.planes[4],
334 culling_[view_id].frustum_planes.planes[5]};
339 return {
culling_[view_id].frustum_corners.corners[0].xyz(),
340 culling_[view_id].frustum_corners.corners[1].xyz(),
341 culling_[view_id].frustum_corners.corners[2].xyz(),
342 culling_[view_id].frustum_corners.corners[3].xyz(),
343 culling_[view_id].frustum_corners.corners[4].xyz(),
344 culling_[view_id].frustum_corners.corners[5].xyz(),
345 culling_[view_id].frustum_corners.corners[6].xyz(),
346 culling_[view_id].frustum_corners.corners[7].xyz()};
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(blender::gpu::Shader *shader, uint groups_x_len, uint groups_y_len, uint groups_z_len, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_debug_group_end()
void GPU_debug_group_begin(const char *name)
void GPU_shader_bind(blender::gpu::Shader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
int GPU_shader_get_ssbo_binding(blender::gpu::Shader *shader, const char *name)
void GPU_shader_uniform_1i(blender::gpu::Shader *sh, const char *name, int value)
@ GPU_BARRIER_SHADER_STORAGE
void GPU_memory_barrier(GPUBarrier barrier)
void GPU_storagebuf_clear(blender::gpu::StorageBuf *ssbo, uint32_t clear_value)
void GPU_storagebuf_bind(blender::gpu::StorageBuf *ssbo, int slot)
BMesh const char void * data
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
UniformArrayBuffer< ViewCullingData, DRW_VIEW_MAX > culling_
static void default_set(const float4x4 &view_mat, const float4x4 &win_mat)
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_
static View & default_get()
const float4x4 & viewinv(int view_id=0) const
virtual VisibilityBuf & get_visibility_buffer()
uint64_t manager_fingerprint_
void frustum_culling_sphere_calc(int view_id)
const float4x4 & wininv(int view_id=0) const
std::array< float3, 8 > frustum_corners_get(int view_id=0)
int visibility_word_per_draw() const
std::array< float4, 6 > frustum_planes_get(int view_id=0)
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_VISIBILITY_GROUP_SIZE
#define DRW_VIEW_CULLING_UBO_SLOT
#define DRW_VIEW_UBO_SLOT
blender::gpu::Shader * DRW_shader_draw_view_finalize_get()
blender::gpu::Shader * DRW_shader_draw_visibility_compute_get()
std::array< VecBase< T, 3 >, 8 > corners(const Bounds< VecBase< T, 3 > > &bounds)
void drw_debug_matrix_as_bbox(const float4x4 &mat, const float4 color, const uint lifetime)
StorageArrayBuffer< ObjectBounds, 128 > ObjectBoundsBuf
StorageArrayBuffer< ObjectInfos, 128 > ObjectInfosBuf
StorageArrayBuffer< uint, 4, true > VisibilityBuf
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)
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< float, 3 > float3
blender::draw::View * default_view
const c_style_mat & ptr() const