Debian Codegraph @

servers/rendering/renderer_rd/storage_rd/light_storage.h

raw symbols SCIP
1 /**************************************************************************/
2 /* light_storage.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "core/templates/local_vector.h"
34 #include "core/templates/paged_array.h"
35 #include "core/templates/rid_owner.h"
36 #include "core/templates/self_list.h"
37 #include "servers/rendering/renderer_rd/cluster_builder_rd.h"
38 #include "servers/rendering/renderer_rd/environment/sky.h"
39 #include "servers/rendering/renderer_rd/storage_rd/forward_id_storage.h"
40 #include "servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.h"
41 #include "servers/rendering/renderer_rd/storage_rd/texture_storage.h"
42 #include "servers/rendering/storage/light_storage.h"
43 #include "servers/rendering/storage/utilities.h"
44
45 class RenderDataRD;
46
47 namespace RendererRD {
48
49 class LightStorage : public RendererLightStorage {
50 public:
51 enum ShadowAtlastQuadrant : uint32_t {
52 QUADRANT_SHIFT = 27,
53 OMNI_LIGHT_FLAG = 1 << 26,
54 SHADOW_INDEX_MASK = OMNI_LIGHT_FLAG - 1,
55 SHADOW_INVALID = 0xFFFFFFFF
56 };
57
58 private:
59 static LightStorage *singleton;
60 uint32_t max_cluster_elements = 512;
61
62 /* LIGHT */
63 struct Light {
64 RS::LightType type;
65 float param[RS::LIGHT_PARAM_MAX];
66 Color color = Color(1, 1, 1, 1);
67 RID projector;
68 bool shadow = false;
69 bool negative = false;
70 bool reverse_cull = false;
71 RS::LightBakeMode bake_mode = RS::LIGHT_BAKE_DYNAMIC;
72 uint32_t max_sdfgi_cascade = 2;
73 uint32_t cull_mask = 0xFFFFFFFF;
74 uint32_t shadow_caster_mask = 0xFFFFFFFF;
75 bool distance_fade = false;
76 real_t distance_fade_begin = 40.0;
77 real_t distance_fade_shadow = 50.0;
78 real_t distance_fade_length = 10.0;
79 RS::LightOmniShadowMode omni_shadow_mode = RS::LIGHT_OMNI_SHADOW_DUAL_PARABOLOID;
80 RS::LightDirectionalShadowMode directional_shadow_mode = RS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL;
81 bool directional_blend_splits = false;
82 RS::LightDirectionalSkyMode directional_sky_mode = RS::LIGHT_DIRECTIONAL_SKY_MODE_LIGHT_AND_SKY;
83 uint64_t version = 0;
84
85 Dependency dependency;
86 };
87
88 mutable RID_Owner<Light, true> light_owner;
89
90 /* LIGHT INSTANCE */
91
92 struct LightInstance {
93 struct ShadowTransform {
94 Projection camera;
95 Transform3D transform;
96 float farplane = 0.0;
97 float split = 0.0;
98 float bias_scale = 0.0;
99 float shadow_texel_size = 0.0;
100 float range_begin = 0.0;
101 Rect2 atlas_rect;
102 Vector2 uv_scale;
103 };
104
105 RS::LightType light_type = RS::LIGHT_DIRECTIONAL;
106
107 ShadowTransform shadow_transform[6];
108
109 AABB aabb;
110 RID self;
111 RID light;
112 Transform3D transform;
113
114 Vector3 light_vector;
115 Vector3 spot_vector;
116 float linear_att = 0.0;
117
118 uint64_t shadow_pass = 0;
119 uint64_t last_scene_pass = 0;
120 uint64_t last_scene_shadow_pass = 0;
121 uint64_t last_pass = 0;
122 uint32_t cull_mask = 0;
123 uint32_t light_directional_index = 0;
124
125 Rect2 directional_rect;
126
127 HashSet<RID> shadow_atlases; //shadow atlases where this light is registered
128
129 ForwardID forward_id = -1;
130
131 LightInstance() {}
132 };
133
134 mutable RID_Owner<LightInstance> light_instance_owner;
135
136 /* OMNI/SPOT LIGHT DATA */
137
138 struct LightData {
139 float position[3];
140 float inv_radius;
141 float direction[3]; // in omni, x and y are used for dual paraboloid offset
142 float size;
143
144 float color[3];
145 float attenuation;
146
147 float inv_spot_attenuation;
148 float cos_spot_angle;
149 float specular_amount;
150 float shadow_opacity;
151
152 float atlas_rect[4]; // in omni, used for atlas uv, in spot, used for projector uv
153 float shadow_matrix[16];
154 float shadow_bias;
155 float shadow_normal_bias;
156 float transmittance_bias;
157 float soft_shadow_size;
158 float soft_shadow_scale;
159 uint32_t mask;
160 float volumetric_fog_energy;
161 uint32_t bake_mode;
162 float projector_rect[4];
163 };
164
165 struct LightInstanceDepthSort {
166 float depth;
167 LightInstance *light_instance;
168 Light *light;
169 bool operator<(const LightInstanceDepthSort &p_sort) const {
170 return depth < p_sort.depth;
171 }
172 };
173
174 uint32_t max_lights;
175 uint32_t omni_light_count = 0;
176 uint32_t spot_light_count = 0;
177 LightData *omni_lights = nullptr;
178 LightData *spot_lights = nullptr;
179 LightInstanceDepthSort *omni_light_sort = nullptr;
180 LightInstanceDepthSort *spot_light_sort = nullptr;
181 RID omni_light_buffer;
182 RID spot_light_buffer;
183
184 /* DIRECTIONAL LIGHT DATA */
185
186 struct DirectionalLightData {
187 float direction[3];
188 float energy;
189 float color[3];
190 float size;
191 float specular;
192 uint32_t mask;
193 float softshadow_angle;
194 float soft_shadow_scale;
195 uint32_t blend_splits;
196 float shadow_opacity;
197 float fade_from;
198 float fade_to;
199 uint32_t pad[2];
200 uint32_t bake_mode;
201 float volumetric_fog_energy;
202 float shadow_bias[4];
203 float shadow_normal_bias[4];
204 float shadow_transmittance_bias[4];
205 float shadow_z_range[4];
206 float shadow_range_begin[4];
207 float shadow_split_offsets[4];
208 float shadow_matrices[4][16];
209 float uv_scale1[2];
210 float uv_scale2[2];
211 float uv_scale3[2];
212 float uv_scale4[2];
213 };
214
215 uint32_t max_directional_lights;
216 DirectionalLightData *directional_lights = nullptr;
217 RID directional_light_buffer;
218
219 /* REFLECTION PROBE */
220
221 struct ReflectionProbe {
222 RS::ReflectionProbeUpdateMode update_mode = RS::REFLECTION_PROBE_UPDATE_ONCE;
223 float intensity = 1.0;
224 float blend_distance = 1.0;
225 RS::ReflectionProbeAmbientMode ambient_mode = RS::REFLECTION_PROBE_AMBIENT_ENVIRONMENT;
226 Color ambient_color;
227 float ambient_color_energy = 1.0;
228 float max_distance = 0;
229 Vector3 size = Vector3(20, 20, 20);
230 Vector3 origin_offset;
231 bool interior = false;
232 bool box_projection = false;
233 bool enable_shadows = false;
234 uint32_t cull_mask = (1 << 20) - 1;
235 uint32_t reflection_mask = (1 << 20) - 1;
236 float mesh_lod_threshold = 0.01;
237 float baked_exposure = 1.0;
238
239 Dependency dependency;
240 };
241 mutable RID_Owner<ReflectionProbe, true> reflection_probe_owner;
242
243 /* REFLECTION ATLAS */
244
245 struct ReflectionAtlas {
246 int count = 0;
247 int size = 0;
248 int reflection_texture_size = 0;
249 float uv_border_size = 0.0;
250 bool update_always = false;
251
252 RID reflection;
253 RID color_buffer;
254 RID color_views[6];
255 RID color_fbs[6];
256 RID depth_buffer;
257 RID depth_fb;
258
259 struct Reflection {
260 RID owner;
261 RendererRD::SkyRD::ReflectionData data;
262 };
263
264 Vector<Reflection> reflections;
265
266 Ref<RenderSceneBuffersRD> render_buffers; // Further render buffers used.
267
268 ClusterBuilderRD *cluster_builder = nullptr; // only used if cluster builder is supported by the renderer.
269 };
270
271 mutable RID_Owner<ReflectionAtlas> reflection_atlas_owner;
272
273 void _reflection_atlas_clear(ReflectionAtlas *p_reflection_atlas);
274
275 /* REFLECTION PROBE INSTANCE */
276
277 struct ReflectionProbeInstance {
278 RID probe;
279 int atlas_index = -1;
280 RID atlas;
281
282 bool dirty = true;
283 bool rendering = false;
284 int processing_layer = 1;
285
286 uint64_t last_pass = 0;
287 uint32_t cull_mask = 0;
288
289 RendererRD::ForwardID forward_id = -1;
290
291 Transform3D transform;
292 };
293
294 mutable RID_Owner<ReflectionProbeInstance> reflection_probe_instance_owner;
295
296 /* REFLECTION DATA */
297
298 enum {
299 REFLECTION_AMBIENT_DISABLED = 0,
300 REFLECTION_AMBIENT_ENVIRONMENT = 1,
301 REFLECTION_AMBIENT_COLOR = 2,
302 };
303
304 struct ReflectionData {
305 float box_extents[3];
306 float index;
307 float box_offset[3];
308 uint32_t mask;
309 float ambient[3]; // ambient color,
310 float intensity;
311 float blend_distance;
312 uint32_t exterior;
313 uint32_t box_project;
314 uint32_t ambient_mode;
315 float exposure_normalization;
316 uint32_t pad0;
317 uint32_t pad1;
318 uint32_t pad2;
319 float local_matrix[16]; // up to here for spot and omni, rest is for directional
320 };
321
322 struct ReflectionProbeInstanceSort {
323 float size;
324 ReflectionProbeInstance *probe_instance;
325 bool operator<(const ReflectionProbeInstanceSort &p_sort) const {
326 return size < p_sort.size;
327 }
328 };
329
330 uint32_t max_reflections;
331 uint32_t reflection_count = 0;
332 // uint32_t max_reflection_probes_per_instance = 0; // seems unused
333 ReflectionData *reflections = nullptr;
334 ReflectionProbeInstanceSort *reflection_sort = nullptr;
335 RID reflection_buffer;
336
337 /* LIGHTMAP */
338
339 struct Lightmap {
340 RID light_texture;
341 RID shadow_texture;
342 RS::ShadowmaskMode shadowmask_mode = RS::SHADOWMASK_MODE_NONE;
343 bool uses_spherical_harmonics = false;
344 bool interior = false;
345 AABB bounds = AABB(Vector3(), Vector3(1, 1, 1));
346 float baked_exposure = 1.0;
347 Vector2i light_texture_size;
348 int32_t array_index = -1; //unassigned
349 PackedVector3Array points;
350 PackedColorArray point_sh;
351 PackedInt32Array tetrahedra;
352 PackedInt32Array bsp_tree;
353
354 struct BSP {
355 static const int32_t EMPTY_LEAF = INT32_MIN;
356 float plane[4];
357 int32_t over = EMPTY_LEAF, under = EMPTY_LEAF;
358 };
359
360 Dependency dependency;
361 };
362
363 bool using_lightmap_array;
364 Vector<RID> lightmap_textures;
365 uint64_t lightmap_array_version = 0;
366 float lightmap_probe_capture_update_speed = 4;
367
368 mutable RID_Owner<Lightmap, true> lightmap_owner;
369
370 Vector<RID> shadowmask_textures;
371
372 /* LIGHTMAP INSTANCE */
373
374 struct LightmapInstance {
375 RID lightmap;
376 Transform3D transform;
377 };
378
379 mutable RID_Owner<LightmapInstance> lightmap_instance_owner;
380
381 /* SHADOW ATLAS */
382
383 uint64_t shadow_atlas_realloc_tolerance_msec = 500;
384
385 struct ShadowShrinkStage {
386 RID texture;
387 RID filter_texture;
388 uint32_t size = 0;
389 };
390
391 struct ShadowAtlas {
392 struct Quadrant {
393 uint32_t subdivision = 0;
394
395 struct Shadow {
396 RID owner;
397 uint64_t version = 0;
398 uint64_t fog_version = 0; // used for fog
399 uint64_t alloc_tick = 0;
400
401 Shadow() {}
402 };
403
404 Vector<Shadow> shadows;
405
406 Quadrant() {}
407 } quadrants[4];
408
409 int size_order[4] = { 0, 1, 2, 3 };
410 uint32_t smallest_subdiv = 0;
411
412 int size = 0;
413 bool use_16_bits = true;
414
415 RID depth;
416 RID fb; //for copying
417
418 HashMap<RID, uint32_t> shadow_owners;
419 };
420
421 RID_Owner<ShadowAtlas> shadow_atlas_owner;
422
423 void _update_shadow_atlas(ShadowAtlas *shadow_atlas);
424
425 void _shadow_atlas_invalidate_shadow(ShadowAtlas::Quadrant::Shadow *p_shadow, RID p_atlas, ShadowAtlas *p_shadow_atlas, uint32_t p_quadrant, uint32_t p_shadow_idx);
426 bool _shadow_atlas_find_shadow(ShadowAtlas *shadow_atlas, int *p_in_quadrants, int p_quadrant_count, int p_current_subdiv, uint64_t p_tick, int &r_quadrant, int &r_shadow);
427 bool _shadow_atlas_find_omni_shadows(ShadowAtlas *shadow_atlas, int *p_in_quadrants, int p_quadrant_count, int p_current_subdiv, uint64_t p_tick, int &r_quadrant, int &r_shadow);
428
429 /* DIRECTIONAL SHADOW */
430
431 struct DirectionalShadow {
432 RID depth;
433 RID fb; //when renderign direct
434
435 int light_count = 0;
436 int size = 0;
437 bool use_16_bits = true;
438 int current_light = 0;
439 } directional_shadow;
440
441 /* SHADOW CUBEMAPS */
442
443 struct ShadowCubemap {
444 RID cubemap;
445 RID side_fb[6];
446 };
447
448 HashMap<int, ShadowCubemap> shadow_cubemaps;
449 ShadowCubemap *_get_shadow_cubemap(int p_size);
450
451 /* PIPELINE HINTS */
452
453 bool shadow_cubemaps_used = false;
454 bool shadow_dual_paraboloid_used = false;
455
456 public:
457 static LightStorage *get_singleton();
458
459 LightStorage();
460 virtual ~LightStorage();
461
462 bool free(RID p_rid);
463
464 /* Settings */
465 void set_max_cluster_elements(const uint32_t p_max_cluster_elements) {
466 max_cluster_elements = p_max_cluster_elements;
467 set_max_reflection_probes(p_max_cluster_elements);
468 set_max_lights(p_max_cluster_elements);
469 }
470 uint32_t get_max_cluster_elements() const { return max_cluster_elements; }
471
472 /* LIGHT */
473
474 bool owns_light(RID p_rid) { return light_owner.owns(p_rid); }
475
476 void _light_initialize(RID p_rid, RS::LightType p_type);
477
478 virtual RID directional_light_allocate() override;
479 virtual void directional_light_initialize(RID p_light) override;
480
481 virtual RID omni_light_allocate() override;
482 virtual void omni_light_initialize(RID p_light) override;
483
484 virtual RID spot_light_allocate() override;
485 virtual void spot_light_initialize(RID p_light) override;
486
487 virtual void light_free(RID p_rid) override;
488
489 virtual void light_set_color(RID p_light, const Color &p_color) override;
490 virtual void light_set_param(RID p_light, RS::LightParam p_param, float p_value) override;
491 virtual void light_set_shadow(RID p_light, bool p_enabled) override;
492 virtual void light_set_projector(RID p_light, RID p_texture) override;
493 virtual void light_set_negative(RID p_light, bool p_enable) override;
494 virtual void light_set_cull_mask(RID p_light, uint32_t p_mask) override;
495 virtual void light_set_distance_fade(RID p_light, bool p_enabled, float p_begin, float p_shadow, float p_length) override;
496 virtual void light_set_reverse_cull_face_mode(RID p_light, bool p_enabled) override;
497 virtual void light_set_shadow_caster_mask(RID p_light, uint32_t p_caster_mask) override;
498 virtual uint32_t light_get_shadow_caster_mask(RID p_light) const override;
499 virtual void light_set_bake_mode(RID p_light, RS::LightBakeMode p_bake_mode) override;
500 virtual void light_set_max_sdfgi_cascade(RID p_light, uint32_t p_cascade) override;
501
502 virtual void light_omni_set_shadow_mode(RID p_light, RS::LightOmniShadowMode p_mode) override;
503
504 virtual void light_directional_set_shadow_mode(RID p_light, RS::LightDirectionalShadowMode p_mode) override;
505 virtual void light_directional_set_blend_splits(RID p_light, bool p_enable) override;
506 virtual bool light_directional_get_blend_splits(RID p_light) const override;
507 virtual void light_directional_set_sky_mode(RID p_light, RS::LightDirectionalSkyMode p_mode) override;
508 virtual RS::LightDirectionalSkyMode light_directional_get_sky_mode(RID p_light) const override;
509
510 virtual RS::LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light) override;
511 virtual RS::LightOmniShadowMode light_omni_get_shadow_mode(RID p_light) override;
512
513 virtual RS::LightType light_get_type(RID p_light) const override {
514 const Light *light = light_owner.get_or_null(p_light);
515 ERR_FAIL_NULL_V(light, RS::LIGHT_DIRECTIONAL);
516
517 return light->type;
518 }
519 virtual AABB light_get_aabb(RID p_light) const override;
520
521 virtual float light_get_param(RID p_light, RS::LightParam p_param) override {
522 const Light *light = light_owner.get_or_null(p_light);
523 ERR_FAIL_NULL_V(light, 0);
524
525 return light->param[p_param];
526 }
527
528 _FORCE_INLINE_ RID light_get_projector(RID p_light) {
529 const Light *light = light_owner.get_or_null(p_light);
530 ERR_FAIL_NULL_V(light, RID());
531
532 return light->projector;
533 }
534
535 virtual Color light_get_color(RID p_light) override {
536 const Light *light = light_owner.get_or_null(p_light);
537 ERR_FAIL_NULL_V(light, Color());
538
539 return light->color;
540 }
541
542 _FORCE_INLINE_ bool light_is_distance_fade_enabled(RID p_light) {
543 const Light *light = light_owner.get_or_null(p_light);
544 return light->distance_fade;
545 }
546
547 _FORCE_INLINE_ float light_get_distance_fade_begin(RID p_light) {
548 const Light *light = light_owner.get_or_null(p_light);
549 return light->distance_fade_begin;
550 }
551
552 _FORCE_INLINE_ float light_get_distance_fade_shadow(RID p_light) {
553 const Light *light = light_owner.get_or_null(p_light);
554 return light->distance_fade_shadow;
555 }
556
557 _FORCE_INLINE_ float light_get_distance_fade_length(RID p_light) {
558 const Light *light = light_owner.get_or_null(p_light);
559 return light->distance_fade_length;
560 }
561
562 virtual bool light_has_shadow(RID p_light) const override {
563 const Light *light = light_owner.get_or_null(p_light);
564 ERR_FAIL_NULL_V(light, RS::LIGHT_DIRECTIONAL);
565
566 return light->shadow;
567 }
568
569 virtual bool light_has_projector(RID p_light) const override {
570 const Light *light = light_owner.get_or_null(p_light);
571 ERR_FAIL_NULL_V(light, RS::LIGHT_DIRECTIONAL);
572
573 return TextureStorage::get_singleton()->owns_texture(light->projector);
574 }
575
576 _FORCE_INLINE_ bool light_is_negative(RID p_light) const {
577 const Light *light = light_owner.get_or_null(p_light);
578 ERR_FAIL_NULL_V(light, RS::LIGHT_DIRECTIONAL);
579
580 return light->negative;
581 }
582
583 _FORCE_INLINE_ float light_get_transmittance_bias(RID p_light) const {
584 const Light *light = light_owner.get_or_null(p_light);
585 ERR_FAIL_NULL_V(light, 0.0);
586
587 return light->param[RS::LIGHT_PARAM_TRANSMITTANCE_BIAS];
588 }
589
590 virtual bool light_get_reverse_cull_face_mode(RID p_light) const override {
591 const Light *light = light_owner.get_or_null(p_light);
592 ERR_FAIL_NULL_V(light, false);
593
594 return light->reverse_cull;
595 }
596
597 virtual RS::LightBakeMode light_get_bake_mode(RID p_light) override;
598 virtual uint32_t light_get_max_sdfgi_cascade(RID p_light) override;
599 virtual uint64_t light_get_version(RID p_light) const override;
600 virtual uint32_t light_get_cull_mask(RID p_light) const override;
601
602 Dependency *light_get_dependency(RID p_light) const;
603
604 /* LIGHT INSTANCE API */
605
606 bool owns_light_instance(RID p_rid) { return light_instance_owner.owns(p_rid); }
607
608 virtual RID light_instance_create(RID p_light) override;
609 virtual void light_instance_free(RID p_light) override;
610 virtual void light_instance_set_transform(RID p_light_instance, const Transform3D &p_transform) override;
611 virtual void light_instance_set_aabb(RID p_light_instance, const AABB &p_aabb) override;
612 virtual void light_instance_set_shadow_transform(RID p_light_instance, const Projection &p_projection, const Transform3D &p_transform, float p_far, float p_split, int p_pass, float p_shadow_texel_size, float p_bias_scale = 1.0, float p_range_begin = 0, const Vector2 &p_uv_scale = Vector2()) override;
613 virtual void light_instance_mark_visible(RID p_light_instance) override;
614
615 virtual bool light_instance_is_shadow_visible_at_position(RID p_light_instance, const Vector3 &p_position) const override {
616 const LightInstance *light_instance = light_instance_owner.get_or_null(p_light_instance);
617 ERR_FAIL_NULL_V(light_instance, false);
618 const Light *light = light_owner.get_or_null(light_instance->light);
619 ERR_FAIL_NULL_V(light, false);
620
621 if (!light->shadow) {
622 return false;
623 }
624
625 if (!light->distance_fade) {
626 return true;
627 }
628
629 real_t distance = p_position.distance_to(light_instance->transform.origin);
630
631 if (distance > light->distance_fade_shadow + light->distance_fade_length) {
632 return false;
633 }
634
635 return true;
636 }
637
638 _FORCE_INLINE_ RID light_instance_get_base_light(RID p_light_instance) {
639 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
640 return li->light;
641 }
642
643 _FORCE_INLINE_ Transform3D light_instance_get_base_transform(RID p_light_instance) {
644 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
645 return li->transform;
646 }
647
648 _FORCE_INLINE_ AABB light_instance_get_base_aabb(RID p_light_instance) {
649 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
650 return li->aabb;
651 }
652
653 _FORCE_INLINE_ void light_instance_set_cull_mask(RID p_light_instance, uint32_t p_cull_mask) {
654 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
655 li->cull_mask = p_cull_mask;
656 }
657
658 _FORCE_INLINE_ uint32_t light_instance_get_cull_mask(RID p_light_instance) {
659 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
660 return li->cull_mask;
661 }
662
663 _FORCE_INLINE_ Rect2 light_instance_get_shadow_atlas_rect(RID p_light_instance, RID p_shadow_atlas, Vector2i &r_omni_offset) {
664 ShadowAtlas *shadow_atlas = shadow_atlas_owner.get_or_null(p_shadow_atlas);
665 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
666 uint32_t key = shadow_atlas->shadow_owners[li->self];
667
668 uint32_t quadrant = (key >> QUADRANT_SHIFT) & 0x3;
669 uint32_t shadow = key & SHADOW_INDEX_MASK;
670
671 ERR_FAIL_COND_V(shadow >= (uint32_t)shadow_atlas->quadrants[quadrant].shadows.size(), Rect2());
672
673 uint32_t atlas_size = shadow_atlas->size;
674 uint32_t quadrant_size = atlas_size >> 1;
675
676 uint32_t x = (quadrant & 1) * quadrant_size;
677 uint32_t y = (quadrant >> 1) * quadrant_size;
678
679 uint32_t shadow_size = (quadrant_size / shadow_atlas->quadrants[quadrant].subdivision);
680 x += (shadow % shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
681 y += (shadow / shadow_atlas->quadrants[quadrant].subdivision) * shadow_size;
682
683 if (key & OMNI_LIGHT_FLAG) {
684 if (((shadow + 1) % shadow_atlas->quadrants[quadrant].subdivision) == 0) {
685 r_omni_offset.x = 1 - int(shadow_atlas->quadrants[quadrant].subdivision);
686 r_omni_offset.y = 1;
687 } else {
688 r_omni_offset.x = 1;
689 r_omni_offset.y = 0;
690 }
691 }
692
693 uint32_t width = shadow_size;
694 uint32_t height = shadow_size;
695
696 return Rect2(x / float(shadow_atlas->size), y / float(shadow_atlas->size), width / float(shadow_atlas->size), height / float(shadow_atlas->size));
697 }
698
699 _FORCE_INLINE_ float light_instance_get_shadow_texel_size(RID p_light_instance, RID p_shadow_atlas) {
700 #ifdef DEBUG_ENABLED
701 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
702 ERR_FAIL_COND_V(!li->shadow_atlases.has(p_shadow_atlas), 0);
703 #endif
704 ShadowAtlas *shadow_atlas = shadow_atlas_owner.get_or_null(p_shadow_atlas);
705 ERR_FAIL_NULL_V(shadow_atlas, 0);
706 #ifdef DEBUG_ENABLED
707 ERR_FAIL_COND_V(!shadow_atlas->shadow_owners.has(p_light_instance), 0);
708 #endif
709 uint32_t key = shadow_atlas->shadow_owners[p_light_instance];
710
711 uint32_t quadrant = (key >> QUADRANT_SHIFT) & 0x3;
712
713 uint32_t quadrant_size = shadow_atlas->size >> 1;
714
715 uint32_t shadow_size = (quadrant_size / shadow_atlas->quadrants[quadrant].subdivision);
716
717 return float(1.0) / shadow_size;
718 }
719
720 _FORCE_INLINE_ Projection light_instance_get_shadow_camera(RID p_light_instance, int p_index) {
721 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
722 return li->shadow_transform[p_index].camera;
723 }
724
725 _FORCE_INLINE_ Transform3D light_instance_get_shadow_transform(RID p_light_instance, int p_index) {
726 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
727 return li->shadow_transform[p_index].transform;
728 }
729 _FORCE_INLINE_ float light_instance_get_shadow_bias_scale(RID p_light_instance, int p_index) {
730 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
731 return li->shadow_transform[p_index].bias_scale;
732 }
733 _FORCE_INLINE_ float light_instance_get_shadow_range(RID p_light_instance, int p_index) {
734 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
735 return li->shadow_transform[p_index].farplane;
736 }
737 _FORCE_INLINE_ float light_instance_get_shadow_range_begin(RID p_light_instance, int p_index) {
738 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
739 return li->shadow_transform[p_index].range_begin;
740 }
741
742 _FORCE_INLINE_ Vector2 light_instance_get_shadow_uv_scale(RID p_light_instance, int p_index) {
743 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
744 return li->shadow_transform[p_index].uv_scale;
745 }
746
747 _FORCE_INLINE_ void light_instance_set_directional_shadow_atlas_rect(RID p_light_instance, int p_index, const Rect2 p_atlas_rect) {
748 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
749 li->shadow_transform[p_index].atlas_rect = p_atlas_rect;
750 }
751
752 _FORCE_INLINE_ Rect2 light_instance_get_directional_shadow_atlas_rect(RID p_light_instance, int p_index) {
753 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
754 return li->shadow_transform[p_index].atlas_rect;
755 }
756
757 _FORCE_INLINE_ float light_instance_get_directional_shadow_split(RID p_light_instance, int p_index) {
758 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
759 return li->shadow_transform[p_index].split;
760 }
761
762 _FORCE_INLINE_ float light_instance_get_directional_shadow_texel_size(RID p_light_instance, int p_index) {
763 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
764 return li->shadow_transform[p_index].shadow_texel_size;
765 }
766
767 _FORCE_INLINE_ void light_instance_set_render_pass(RID p_light_instance, uint64_t p_pass) {
768 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
769 li->last_pass = p_pass;
770 }
771
772 _FORCE_INLINE_ uint64_t light_instance_get_render_pass(RID p_light_instance) {
773 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
774 return li->last_pass;
775 }
776
777 _FORCE_INLINE_ void light_instance_set_shadow_pass(RID p_light_instance, uint64_t p_pass) {
778 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
779 li->last_scene_shadow_pass = p_pass;
780 }
781
782 _FORCE_INLINE_ uint64_t light_instance_get_shadow_pass(RID p_light_instance) {
783 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
784 return li->last_scene_shadow_pass;
785 }
786
787 _FORCE_INLINE_ ForwardID light_instance_get_forward_id(RID p_light_instance) {
788 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
789 return li->forward_id;
790 }
791
792 _FORCE_INLINE_ RS::LightType light_instance_get_type(RID p_light_instance) {
793 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
794 return li->light_type;
795 }
796
797 _FORCE_INLINE_ void light_instance_set_directional_rect(RID p_light_instance, const Rect2 &p_directional_rect) {
798 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
799 li->directional_rect = p_directional_rect;
800 }
801
802 _FORCE_INLINE_ Rect2 light_instance_get_directional_rect(RID p_light_instance) {
803 LightInstance *li = light_instance_owner.get_or_null(p_light_instance);
804 return li->directional_rect;
805 }
806
807 /* LIGHT DATA */
808
809 void free_light_data();
810 void set_max_lights(const uint32_t p_max_lights);
811 RID get_omni_light_buffer() { return omni_light_buffer; }
812 RID get_spot_light_buffer() { return spot_light_buffer; }
813 RID get_directional_light_buffer() { return directional_light_buffer; }
814 uint32_t get_max_directional_lights() { return max_directional_lights; }
815 uint32_t get_directional_light_blend_splits(uint32_t p_directional_light_count) const {
816 uint32_t blend_splits = 0;
817 for (uint32_t i = 0; i < p_directional_light_count; i++) {
818 if (directional_lights[i].blend_splits) {
819 blend_splits |= 1U << i;
820 }
821 }
822
823 return blend_splits;
824 }
825 bool has_directional_shadows(const uint32_t p_directional_light_count) {
826 for (uint32_t i = 0; i < p_directional_light_count; i++) {
827 if (directional_lights[i].shadow_opacity > 0.001) {
828 return true;
829 }
830 }
831 return false;
832 }
833 void update_light_buffers(RenderDataRD *p_render_data, const PagedArray<RID> &p_lights, const Transform3D &p_camera_transform, RID p_shadow_atlas, bool p_using_shadows, uint32_t &r_directional_light_count, uint32_t &r_positional_light_count, bool &r_directional_light_soft_shadows);
834
835 /* REFLECTION PROBE */
836
837 bool owns_reflection_probe(RID p_rid) { return reflection_probe_owner.owns(p_rid); }
838
839 virtual RID reflection_probe_allocate() override;
840 virtual void reflection_probe_initialize(RID p_reflection_probe) override;
841 virtual void reflection_probe_free(RID p_rid) override;
842
843 virtual void reflection_probe_set_update_mode(RID p_probe, RS::ReflectionProbeUpdateMode p_mode) override;
844 virtual void reflection_probe_set_intensity(RID p_probe, float p_intensity) override;
845 virtual void reflection_probe_set_blend_distance(RID p_probe, float p_blend_distance) override;
846 virtual void reflection_probe_set_ambient_mode(RID p_probe, RS::ReflectionProbeAmbientMode p_mode) override;
847 virtual void reflection_probe_set_ambient_color(RID p_probe, const Color &p_color) override;
848 virtual void reflection_probe_set_ambient_energy(RID p_probe, float p_energy) override;
849 virtual void reflection_probe_set_max_distance(RID p_probe, float p_distance) override;
850 virtual void reflection_probe_set_size(RID p_probe, const Vector3 &p_size) override;
851 virtual void reflection_probe_set_origin_offset(RID p_probe, const Vector3 &p_offset) override;
852 virtual void reflection_probe_set_as_interior(RID p_probe, bool p_enable) override;
853 virtual void reflection_probe_set_enable_box_projection(RID p_probe, bool p_enable) override;
854 virtual void reflection_probe_set_enable_shadows(RID p_probe, bool p_enable) override;
855 virtual void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers) override;
856 virtual void reflection_probe_set_reflection_mask(RID p_probe, uint32_t p_layers) override;
857 virtual void reflection_probe_set_resolution(RID p_probe, int p_resolution) override;
858 virtual void reflection_probe_set_mesh_lod_threshold(RID p_probe, float p_ratio) override;
859
860 void reflection_probe_set_baked_exposure(RID p_probe, float p_exposure);
861
862 virtual AABB reflection_probe_get_aabb(RID p_probe) const override;
863 virtual RS::ReflectionProbeUpdateMode reflection_probe_get_update_mode(RID p_probe) const override;
864 virtual uint32_t reflection_probe_get_cull_mask(RID p_probe) const override;
865 virtual uint32_t reflection_probe_get_reflection_mask(RID p_probe) const override;
866 virtual Vector3 reflection_probe_get_size(RID p_probe) const override;
867 virtual Vector3 reflection_probe_get_origin_offset(RID p_probe) const override;
868 virtual float reflection_probe_get_origin_max_distance(RID p_probe) const override;
869 virtual float reflection_probe_get_mesh_lod_threshold(RID p_probe) const override;
870
871 float reflection_probe_get_baked_exposure(RID p_probe) const;
872 virtual bool reflection_probe_renders_shadows(RID p_probe) const override;
873
874 float reflection_probe_get_intensity(RID p_probe) const;
875 float reflection_probe_get_blend_distance(RID p_probe) const;
876 bool reflection_probe_is_interior(RID p_probe) const;
877 bool reflection_probe_is_box_projection(RID p_probe) const;
878 RS::ReflectionProbeAmbientMode reflection_probe_get_ambient_mode(RID p_probe) const;
879 Color reflection_probe_get_ambient_color(RID p_probe) const;
880 float reflection_probe_get_ambient_color_energy(RID p_probe) const;
881
882 Dependency *reflection_probe_get_dependency(RID p_probe) const;
883
884 /* REFLECTION ATLAS */
885
886 bool owns_reflection_atlas(RID p_rid) { return reflection_atlas_owner.owns(p_rid); }
887
888 virtual RID reflection_atlas_create() override;
889 virtual void reflection_atlas_free(RID p_ref_atlas) override;
890 virtual void reflection_atlas_set_size(RID p_ref_atlas, int p_reflection_size, int p_reflection_count) override;
891 virtual int reflection_atlas_get_size(RID p_ref_atlas) const override;
892
893 _FORCE_INLINE_ RID reflection_atlas_get_texture(RID p_ref_atlas) {
894 ReflectionAtlas *atlas = reflection_atlas_owner.get_or_null(p_ref_atlas);
895 ERR_FAIL_NULL_V(atlas, RID());
896 return atlas->reflection;
897 }
898
899 _FORCE_INLINE_ int reflection_atlas_get_texture_size(RID p_ref_atlas) {
900 ReflectionAtlas *atlas = reflection_atlas_owner.get_or_null(p_ref_atlas);
901 ERR_FAIL_NULL_V(atlas, 0);
902 return atlas->reflection_texture_size;
903 }
904
905 _FORCE_INLINE_ float reflection_atlas_get_border_size(RID p_ref_atlas) {
906 ReflectionAtlas *atlas = reflection_atlas_owner.get_or_null(p_ref_atlas);
907 ERR_FAIL_NULL_V(atlas, 0.0);
908 return atlas->uv_border_size;
909 }
910
911 /* REFLECTION PROBE INSTANCE */
912
913 bool owns_reflection_probe_instance(RID p_rid) { return reflection_probe_instance_owner.owns(p_rid); }
914
915 virtual RID reflection_probe_instance_create(RID p_probe) override;
916 virtual void reflection_probe_instance_free(RID p_instance) override;
917 virtual void reflection_probe_instance_set_transform(RID p_instance, const Transform3D &p_transform) override;
918 virtual bool reflection_probe_has_atlas_index(RID p_instance) override;
919 virtual void reflection_probe_release_atlas_index(RID p_instance) override;
920 virtual bool reflection_probe_instance_needs_redraw(RID p_instance) override;
921 virtual bool reflection_probe_instance_has_reflection(RID p_instance) override;
922 virtual bool reflection_probe_instance_begin_render(RID p_instance, RID p_reflection_atlas) override;
923 virtual bool reflection_probe_instance_end_render(RID p_instance, RID p_reflection_atlas) override;
924 virtual Ref<RenderSceneBuffers> reflection_probe_atlas_get_render_buffers(RID p_reflection_atlas) override;
925 virtual bool reflection_probe_instance_postprocess_step(RID p_instance) override;
926
927 uint32_t reflection_probe_instance_get_resolution(RID p_instance);
928 RID reflection_probe_instance_get_framebuffer(RID p_instance, int p_index);
929 RID reflection_probe_instance_get_depth_framebuffer(RID p_instance, int p_index);
930
931 _FORCE_INLINE_ RID reflection_probe_instance_get_probe(RID p_instance) {
932 ReflectionProbeInstance *rpi = reflection_probe_instance_owner.get_or_null(p_instance);
933 ERR_FAIL_NULL_V(rpi, RID());
934
935 return rpi->probe;
936 }
937
938 _FORCE_INLINE_ RendererRD::ForwardID reflection_probe_instance_get_forward_id(RID p_instance) {
939 ReflectionProbeInstance *rpi = reflection_probe_instance_owner.get_or_null(p_instance);
940 ERR_FAIL_NULL_V(rpi, 0);
941
942 return rpi->forward_id;
943 }
944
945 _FORCE_INLINE_ void reflection_probe_instance_set_cull_mask(RID p_instance, uint32_t p_render_pass) {
946 ReflectionProbeInstance *rpi = reflection_probe_instance_owner.get_or_null(p_instance);
947 ERR_FAIL_NULL(rpi);
948 rpi->cull_mask = p_render_pass;
949 }
950
951 _FORCE_INLINE_ void reflection_probe_instance_set_render_pass(RID p_instance, uint32_t p_render_pass) {
952 ReflectionProbeInstance *rpi = reflection_probe_instance_owner.get_or_null(p_instance);
953 ERR_FAIL_NULL(rpi);
954 rpi->last_pass = p_render_pass;
955 }
956
957 _FORCE_INLINE_ uint32_t reflection_probe_instance_get_render_pass(RID p_instance) {
958 ReflectionProbeInstance *rpi = reflection_probe_instance_owner.get_or_null(p_instance);
959 ERR_FAIL_NULL_V(rpi, 0);
960
961 return rpi->last_pass;
962 }
963
964 _FORCE_INLINE_ Transform3D reflection_probe_instance_get_transform(RID p_instance) {
965 ReflectionProbeInstance *rpi = reflection_probe_instance_owner.get_or_null(p_instance);
966 ERR_FAIL_NULL_V(rpi, Transform3D());
967
968 return rpi->transform;
969 }
970
971 _FORCE_INLINE_ int reflection_probe_instance_get_atlas_index(RID p_instance) {
972 ReflectionProbeInstance *rpi = reflection_probe_instance_owner.get_or_null(p_instance);
973 ERR_FAIL_NULL_V(rpi, -1);
974
975 return rpi->atlas_index;
976 }
977
978 ClusterBuilderRD *reflection_probe_instance_get_cluster_builder(RID p_instance, ClusterBuilderSharedDataRD *p_cluster_builder_shared);
979
980 /* REFLECTION DATA */
981
982 void free_reflection_data();
983 void set_max_reflection_probes(const uint32_t p_max_reflection_probes);
984 RID get_reflection_probe_buffer() { return reflection_buffer; }
985 void update_reflection_probe_buffer(RenderDataRD *p_render_data, const PagedArray<RID> &p_reflections, const Transform3D &p_camera_inverse_transform, RID p_environment);
986 static RD::DataFormat get_reflection_probe_color_format();
987 static uint32_t get_reflection_probe_color_usage_bits(bool p_storage);
988 static RD::DataFormat get_reflection_probe_depth_format();
989 static uint32_t get_reflection_probe_depth_usage_bits();
990
991 /* LIGHTMAP */
992
993 bool owns_lightmap(RID p_rid) { return lightmap_owner.owns(p_rid); }
994
995 virtual RID lightmap_allocate() override;
996 virtual void lightmap_initialize(RID p_lightmap) override;
997 virtual void lightmap_free(RID p_rid) override;
998
999 virtual void lightmap_set_textures(RID p_lightmap, RID p_light, bool p_uses_spherical_haromics) override;
1000 virtual void lightmap_set_probe_bounds(RID p_lightmap, const AABB &p_bounds) override;
1001 virtual void lightmap_set_probe_interior(RID p_lightmap, bool p_interior) override;
1002 virtual void lightmap_set_probe_capture_data(RID p_lightmap, const PackedVector3Array &p_points, const PackedColorArray &p_point_sh, const PackedInt32Array &p_tetrahedra, const PackedInt32Array &p_bsp_tree) override;
1003 virtual void lightmap_set_baked_exposure_normalization(RID p_lightmap, float p_exposure) override;
1004 virtual PackedVector3Array lightmap_get_probe_capture_points(RID p_lightmap) const override;
1005 virtual PackedColorArray lightmap_get_probe_capture_sh(RID p_lightmap) const override;
1006 virtual PackedInt32Array lightmap_get_probe_capture_tetrahedra(RID p_lightmap) const override;
1007 virtual PackedInt32Array lightmap_get_probe_capture_bsp_tree(RID p_lightmap) const override;
1008 virtual AABB lightmap_get_aabb(RID p_lightmap) const override;
1009 virtual bool lightmap_is_interior(RID p_lightmap) const override;
1010 virtual void lightmap_tap_sh_light(RID p_lightmap, const Vector3 &p_point, Color *r_sh) override;
1011 virtual void lightmap_set_probe_capture_update_speed(float p_speed) override;
1012
1013 Dependency *lightmap_get_dependency(RID p_lightmap) const;
1014
1015 virtual void lightmap_set_shadowmask_textures(RID p_lightmap, RID p_shadow) override;
1016 virtual RS::ShadowmaskMode lightmap_get_shadowmask_mode(RID p_lightmap) override;
1017 virtual void lightmap_set_shadowmask_mode(RID p_lightmap, RS::ShadowmaskMode p_mode) override;
1018
1019 virtual float lightmap_get_probe_capture_update_speed() const override {
1020 return lightmap_probe_capture_update_speed;
1021 }
1022 _FORCE_INLINE_ RID lightmap_get_texture(RID p_lightmap) const {
1023 const Lightmap *lm = lightmap_owner.get_or_null(p_lightmap);
1024 ERR_FAIL_NULL_V(lm, RID());
1025 return lm->light_texture;
1026 }
1027 _FORCE_INLINE_ float lightmap_get_baked_exposure_normalization(RID p_lightmap) const {
1028 const Lightmap *lm = lightmap_owner.get_or_null(p_lightmap);
1029 ERR_FAIL_NULL_V(lm, 1.0);
1030 return lm->baked_exposure;
1031 }
1032 _FORCE_INLINE_ int32_t lightmap_get_array_index(RID p_lightmap) const {
1033 ERR_FAIL_COND_V(!using_lightmap_array, -1); //only for arrays
1034 const Lightmap *lm = lightmap_owner.get_or_null(p_lightmap);
1035 return lm->array_index;
1036 }
1037 _FORCE_INLINE_ bool lightmap_uses_spherical_harmonics(RID p_lightmap) const {
1038 ERR_FAIL_COND_V(!using_lightmap_array, false); //only for arrays
1039 const Lightmap *lm = lightmap_owner.get_or_null(p_lightmap);
1040 return lm->uses_spherical_harmonics;
1041 }
1042 _FORCE_INLINE_ Vector2i lightmap_get_light_texture_size(RID p_lightmap) const {
1043 const Lightmap *lm = lightmap_owner.get_or_null(p_lightmap);
1044 return lm->light_texture_size;
1045 }
1046 _FORCE_INLINE_ uint64_t lightmap_array_get_version() const {
1047 ERR_FAIL_COND_V(!using_lightmap_array, 0); //only for arrays
1048 return lightmap_array_version;
1049 }
1050
1051 _FORCE_INLINE_ int lightmap_array_get_size() const {
1052 ERR_FAIL_COND_V(!using_lightmap_array, 0); //only for arrays
1053 return lightmap_textures.size();
1054 }
1055
1056 _FORCE_INLINE_ const Vector<RID> &lightmap_array_get_textures() const {
1057 ERR_FAIL_COND_V(!using_lightmap_array, lightmap_textures); //only for arrays
1058 return lightmap_textures;
1059 }
1060
1061 _FORCE_INLINE_ RID shadowmask_get_texture(RID p_lightmap) const {
1062 const Lightmap *lm = lightmap_owner.get_or_null(p_lightmap);
1063 ERR_FAIL_NULL_V(lm, RID());
1064 return lm->shadow_texture;
1065 }
1066
1067 /* LIGHTMAP INSTANCE */
1068
1069 bool owns_lightmap_instance(RID p_rid) { return lightmap_instance_owner.owns(p_rid); }
1070
1071 virtual RID lightmap_instance_create(RID p_lightmap) override;
1072 virtual void lightmap_instance_free(RID p_lightmap) override;
1073 virtual void lightmap_instance_set_transform(RID p_lightmap, const Transform3D &p_transform) override;
1074 _FORCE_INLINE_ bool lightmap_instance_is_valid(RID p_lightmap_instance) {
1075 return lightmap_instance_owner.get_or_null(p_lightmap_instance) != nullptr;
1076 }
1077
1078 _FORCE_INLINE_ RID lightmap_instance_get_lightmap(RID p_lightmap_instance) {
1079 LightmapInstance *li = lightmap_instance_owner.get_or_null(p_lightmap_instance);
1080 return li->lightmap;
1081 }
1082 _FORCE_INLINE_ Transform3D lightmap_instance_get_transform(RID p_lightmap_instance) {
1083 LightmapInstance *li = lightmap_instance_owner.get_or_null(p_lightmap_instance);
1084 return li->transform;
1085 }
1086
1087 /* SHADOW ATLAS API */
1088
1089 bool owns_shadow_atlas(RID p_rid) { return shadow_atlas_owner.owns(p_rid); }
1090
1091 virtual RID shadow_atlas_create() override;
1092 virtual void shadow_atlas_free(RID p_atlas) override;
1093
1094 virtual void shadow_atlas_set_size(RID p_atlas, int p_size, bool p_16_bits = true) override;
1095 virtual void shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p_quadrant, int p_subdivision) override;
1096 virtual bool shadow_atlas_update_light(RID p_atlas, RID p_light_instance, float p_coverage, uint64_t p_light_version) override;
1097 _FORCE_INLINE_ bool shadow_atlas_owns_light_instance(RID p_atlas, RID p_light_instance) {
1098 ShadowAtlas *atlas = shadow_atlas_owner.get_or_null(p_atlas);
1099 ERR_FAIL_NULL_V(atlas, false);
1100 return atlas->shadow_owners.has(p_light_instance);
1101 }
1102 _FORCE_INLINE_ uint32_t shadow_atlas_get_light_instance_key(RID p_atlas, RID p_light_instance) {
1103 ShadowAtlas *atlas = shadow_atlas_owner.get_or_null(p_atlas);
1104 ERR_FAIL_NULL_V(atlas, -1);
1105 return atlas->shadow_owners[p_light_instance];
1106 }
1107
1108 _FORCE_INLINE_ RID shadow_atlas_get_texture(RID p_atlas) {
1109 ShadowAtlas *atlas = shadow_atlas_owner.get_or_null(p_atlas);
1110 ERR_FAIL_NULL_V(atlas, RID());
1111 return atlas->depth;
1112 }
1113
1114 _FORCE_INLINE_ int shadow_atlas_get_size(RID p_atlas) {
1115 ShadowAtlas *atlas = shadow_atlas_owner.get_or_null(p_atlas);
1116 ERR_FAIL_NULL_V(atlas, 0);
1117 return atlas->size;
1118 }
1119
1120 _FORCE_INLINE_ int shadow_atlas_get_quadrant_shadow_size(RID p_atlas, uint32_t p_quadrant) {
1121 ShadowAtlas *atlas = shadow_atlas_owner.get_or_null(p_atlas);
1122 ERR_FAIL_NULL_V(atlas, 0);
1123 ERR_FAIL_UNSIGNED_INDEX_V(p_quadrant, 4, 0);
1124 return atlas->quadrants[p_quadrant].shadows.size();
1125 }
1126
1127 _FORCE_INLINE_ uint32_t shadow_atlas_get_quadrant_subdivision(RID p_atlas, uint32_t p_quadrant) {
1128 ShadowAtlas *atlas = shadow_atlas_owner.get_or_null(p_atlas);
1129 ERR_FAIL_NULL_V(atlas, 0);
1130 ERR_FAIL_UNSIGNED_INDEX_V(p_quadrant, 4, 0);
1131 return atlas->quadrants[p_quadrant].subdivision;
1132 }
1133
1134 _FORCE_INLINE_ RID shadow_atlas_get_fb(RID p_atlas) {
1135 ShadowAtlas *atlas = shadow_atlas_owner.get_or_null(p_atlas);
1136 ERR_FAIL_NULL_V(atlas, RID());
1137 return atlas->fb;
1138 }
1139
1140 virtual void shadow_atlas_update(RID p_atlas) override;
1141 static RD::DataFormat get_shadow_atlas_depth_format(bool p_16_bits);
1142 static uint32_t get_shadow_atlas_depth_usage_bits();
1143
1144 /* DIRECTIONAL SHADOW */
1145
1146 virtual void directional_shadow_atlas_set_size(int p_size, bool p_16_bits = true) override;
1147 virtual int get_directional_light_shadow_size(RID p_light_instance) override;
1148 virtual void set_directional_shadow_count(int p_count) override;
1149
1150 Rect2i get_directional_shadow_rect();
1151 void update_directional_shadow_atlas();
1152
1153 _FORCE_INLINE_ RID directional_shadow_get_texture() {
1154 return directional_shadow.depth;
1155 }
1156
1157 _FORCE_INLINE_ int directional_shadow_get_size() {
1158 return directional_shadow.size;
1159 }
1160
1161 _FORCE_INLINE_ RID direction_shadow_get_fb() {
1162 return directional_shadow.fb;
1163 }
1164
1165 _FORCE_INLINE_ void directional_shadow_increase_current_light() {
1166 directional_shadow.current_light++;
1167 }
1168
1169 /* SHADOW CUBEMAPS */
1170
1171 RID get_cubemap(int p_size);
1172 RID get_cubemap_fb(int p_size, int p_pass);
1173 static RD::DataFormat get_cubemap_depth_format();
1174 static uint32_t get_cubemap_depth_usage_bits();
1175
1176 /* PIPELINE HINTS */
1177
1178 bool get_shadow_cubemaps_used() const;
1179 bool get_shadow_dual_paraboloid_used() const;
1180 };
1181
1182 } // namespace RendererRD