Blender V5.3
eevee_light.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
21
22#pragma once
23
24#include "DNA_light_types.h"
25
26#include "DRW_gpu_wrapper.hh"
27
28#include "eevee_camera.hh"
29#include "eevee_light_shared.hh"
30#include "eevee_sampling.hh"
31#include "eevee_sync.hh"
32
33namespace blender::eevee {
34
35class Instance;
36class ShadowModule;
38class ShadowPunctual;
39
40/* -------------------------------------------------------------------- */
43
50
51struct Light : public LightData, NonCopyable {
52 public:
53 bool initialized = false;
54 bool used = false;
55
59
62
64 {
65 /* Avoid valgrind warning. */
66 this->type = LIGHT_SUN;
67 }
68
69 /* Only used for debugging. */
70#ifndef NDEBUG
71 Light(Light &&other)
72 {
73 *static_cast<LightData *>(this) = other;
74 this->initialized = other.initialized;
75 this->used = other.used;
76 this->directional = other.directional;
77 this->punctual = other.punctual;
78 this->shadow_set_membership = other.shadow_set_membership;
79 other.directional = nullptr;
80 other.punctual = nullptr;
81 }
82
84 {
85 BLI_assert(directional == nullptr);
86 BLI_assert(punctual == nullptr);
87 }
88#endif
89
90 void sync(ShadowModule &shadows,
92 char visibility_flag,
93 const blender::Light *la,
96 float threshold);
97
98 void shadow_ensure(ShadowModule &shadows);
99 void shadow_discard_safe(ShadowModule &shadows);
100
101 void debug_draw();
102
103 private:
104 float shadow_lod_min_get(const blender::Light *la);
105 float shadow_shape_size_get(const blender::Light *la);
106 float attenuation_radius_get(const blender::Light *la, float light_threshold, float light_power);
107 void shape_parameters_set(const blender::Light *la,
108 const float3 &scale,
109 const float3 &z_axis,
110 float threshold,
111 bool use_jitter);
112 float shape_radiance_get();
113 float point_radiance_get();
114};
115
117
118/* -------------------------------------------------------------------- */
121
126 friend ShadowModule;
127
128 private:
129 /* Keep tile count reasonable for memory usage and 2D culling performance. */
130 static constexpr uint max_memory_threshold = 32 * 1024 * 1024; /* 32 MiB */
131 static constexpr uint max_word_count_threshold = max_memory_threshold / sizeof(uint);
132 static constexpr uint max_tile_count_threshold = 8192;
133
134 Instance &inst_;
135
137 Map<ObjectKey, Light> light_map_;
142 ObjectKey world_sunlight_key_[WORLD_SUN_MAX] = {ObjectKey(WORLD_SUN_DIFFUSE),
145 LightDataBuf light_buf_ = {"Lights_no_cull"};
147 float light_threshold_ = 0.01f;
149 bool use_scene_lights_ = false;
151 bool use_sun_lights_ = false;
153 int sun_lights_len_ = 0;
154 int local_lights_len_ = 0;
156 int lights_len_ = 0;
157
161
163 LightDataBuf culling_light_buf_ = {"Lights_culled"};
165 LightCullingDataBuf culling_data_buf_ = {"LightCull_data"};
167 LightCullingZdistBuf culling_zdist_buf_ = {"LightCull_zdist"};
169 LightCullingKeyBuf culling_key_buf_ = {"LightCull_key"};
171 LightCullingZbinBuf culling_zbin_buf_ = {"LightCull_zbin"};
173 LightCullingTileBuf culling_tile_buf_ = {"LightCull_tile"};
175 PassSimple culling_ps_ = {"LightCulling"};
177 uint total_word_count_ = 0;
179 bool view_is_flipped_ = false;
180
182 PassSimple update_ps_ = {"LightUpdate"};
184 PassSimple shape_display_ps_ = {"Light.ShapeDisplay"};
185
187 PassSimple debug_draw_ps_ = {"LightCulling.Debug"};
188
189 public:
190 LightModule(Instance &inst) : inst_(inst) {};
191 ~LightModule();
192
193 void begin_sync();
194 void sync_light(const ObjectRef &ob_ref);
195 void end_sync();
196
200 void set_view(View &view, const int2 extent);
201
202 void shape_display_draw(View &view, gpu::FrameBuffer *view_fb);
203 void debug_draw(View &view, gpu::FrameBuffer *view_fb);
204
205 template<typename PassType> void bind_resources(PassType &pass)
206 {
207 pass.bind_ssbo(LIGHT_CULL_BUF_SLOT, &culling_data_buf_);
208 pass.bind_ssbo(LIGHT_BUF_SLOT, &culling_light_buf_);
209 pass.bind_ssbo(LIGHT_ZBIN_BUF_SLOT, &culling_zbin_buf_);
210 pass.bind_ssbo(LIGHT_TILE_BUF_SLOT, &culling_tile_buf_);
211 }
212
213 private:
214 void culling_pass_sync();
215 void update_pass_sync();
216 void shape_display_pass_sync();
217 void debug_pass_sync();
218
219 void add_world_sun_light(const ObjectKey &key, bool use_diffuse, bool use_glossy);
220};
221
223
224} // namespace blender::eevee
NonCopyable(const NonCopyable &other)=delete
A running instance of the engine.
void sync_light(const ObjectRef &ob_ref)
void set_view(View &view, const int2 extent)
void bind_resources(PassType &pass)
void shape_display_draw(View &view, gpu::FrameBuffer *view_fb)
void debug_draw(View &view, gpu::FrameBuffer *view_fb)
#define LIGHT_BUF_SLOT
#define LIGHT_ZBIN_BUF_SLOT
#define LIGHT_TILE_BUF_SLOT
#define LIGHT_CULL_BUF_SLOT
float3x3 scale(float3x3 mat, float2 scale)
PassType
detail::Pass< command::DrawCommandBuf > PassSimple
draw::StorageArrayBuffer< LightData, LIGHT_CHUNK > LightDataBuf
draw::StorageArrayBuffer< uint, CULLING_ZBIN_COUNT, true > LightCullingZbinBuf
draw::StorageArrayBuffer< float, LIGHT_CHUNK, true > LightCullingZdistBuf
draw::StorageArrayBuffer< uint, LIGHT_CHUNK, true > LightCullingTileBuf
draw::StorageBuffer< LightCullingData > LightCullingDataBuf
draw::StorageArrayBuffer< uint, LIGHT_CHUNK, true > LightCullingKeyBuf
VecBase< uint32_t, 2 > uint2
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
unsigned int uint
Definition BKE_text.h:55
MatBase< float, 4, 4 > float4x4
VecBase< int32_t, 2 > int2
VecBase< float, 3 > float3
void sync(ShadowModule &shadows, float4x4 object_to_world, char visibility_flag, const blender::Light *la, uint64_t light_set_membership, uint64_t shadow_set_membership, float threshold)
void shadow_discard_safe(ShadowModule &shadows)
Light(Light &&other)
ShadowDirectional * directional
void shadow_ensure(ShadowModule &shadows)
ShadowPunctual * punctual