Blender V5.0
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
61 {
62 /* Avoid valgrind warning. */
63 this->type = LIGHT_SUN;
64 }
65
66 /* Only used for debugging. */
67#ifndef NDEBUG
68 Light(Light &&other)
69 {
70 *static_cast<LightData *>(this) = other;
71 this->initialized = other.initialized;
72 this->used = other.used;
73 this->directional = other.directional;
74 this->punctual = other.punctual;
75 other.directional = nullptr;
76 other.punctual = nullptr;
77 }
78
80 {
81 BLI_assert(directional == nullptr);
82 BLI_assert(punctual == nullptr);
83 }
84#endif
85
86 void sync(ShadowModule &shadows,
87 float4x4 object_to_world,
88 char visibility_flag,
89 const ::Light *la,
90 const LightLinking *light_linking,
91 float threshold);
92
93 void shadow_ensure(ShadowModule &shadows);
94 void shadow_discard_safe(ShadowModule &shadows);
95
96 void debug_draw();
97
98 private:
99 float shadow_lod_min_get(const ::Light *la);
100 float shadow_shape_size_get(const ::Light *la);
101 float attenuation_radius_get(const ::Light *la, float light_threshold, float light_power);
102 void shape_parameters_set(const ::Light *la,
103 const float3 &scale,
104 const float3 &z_axis,
105 float threshold,
106 bool use_jitter);
107 float shape_radiance_get();
108 float point_radiance_get();
109};
110
112
113/* -------------------------------------------------------------------- */
116
121 friend ShadowModule;
122
123 private:
124 /* Keep tile count reasonable for memory usage and 2D culling performance. */
125 static constexpr uint max_memory_threshold = 32 * 1024 * 1024; /* 32 MiB */
126 static constexpr uint max_word_count_threshold = max_memory_threshold / sizeof(uint);
127 static constexpr uint max_tile_count_threshold = 8192;
128
129 Instance &inst_;
130
132 Map<ObjectKey, Light> light_map_;
133 ObjectKey world_sunlight_key;
135 LightDataBuf light_buf_ = {"Lights_no_cull"};
137 float light_threshold_ = 0.01f;
139 bool use_scene_lights_ = false;
141 bool use_sun_lights_ = false;
143 int sun_lights_len_ = 0;
144 int local_lights_len_ = 0;
146 int lights_len_ = 0;
147
151
153 LightDataBuf culling_light_buf_ = {"Lights_culled"};
155 LightCullingDataBuf culling_data_buf_ = {"LightCull_data"};
157 LightCullingZdistBuf culling_zdist_buf_ = {"LightCull_zdist"};
159 LightCullingKeyBuf culling_key_buf_ = {"LightCull_key"};
161 LightCullingZbinBuf culling_zbin_buf_ = {"LightCull_zbin"};
163 LightCullingTileBuf culling_tile_buf_ = {"LightCull_tile"};
165 PassSimple culling_ps_ = {"LightCulling"};
167 uint total_word_count_ = 0;
169 bool view_is_flipped_ = false;
170
172 PassSimple update_ps_ = {"LightUpdate"};
173
175 PassSimple debug_draw_ps_ = {"LightCulling.Debug"};
176
177 public:
178 LightModule(Instance &inst) : inst_(inst) {};
179 ~LightModule();
180
181 void begin_sync();
182 void sync_light(const Object *ob, ObjectHandle &handle);
183 void end_sync();
184
188 void set_view(View &view, const int2 extent);
189
190 void debug_draw(View &view, gpu::FrameBuffer *view_fb);
191
192 template<typename PassType> void bind_resources(PassType &pass)
193 {
194 pass.bind_ssbo(LIGHT_CULL_BUF_SLOT, &culling_data_buf_);
195 pass.bind_ssbo(LIGHT_BUF_SLOT, &culling_light_buf_);
196 pass.bind_ssbo(LIGHT_ZBIN_BUF_SLOT, &culling_zbin_buf_);
197 pass.bind_ssbo(LIGHT_TILE_BUF_SLOT, &culling_tile_buf_);
198 }
199
200 private:
201 void culling_pass_sync();
202 void update_pass_sync();
203 void debug_pass_sync();
204};
205
207
208} // namespace blender::eevee
#define BLI_assert(a)
Definition BLI_assert.h:46
unsigned int uint
static AppView * view
NonCopyable(const NonCopyable &other)=delete
A running instance of the engine.
void sync_light(const Object *ob, ObjectHandle &handle)
void set_view(View &view, const int2 extent)
void bind_resources(PassType &pass)
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
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
MatBase< T, NumCol, NumRow > scale(const MatBase< T, NumCol, NumRow > &mat, const VectorT &scale)
MatBase< float, 4, 4 > float4x4
VecBase< int32_t, 2 > int2
VecBase< float, 3 > float3
void shadow_discard_safe(ShadowModule &shadows)
Light(Light &&other)
ShadowDirectional * directional
void shadow_ensure(ShadowModule &shadows)
void sync(ShadowModule &shadows, float4x4 object_to_world, char visibility_flag, const ::Light *la, const LightLinking *light_linking, float threshold)
ShadowPunctual * punctual