Blender V5.3
eevee_light_shared.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
10
11#pragma once
12
13#include "eevee_defines.hh"
14#include "eevee_transform.hh"
15
16#ifndef GPU_SHADER
17# include "BLI_math_bits.hh"
18
19namespace blender::eevee {
20#endif
21
22#define LIGHT_NO_SHADOW -1
23
31
32 /* Index of each components. */
35
37};
38
42 /* Point light. */
45 /* Spot light. */
48 /* Area light. */
51};
52
54 /* True if the light shape should be invisible to camera rays. */
56 /* True if the light uses jittered soft shadows. */
58};
59
60static inline bool is_area_light(eLightType type)
61{
62 return type >= LIGHT_RECT;
63}
64
65static inline bool is_point_light(eLightType type)
66{
67 return type >= LIGHT_OMNI_SPHERE && type <= LIGHT_SPOT_DISK;
68}
69
70static inline bool is_spot_light(eLightType type)
71{
72 return type == LIGHT_SPOT_SPHERE || type == LIGHT_SPOT_DISK;
73}
74
75static inline bool is_sphere_light(eLightType type)
76{
77 return type == LIGHT_SPOT_SPHERE || type == LIGHT_OMNI_SPHERE;
78}
79
80static inline bool is_oriented_disk_light(eLightType type)
81{
82 return type == LIGHT_SPOT_DISK || type == LIGHT_OMNI_DISK;
83}
84
85static inline bool is_sun_light(eLightType type)
86{
87 return type < LIGHT_OMNI_SPHERE;
88}
89
90static inline bool is_local_light(eLightType type)
91{
92 return type >= LIGHT_OMNI_SPHERE;
93}
94
108
109/* Untyped local light data. Gets reinterpreted to LightSpotData and LightAreaData.
110 * Allow access to local light common data without casting. */
113
115 int tilemaps_count; /* Leaked from LightLocalCommon because of alignment. */
116 float _pad0;
117 float _pad1;
118 float _pad2;
119
121 float _pad4;
122 float _pad5;
123};
124
125/* Despite the name, is also used for omni light. */
128
130 int tilemaps_count; /* Leaked from LightLocalCommon because of alignment. */
131 float _pad0;
132 float _pad1;
134 float spot_mul;
135
139 float spot_tan;
141};
142
145
147 int tilemaps_count; /* Leaked from LightLocalCommon because of alignment. */
148 float _pad0;
149 float _pad1;
150 float _pad2;
151
156 float _pad6;
157};
158
160 /* Sun direction for shading. Use object_to_world for getting into shadow space. */
162 /* Radius of the sun disk, one unit away from a shading point. */
164
169
173 float _pad3;
174 float _pad4;
175
181};
182
190
195
197
199
204
211 /* Radius in pixels for shadow filtering. */
213
214 /* Shadow Map resolution bias. */
215 float lod_bias;
216 /* Shadow Map resolution maximum resolution. */
217 float lod_min;
219
226
228 {
229 return object_to_world.x_axis();
230 }
232 {
233 return object_to_world.y_axis();
234 }
236 {
237 return object_to_world.z_axis();
238 }
240 {
241 return object_to_world.location();
242 }
243
244 int tilemap_max_get() const
245 {
246 /* This is not something we need in performance critical code. */
247 if (is_sun_light(this->type)) {
248 return this->tilemap_index + (this->sun.clipmap_lod_max - this->sun.clipmap_lod_min);
249 }
250 return this->tilemap_index + this->local.tilemaps_count - 1;
251 }
252
253 /* Return the number of tilemap needed for a local light. */
255 {
256 if (is_spot_light(this->type)) {
257 return (this->spot.spot_tan > tanf(EEVEE_PI / 4.0)) ? 5 : 1;
258 }
259 if (is_area_light(this->type)) {
260 return 5;
261 }
262 return 6;
263 }
264};
265
266/* -------------------------------------------------------------------- */
269
270/* Number of items we can cull. Limited by how we store CullingZBin. */
271static constexpr int CULLING_MAX_ITEM = 65536;
272/* Fine grained subdivision in the Z direction. Limited by the LDS in z-binning compute shader. */
273static constexpr int CULLING_ZBIN_COUNT = 4096;
274/* Max tile map resolution per axes. */
275static constexpr int CULLING_TILE_RES = 16;
276
304
306
307#ifndef GPU_SHADER
308} // namespace blender::eevee
309#endif
#define host_shared
int32_t bool32_t
#define EEVEE_PI
static bool is_sphere_light(eLightType type)
static constexpr int CULLING_ZBIN_COUNT
static bool is_area_light(eLightType type)
static constexpr int CULLING_TILE_RES
static constexpr int CULLING_MAX_ITEM
static bool is_sun_light(eLightType type)
static bool is_spot_light(eLightType type)
static bool is_oriented_disk_light(eLightType type)
static bool is_local_light(eLightType type)
static bool is_point_light(eLightType type)
VecBase< uint32_t, 2 > uint2
unsigned int uint
Definition BKE_text.h:55
VecBase< float, 4 > float4
unsigned int uint32_t
Definition BKE_text.h:81
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< float, 3 > float3
#define tanf