Blender V5.3
eevee_shadow_visibility.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9/* TODO(fclem): Could reject bounding boxes that are covering only invalid tiles. */
10
11#pragma once
12
13#include "draw_intersect.bsl.hh"
14#include "draw_model.bsl.hh"
16
17#include "eevee_defines.hh"
19
20namespace eevee::shadow {
21
24
26
27 [[storage(0, read)]] const ObjectBounds (&bounds_buf)[];
28 [[storage(1, read_write)]] uint (&visibility_buf)[];
29 [[storage(2, read)]] const ShadowRenderView (&render_view_buf)[SHADOW_VIEW_MAX];
30
32
33 bool shadow_linking_affects_caster(uint view_id, uint resource_id)
34 {
35 ObjectInfos object_infos = infos.get(resource_id);
36 return bitmask64_test(render_view_buf[view_id].shadow_set_membership,
37 blocker_shadow_set_get(object_infos));
38 }
39
40 void mask_visibility_bit(uint view_id, uint3 global_id)
41 {
42 constexpr uint visibility_word_per_draw = uint(SHADOW_VIEW_MAX) / 32u;
43 uint index = global_id.x * visibility_word_per_draw + (view_id / 32u);
44 visibility_buf[index] &= ~(1u << (view_id & 31u));
45 }
46
47 /* Returns true if visibility needs to be disabled. */
48 bool non_culling_tests(uint view_id, uint resource_id)
49 {
50 if (shadow_linking_affects_caster(view_id, resource_id) == false) {
51 /* Object doesn't cast shadow from this light. */
52 return true;
53 }
54 if (view_culling.get(view_id).bound_sphere.w == -1.0f) {
55 /* View disabled. */
56 return true;
57 }
58 return false;
59 }
60};
61
64 [[global_invocation_id]] const uint3 global_id)
65{
66 draw::ViewCulling &culling = srt.view_culling;
67
68 if (int(global_id.x) >= srt.resource_len) {
69 return;
70 }
71
72 ObjectBounds bounds = srt.bounds_buf[global_id.x];
73
74 if (drw_bounds_are_valid(bounds)) {
75 IsectBox box = isect_box_setup(bounds.bounding_corners[0].xyz,
76 bounds.bounding_corners[1].xyz,
77 bounds.bounding_corners[2].xyz,
78 bounds.bounding_corners[3].xyz);
79 Sphere bounding_sphere = shape_sphere(bounds.bounding_sphere.xyz, bounds.bounding_sphere.w);
80 Sphere inscribed_sphere = shape_sphere(bounds.bounding_sphere.xyz,
81 bounds.inner_sphere_radius());
82
83 for (uint view_id = 0u; view_id < uint(SHADOW_VIEW_MAX); view_id++) {
84 if (srt.non_culling_tests(view_id, global_id.x)) {
85 srt.mask_visibility_bit(view_id, global_id);
86 }
87 else if (culling.get(view_id).bound_sphere.w == -1.0f) {
88 /* View disabled. */
89 srt.mask_visibility_bit(view_id, global_id);
90 }
91 else if (culling.intersect_view(inscribed_sphere, view_id) == true) {
92 /* Visible. */
93 }
94 else if (culling.intersect_view(bounding_sphere, view_id) == false) {
95 /* Not visible. */
96 srt.mask_visibility_bit(view_id, global_id);
97 }
98 else if (culling.intersect_view(box, view_id) == false) {
99 /* Not visible. */
100 srt.mask_visibility_bit(view_id, global_id);
101 }
102 }
103 }
104 else {
105 /* Culling is disabled, but we need to mask the bits for disabled views. */
106 for (uint view_id = 0u; view_id < uint(SHADOW_VIEW_MAX); view_id++) {
107 if (srt.non_culling_tests(view_id, global_id.x)) {
108 srt.mask_visibility_bit(view_id, global_id);
109 }
110 }
111 }
112}
113
115
116} // namespace eevee::shadow
#define DRW_VISIBILITY_GROUP_SIZE
IsectBox isect_box_setup(Box shape)
bool drw_bounds_are_valid(ObjectBounds bounds)
uint blocker_shadow_set_get(ObjectInfos object_infos)
Sphere shape_sphere(float3 center, float radius)
#define storage(slot, qualifiers)
#define index(i)
#define push_constant
#define resource_table
#define global_invocation_id
#define compute
#define local_size(...)
bool bitmask64_test(uint2 bitmask, uint bit_index)
void comp_main(ViewVisibility &srt, const uint3 global_id)
PipelineCompute view_visibility(eevee::shadow::comp_main)
float4 bounding_corners[4]
float inner_sphere_radius() const
ObjectInfos get(uint resource_id) const
ViewCullingData get(uint view_id) const
bool intersect_view(Pyramid pyramid, uint view_id) const
void mask_visibility_bit(uint view_id, uint3 global_id)
bool shadow_linking_affects_caster(uint view_id, uint resource_id)
bool non_culling_tests(uint view_id, uint resource_id)
const ShadowRenderView(& render_view_buf)[SHADOW_VIEW_MAX]
uint x
Definition types_uint3.h:13