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