Blender V4.5
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 "eevee_camera.hh"
27#include "eevee_sampling.hh"
29#include "eevee_sync.hh"
30
31namespace blender::eevee {
32
33class Instance;
34class ShadowModule;
35
36/* -------------------------------------------------------------------- */
39
40struct Light : public LightData, NonCopyable {
41 public:
42 bool initialized = false;
43 bool used = false;
44
48
50 {
51 /* Avoid valgrind warning. */
52 this->type = LIGHT_SUN;
53 }
54
55 /* Only used for debugging. */
56#ifndef NDEBUG
57 Light(Light &&other)
58 {
59 *static_cast<LightData *>(this) = other;
60 this->initialized = other.initialized;
61 this->used = other.used;
62 this->directional = other.directional;
63 this->punctual = other.punctual;
64 other.directional = nullptr;
65 other.punctual = nullptr;
66 }
67
69 {
70 BLI_assert(directional == nullptr);
71 BLI_assert(punctual == nullptr);
72 }
73#endif
74
75 void sync(ShadowModule &shadows,
76 float4x4 object_to_world,
77 char visibility_flag,
78 const ::Light *la,
79 const LightLinking *light_linking,
80 float threshold);
81
82 void shadow_ensure(ShadowModule &shadows);
83 void shadow_discard_safe(ShadowModule &shadows);
84
85 void debug_draw();
86
87 private:
88 float shadow_lod_min_get(const ::Light *la);
89 float shadow_shape_size_get(const ::Light *la);
90 float attenuation_radius_get(const ::Light *la, float light_threshold, float light_power);
91 void shape_parameters_set(const ::Light *la,
92 const float3 &scale,
93 const float3 &z_axis,
94 float threshold,
95 bool use_jitter);
96 float shape_radiance_get();
97 float point_radiance_get();
98};
99
101
102/* -------------------------------------------------------------------- */
105
110 friend ShadowModule;
111
112 private:
113 /* Keep tile count reasonable for memory usage and 2D culling performance. */
114 static constexpr uint max_memory_threshold = 32 * 1024 * 1024; /* 32 MiB */
115 static constexpr uint max_word_count_threshold = max_memory_threshold / sizeof(uint);
116 static constexpr uint max_tile_count_threshold = 8192;
117
118 Instance &inst_;
119
121 Map<ObjectKey, Light> light_map_;
122 ObjectKey world_sunlight_key;
124 LightDataBuf light_buf_ = {"Lights_no_cull"};
126 float light_threshold_ = 0.01f;
128 bool use_scene_lights_ = false;
130 bool use_sun_lights_ = false;
132 int sun_lights_len_ = 0;
133 int local_lights_len_ = 0;
135 int lights_len_ = 0;
136
140
142 LightDataBuf culling_light_buf_ = {"Lights_culled"};
144 LightCullingDataBuf culling_data_buf_ = {"LightCull_data"};
146 LightCullingZdistBuf culling_zdist_buf_ = {"LightCull_zdist"};
148 LightCullingKeyBuf culling_key_buf_ = {"LightCull_key"};
150 LightCullingZbinBuf culling_zbin_buf_ = {"LightCull_zbin"};
152 LightCullingTileBuf culling_tile_buf_ = {"LightCull_tile"};
154 PassSimple culling_ps_ = {"LightCulling"};
156 uint total_word_count_ = 0;
158 bool view_is_flipped_ = false;
159
161 PassSimple update_ps_ = {"LightUpdate"};
162
164 PassSimple debug_draw_ps_ = {"LightCulling.Debug"};
165
166 public:
167 LightModule(Instance &inst) : inst_(inst){};
168 ~LightModule();
169
170 void begin_sync();
171 void sync_light(const Object *ob, ObjectHandle &handle);
172 void end_sync();
173
177 void set_view(View &view, const int2 extent);
178
179 void debug_draw(View &view, GPUFrameBuffer *view_fb);
180
181 template<typename PassType> void bind_resources(PassType &pass)
182 {
183 pass.bind_ssbo(LIGHT_CULL_BUF_SLOT, &culling_data_buf_);
184 pass.bind_ssbo(LIGHT_BUF_SLOT, &culling_light_buf_);
185 pass.bind_ssbo(LIGHT_ZBIN_BUF_SLOT, &culling_zbin_buf_);
186 pass.bind_ssbo(LIGHT_TILE_BUF_SLOT, &culling_tile_buf_);
187 }
188
189 private:
190 void culling_pass_sync();
191 void update_pass_sync();
192 void debug_pass_sync();
193};
194
196
197} // 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, GPUFrameBuffer *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