2023-08-24 10:54:59 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2022-2023 Blender Authors
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2022-09-02 18:30:48 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Compute visibility of each resource bounds for a given view.
|
|
|
|
|
*/
|
|
|
|
|
/* TODO(fclem): This could be augmented by a 2 pass occlusion culling system. */
|
|
|
|
|
|
2025-09-25 10:57:02 +02:00
|
|
|
#include "draw_view_infos.hh"
|
2024-11-13 12:32:39 +01:00
|
|
|
|
2025-03-04 00:48:31 +01:00
|
|
|
#include "draw_intersect_lib.glsl"
|
2022-09-02 18:30:48 +02:00
|
|
|
|
2024-10-05 10:17:30 +02:00
|
|
|
COMPUTE_SHADER_CREATE_INFO(draw_visibility_compute)
|
|
|
|
|
|
2022-11-14 00:42:31 +01:00
|
|
|
void mask_visibility_bit(uint view_id)
|
2022-09-02 18:30:48 +02:00
|
|
|
{
|
2022-11-14 00:42:31 +01:00
|
|
|
if (view_len > 1) {
|
|
|
|
|
uint index = gl_GlobalInvocationID.x * uint(visibility_word_per_draw) + (view_id / 32u);
|
|
|
|
|
visibility_buf[index] &= ~(1u << view_id);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
atomicAnd(visibility_buf[gl_WorkGroupID.x], ~(1u << gl_LocalInvocationID.x));
|
|
|
|
|
}
|
2022-09-02 18:30:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void main()
|
|
|
|
|
{
|
2023-07-14 11:09:39 +02:00
|
|
|
if (int(gl_GlobalInvocationID.x) >= resource_len) {
|
2022-09-02 18:30:48 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ObjectBounds bounds = bounds_buf[gl_GlobalInvocationID.x];
|
|
|
|
|
|
2024-09-25 19:58:38 +02:00
|
|
|
if (drw_bounds_are_valid(bounds)) {
|
2023-11-23 16:02:10 +01:00
|
|
|
IsectBox box = isect_box_setup(bounds.bounding_corners[0].xyz,
|
|
|
|
|
bounds.bounding_corners[1].xyz,
|
|
|
|
|
bounds.bounding_corners[2].xyz,
|
|
|
|
|
bounds.bounding_corners[3].xyz);
|
2023-04-20 08:03:31 +02:00
|
|
|
Sphere bounding_sphere = shape_sphere(bounds.bounding_sphere.xyz, bounds.bounding_sphere.w);
|
|
|
|
|
Sphere inscribed_sphere = shape_sphere(bounds.bounding_sphere.xyz,
|
|
|
|
|
bounds._inner_sphere_radius);
|
2022-09-02 18:30:48 +02:00
|
|
|
|
2025-08-06 10:41:23 +02:00
|
|
|
for (uint view_id = 0u; view_id < uint(view_len); view_id++) {
|
|
|
|
|
if (drw_view_culling(view_id).bound_sphere.w == -1.0f) {
|
2023-01-18 14:50:18 +01:00
|
|
|
/* View disabled. */
|
2025-08-06 10:41:23 +02:00
|
|
|
mask_visibility_bit(view_id);
|
2023-01-18 14:50:18 +01:00
|
|
|
}
|
2025-08-06 10:41:23 +02:00
|
|
|
else if (intersect_view(inscribed_sphere, view_id) == true) {
|
2022-11-14 00:42:31 +01:00
|
|
|
/* Visible. */
|
|
|
|
|
}
|
2025-08-06 10:41:23 +02:00
|
|
|
else if (intersect_view(bounding_sphere, view_id) == false) {
|
2022-11-14 00:42:31 +01:00
|
|
|
/* Not visible. */
|
2025-08-06 10:41:23 +02:00
|
|
|
mask_visibility_bit(view_id);
|
2022-11-14 00:42:31 +01:00
|
|
|
}
|
2025-08-06 10:41:23 +02:00
|
|
|
else if (intersect_view(box, view_id) == false) {
|
2022-11-14 00:42:31 +01:00
|
|
|
/* Not visible. */
|
2025-08-06 10:41:23 +02:00
|
|
|
mask_visibility_bit(view_id);
|
2022-11-14 00:42:31 +01:00
|
|
|
}
|
2022-09-02 18:30:48 +02:00
|
|
|
}
|
|
|
|
|
}
|
2024-05-10 13:02:54 +02:00
|
|
|
else {
|
|
|
|
|
/* Culling is disabled, but we need to mask the bits for disabled views. */
|
2025-08-06 10:41:23 +02:00
|
|
|
for (uint view_id = 0u; view_id < uint(view_len); view_id++) {
|
|
|
|
|
if (drw_view_culling(view_id).bound_sphere.w == -1.0f) {
|
2024-05-10 13:02:54 +02:00
|
|
|
/* View disabled. */
|
2025-08-06 10:41:23 +02:00
|
|
|
mask_visibility_bit(view_id);
|
2024-05-10 13:02:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-09 15:38:27 +10:00
|
|
|
}
|