Blender V5.3
eevee_shadow_tilemap_bounds.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
12#pragma once
13
14#include "draw_shader_shared.hh"
15#include "draw_shape.bsl.hh"
19
20namespace eevee::shadow {
21
23 [[storage(0, write)]] ShadowTileMapClip (&tilemaps_clip_buf)[];
25};
26
27[[compute, local_size(SHADOW_CLIPMAP_GROUP_SIZE)]]
29 [[global_invocation_id]] const uint3 global_id)
30{
31 int index = int(global_id.x);
32 if (index < srt.tilemaps_clip_buf_len) {
33 srt.tilemaps_clip_buf[index].clip_far = floatBitsToOrderedInt(-FLT_MAX);
34 srt.tilemaps_clip_buf[index].clip_near = floatBitsToOrderedInt(FLT_MAX);
35 }
36}
37
40
41 [[storage(4, read)]] const uint (&casters_id_buf)[];
42 [[storage(5, read_write)]] ShadowTileMapData (&tilemaps_buf)[];
43 [[storage(6, read)]] const ObjectBounds (&bounds_buf)[];
44 [[storage(7, read_write)]] ShadowTileMapClip (&tilemaps_clip_buf)[];
45
46 [[storage(8, read_write)]] LightData (&light_buf_write)[];
47
49
52};
53
58
59 void eval_directional(TilemapBounds &srt, uint l_index, LightData /*light*/)
60 {
61 LightData light = srt.light_data.light_buf[l_index];
62
63 if (light.tilemap_index == LIGHT_NO_SHADOW) {
64 return;
65 }
66
67 float local_min = FLT_MAX;
68 float local_max = -FLT_MAX;
69 for (int i = 0; i < 8; i++) {
70 float z = dot(box.corners[i].xyz, -light.z_axis());
71 local_min = min(local_min, z);
72 local_max = max(local_max, z);
73 }
74
75 if (local_id == 0u) {
78 }
79
80 barrier();
81
82 /* Quantization bias. */
83 local_min -= abs(local_min) * 0.01f;
84 local_max += abs(local_max) * 0.01f;
85
86 if (is_valid) {
87 /* Intermediate result. Min/Max of a compute group. */
90 }
91
92 barrier();
93
94 if (local_id == 0u) {
95 /* Final result. Min/Max of the whole dispatch. */
96 atomicMin(srt.light_buf_write[l_index].clip_near, srt.global_min);
97 atomicMax(srt.light_buf_write[l_index].clip_far, srt.global_max);
98 /* TODO(fclem): This feel unnecessary but we currently have no indexing from
99 * tile-map to lights. This is because the lights are selected by culling phase. */
100 for (int i = light.tilemap_index; i <= light.tilemap_max_get(); i++) {
101 int index = srt.tilemaps_buf[i].clip_data_index;
102 atomicMin(srt.tilemaps_clip_buf[index].clip_near, srt.global_min);
103 atomicMax(srt.tilemaps_clip_buf[index].clip_far, srt.global_max);
104 }
105 }
106
107 /* No need for barrier here since global_min/max is only read by thread 0 before being reset by
108 * thread 0. */
109 }
110
111 void eval_local(TilemapBounds & /*srt*/, uint /*index*/, LightData /*light*/) {}
112};
113
114} // namespace eevee::shadow
115
120
121namespace eevee::shadow {
122
123[[compute, local_size(SHADOW_BOUNDS_GROUP_SIZE)]]
125 [[global_invocation_id]] const uint3 global_id,
126 [[local_invocation_index]] const uint local_index)
127{
129 ctx.is_valid = true;
130 ctx.local_id = local_index;
131
132 if (srt.resource_len > 0) {
133 uint index = global_id.x;
134 /* Keep uniform control flow. Do not return. */
135 index = min(index, uint(srt.resource_len) - 1);
136 uint resource_id = srt.casters_id_buf[index];
137 resource_id = (resource_id & 0x7FFFFFFFu);
138
139 ObjectBounds bounds = srt.bounds_buf[resource_id];
141 ctx.box = shape_box(bounds.bounding_corners[0].xyz,
142 bounds.bounding_corners[0].xyz + bounds.bounding_corners[1].xyz,
143 bounds.bounding_corners[0].xyz + bounds.bounding_corners[2].xyz,
144 bounds.bounding_corners[0].xyz + bounds.bounding_corners[3].xyz);
145 }
146 else {
147 /* Create a dummy box so initialization happens even when there are no shadow casters. */
148 ctx.box = shape_box(float3(-1.0f),
149 float3(-1.0f) + float3(1.0f, 0.0f, 0.0f),
150 float3(-1.0f) + float3(0.0f, 1.0f, 0.0f),
151 float3(-1.0f) + float3(0.0f, 0.0f, 1.0f));
152 }
153
154 light::foreach(srt.light_data, ctx, srt);
155}
156
159
160} // namespace eevee::shadow
btScalar max
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
bool drw_bounds_corners_are_valid(ObjectBounds bounds)
Box shape_box(float3 v000, float3 v100, float3 v010, float3 v001)
#define LIGHT_NO_SHADOW
#define FLT_MAX
#define shared
#define local_invocation_index
#define storage(slot, qualifiers)
#define index(i)
#define push_constant
#define resource_table
#define global_invocation_id
#define compute
#define local_size(...)
int atomicMin(int &, int) RET
int atomicMax(int &, int) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
#define abs
void barrier()
int floatBitsToOrderedInt(float value)
void foreach(const LightRenderData &srt, CallbackT &cb, ResourceT &res)
PipelineCompute tilemap_bounds_init(tilemap_bounds_clear)
PipelineCompute tilemap_bounds(tilemap_bounds_min_max)
void tilemap_bounds_min_max(TilemapBounds &srt, const uint3 global_id, const uint local_index)
void tilemap_bounds_clear(TilemapBoundsInit &srt, const uint3 global_id)
#define min(a, b)
Definition sort.cc:38
float3 corners[8]
float4 bounding_corners[4]
const LightData(& light_buf)[]
void eval_directional(TilemapBounds &srt, uint l_index, LightData)
void eval_local(TilemapBounds &, uint, LightData)