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 | #ifndef LIGHT_STORAGE_RD_H |
32 | #define LIGHT_STORAGE_RD_H |
33 | |
34 | #include "core/templates/local_vector.h" |
35 | #include "core/templates/paged_array.h" |
36 | #include "core/templates/rid_owner.h" |
37 | #include "core/templates/self_list.h" |
38 | #include "servers/rendering/renderer_rd/cluster_builder_rd.h" |
39 | #include "servers/rendering/renderer_rd/environment/sky.h" |
40 | #include "servers/rendering/renderer_rd/storage_rd/forward_id_storage.h" |
41 | #include "servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.h" |
42 | #include "servers/rendering/renderer_rd/storage_rd/texture_storage.h" |
43 | #include "servers/rendering/storage/light_storage.h" |
44 | #include "servers/rendering/storage/utilities.h" |
45 | |
46 | struct RenderDataRD; |
47 | |
48 | namespace RendererRD { |
49 | |
50 | class LightStorage : public RendererLightStorage { |
51 | public: |
52 | enum ShadowAtlastQuadrant { |
53 | QUADRANT_SHIFT = 27, |
54 | OMNI_LIGHT_FLAG = 1 << 26, |
55 | SHADOW_INDEX_MASK = OMNI_LIGHT_FLAG - 1, |
56 | SHADOW_INVALID = 0xFFFFFFFF |
57 | }; |
58 | |
59 | private: |
60 | static LightStorage *singleton; |
61 | uint32_t max_cluster_elements = 512; |
62 | |
63 | /* LIGHT */ |
64 | struct Light { |
65 | RS::LightType type; |
66 | float param[RS::LIGHT_PARAM_MAX]; |
67 | Color color = Color(1, 1, 1, 1); |
68 | RID projector; |
69 | bool shadow = false; |
70 | bool negative = false; |
71 | bool reverse_cull = false; |
72 | RS::LightBakeMode bake_mode = RS::LIGHT_BAKE_DYNAMIC; |
73 | uint32_t max_sdfgi_cascade = 2; |
74 | uint32_t cull_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 | int resolution = 256; |
224 | float intensity = 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 | float mesh_lod_threshold = 0.01; |
236 | float baked_exposure = 1.0; |
237 | |
238 | Dependency dependency; |
239 | }; |
240 | mutable RID_Owner<ReflectionProbe, true> reflection_probe_owner; |
241 | |
242 | /* REFLECTION ATLAS */ |
243 | |
244 | struct ReflectionAtlas { |
245 | int count = 0; |
246 | int size = 0; |
247 | |
248 | RID reflection; |
249 | RID depth_buffer; |
250 | RID depth_fb; |
251 | |
252 | struct Reflection { |
253 | RID owner; |
254 | RendererRD::SkyRD::ReflectionData data; |
255 | RID fbs[6]; |
256 | }; |
257 | |
258 | Vector<Reflection> reflections; |
259 | |
260 | Ref<RenderSceneBuffersRD> render_buffers; // Further render buffers used. |
261 | |
262 | ClusterBuilderRD *cluster_builder = nullptr; // only used if cluster builder is supported by the renderer. |
263 | }; |
264 | |
265 | mutable RID_Owner<ReflectionAtlas> reflection_atlas_owner; |
266 | |
267 | /* REFLECTION PROBE INSTANCE */ |
268 | |
269 | struct ReflectionProbeInstance { |
270 | RID probe; |
271 | int atlas_index = -1; |
272 | RID atlas; |
273 | |
274 | bool dirty = true; |
275 | bool rendering = false; |
276 | int processing_layer = 1; |
277 | int processing_side = 0; |
278 | |
279 | uint32_t render_step = 0; |
280 | uint64_t last_pass = 0; |
281 | uint32_t cull_mask = 0; |
282 | |
283 | RendererRD::ForwardID forward_id = -1; |
284 | |
285 | Transform3D transform; |
286 | }; |
287 | |
288 | mutable RID_Owner<ReflectionProbeInstance> reflection_probe_instance_owner; |
289 | |
290 | /* REFLECTION DATA */ |
291 | |
292 | enum { |
293 | REFLECTION_AMBIENT_DISABLED = 0, |
294 | REFLECTION_AMBIENT_ENVIRONMENT = 1, |
295 | REFLECTION_AMBIENT_COLOR = 2, |
296 | }; |
297 | |
298 | struct ReflectionData { |
299 | float box_extents[3]; |
300 | float index; |
301 | float box_offset[3]; |
302 | uint32_t mask; |
303 | float ambient[3]; // ambient color, |
304 | float intensity; |
305 | uint32_t exterior; |
306 | uint32_t box_project; |
307 | uint32_t ambient_mode; |
308 | float exposure_normalization; |
309 | float local_matrix[16]; // up to here for spot and omni, rest is for directional |
310 | }; |
311 | |
312 | struct ReflectionProbeInstanceSort { |
313 | float depth; |
314 | ReflectionProbeInstance *probe_instance; |
315 | bool operator<(const ReflectionProbeInstanceSort &p_sort) const { |
316 | return depth < p_sort.depth; |
317 | } |
318 | }; |
319 | |
320 | uint32_t max_reflections; |
321 | uint32_t reflection_count = 0; |
322 | // uint32_t max_reflection_probes_per_instance = 0; // seems unused |
323 | ReflectionData *reflections = nullptr; |
324 | ReflectionProbeInstanceSort *reflection_sort = nullptr; |
325 | RID reflection_buffer; |
326 | |
327 | /* LIGHTMAP */ |
328 | |
329 | struct Lightmap { |
330 | RID light_texture; |
331 | bool uses_spherical_harmonics = false; |
332 | bool interior = false; |
333 | AABB bounds = AABB(Vector3(), Vector3(1, 1, 1)); |
334 | float baked_exposure = 1.0; |
335 | int32_t array_index = -1; //unassigned |
336 | PackedVector3Array points; |
337 | PackedColorArray point_sh; |
338 | PackedInt32Array tetrahedra; |
339 | PackedInt32Array bsp_tree; |
340 | |
341 | struct BSP { |
342 | static const int32_t EMPTY_LEAF = INT32_MIN; |
343 | float plane[4]; |
344 | int32_t over = EMPTY_LEAF, under = EMPTY_LEAF; |
345 | }; |
346 | |
347 | Dependency dependency; |
348 | }; |
349 | |
350 | bool using_lightmap_array; |
351 | Vector<RID> lightmap_textures; |
352 | uint64_t lightmap_array_version = 0; |
353 | float lightmap_probe_capture_update_speed = 4; |
354 | |
355 | mutable RID_Owner<Lightmap, true> lightmap_owner; |
356 | |
357 | /* LIGHTMAP INSTANCE */ |
358 | |
359 | struct LightmapInstance { |
360 | RID lightmap; |
361 | Transform3D transform; |
362 | }; |
363 | |
364 | mutable RID_Owner<LightmapInstance> lightmap_instance_owner; |
365 | |
366 | /* SHADOW ATLAS */ |
367 | |
368 | uint64_t shadow_atlas_realloc_tolerance_msec = 500; |
369 | |
370 | struct ShadowShrinkStage { |
371 | RID texture; |
372 | RID filter_texture; |
373 | uint32_t size = 0; |
374 | }; |
375 | |
376 | struct ShadowAtlas { |
377 | struct Quadrant { |
378 | uint32_t subdivision = 0; |
379 | |
380 | struct Shadow { |
381 | RID owner; |
382 | uint64_t version = 0; |
383 | uint64_t fog_version = 0; // used for fog |
384 | uint64_t alloc_tick = 0; |
385 | |
386 | Shadow() {} |
387 | }; |
388 | |
389 | Vector<Shadow> shadows; |
390 | |
391 | Quadrant() {} |
392 | } quadrants[4]; |
393 | |
394 | int size_order[4] = { 0, 1, 2, 3 }; |
395 | uint32_t smallest_subdiv = 0; |
396 | |
397 | int size = 0; |
398 | bool use_16_bits = true; |
399 | |
400 | RID depth; |
401 | RID fb; //for copying |
402 | |
403 | HashMap<RID, uint32_t> shadow_owners; |
404 | }; |
405 | |
406 | RID_Owner<ShadowAtlas> shadow_atlas_owner; |
407 | |
408 | void _update_shadow_atlas(ShadowAtlas *shadow_atlas); |
409 | |
410 | 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); |
411 | 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); |
412 | 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); |
413 | |
414 | /* DIRECTIONAL SHADOW */ |
415 | |
416 | struct DirectionalShadow { |
417 | RID depth; |
418 | RID fb; //when renderign direct |
419 | |
420 | int light_count = 0; |
421 | int size = 0; |
422 | bool use_16_bits = true; |
423 | int current_light = 0; |
424 | } directional_shadow; |
425 | |
426 | /* SHADOW CUBEMAPS */ |
427 | |
428 | struct ShadowCubemap { |
429 | RID cubemap; |
430 | RID side_fb[6]; |
431 | }; |
432 | |
433 | HashMap<int, ShadowCubemap> shadow_cubemaps; |
434 | ShadowCubemap *_get_shadow_cubemap(int p_size); |
435 | |
436 | public: |
437 | static LightStorage *get_singleton(); |
438 | |
439 | LightStorage(); |
440 | virtual ~LightStorage(); |
441 | |
442 | bool free(RID p_rid); |
443 | |
444 | /* Settings */ |
445 | void set_max_cluster_elements(const uint32_t p_max_cluster_elements) { |
446 | max_cluster_elements = p_max_cluster_elements; |
447 | set_max_reflection_probes(p_max_cluster_elements); |
448 | set_max_lights(p_max_cluster_elements); |
449 | } |
450 | uint32_t get_max_cluster_elements() const { return max_cluster_elements; } |
451 | |
452 | /* LIGHT */ |
453 | |
454 | bool owns_light(RID p_rid) { return light_owner.owns(p_rid); } |
455 | |
456 | void _light_initialize(RID p_rid, RS::LightType p_type); |
457 | |
458 | virtual RID directional_light_allocate() override; |
459 | virtual void directional_light_initialize(RID p_light) override; |
460 | |
461 | virtual RID omni_light_allocate() override; |
462 | virtual void omni_light_initialize(RID p_light) override; |
463 | |
464 | virtual RID spot_light_allocate() override; |
465 | virtual void spot_light_initialize(RID p_light) override; |
466 | |
467 | virtual void light_free(RID p_rid) override; |
468 | |
469 | virtual void light_set_color(RID p_light, const Color &p_color) override; |
470 | virtual void light_set_param(RID p_light, RS::LightParam p_param, float p_value) override; |
471 | virtual void light_set_shadow(RID p_light, bool p_enabled) override; |
472 | virtual void light_set_projector(RID p_light, RID p_texture) override; |
473 | virtual void light_set_negative(RID p_light, bool p_enable) override; |
474 | virtual void light_set_cull_mask(RID p_light, uint32_t p_mask) override; |
475 | virtual void light_set_distance_fade(RID p_light, bool p_enabled, float p_begin, float p_shadow, float p_length) override; |
476 | virtual void light_set_reverse_cull_face_mode(RID p_light, bool p_enabled) override; |
477 | virtual void light_set_bake_mode(RID p_light, RS::LightBakeMode p_bake_mode) override; |
478 | virtual void light_set_max_sdfgi_cascade(RID p_light, uint32_t p_cascade) override; |
479 | |
480 | virtual void light_omni_set_shadow_mode(RID p_light, RS::LightOmniShadowMode p_mode) override; |
481 | |
482 | virtual void light_directional_set_shadow_mode(RID p_light, RS::LightDirectionalShadowMode p_mode) override; |
483 | virtual void light_directional_set_blend_splits(RID p_light, bool p_enable) override; |
484 | virtual bool light_directional_get_blend_splits(RID p_light) const override; |
485 | virtual void light_directional_set_sky_mode(RID p_light, RS::LightDirectionalSkyMode p_mode) override; |
486 | virtual RS::LightDirectionalSkyMode light_directional_get_sky_mode(RID p_light) const override; |
487 | |
488 | virtual RS::LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light) override; |
489 | virtual RS::LightOmniShadowMode light_omni_get_shadow_mode(RID p_light) override; |
490 | |
491 | virtual RS::LightType light_get_type(RID p_light) const override { |
492 | const Light *light = light_owner.get_or_null(p_light); |
493 | ERR_FAIL_COND_V(!light, RS::LIGHT_DIRECTIONAL); |
494 | |
495 | return light->type; |
496 | } |
497 | virtual AABB light_get_aabb(RID p_light) const override; |
498 | |
499 | virtual float light_get_param(RID p_light, RS::LightParam p_param) override { |
500 | const Light *light = light_owner.get_or_null(p_light); |
501 | ERR_FAIL_COND_V(!light, 0); |
502 | |
503 | return light->param[p_param]; |
504 | } |
505 | |
506 | _FORCE_INLINE_ RID light_get_projector(RID p_light) { |
507 | const Light *light = light_owner.get_or_null(p_light); |
508 | ERR_FAIL_COND_V(!light, RID()); |
509 | |
510 | return light->projector; |
511 | } |
512 | |
513 | virtual Color light_get_color(RID p_light) override { |
514 | const Light *light = light_owner.get_or_null(p_light); |
515 | ERR_FAIL_COND_V(!light, Color()); |
516 | |
517 | return light->color; |
518 | } |
519 | |
520 | _FORCE_INLINE_ bool light_is_distance_fade_enabled(RID p_light) { |
521 | const Light *light = light_owner.get_or_null(p_light); |
522 | return light->distance_fade; |
523 | } |
524 | |
525 | _FORCE_INLINE_ float light_get_distance_fade_begin(RID p_light) { |
526 | const Light *light = light_owner.get_or_null(p_light); |
527 | return light->distance_fade_begin; |
528 | } |
529 | |
530 | _FORCE_INLINE_ float light_get_distance_fade_shadow(RID p_light) { |
531 | const Light *light = light_owner.get_or_null(p_light); |
532 | return light->distance_fade_shadow; |
533 | } |
534 | |
535 | _FORCE_INLINE_ float light_get_distance_fade_length(RID p_light) { |
536 | const Light *light = light_owner.get_or_null(p_light); |
537 | return light->distance_fade_length; |
538 | } |
539 | |
540 | virtual bool light_has_shadow(RID p_light) const override { |
541 | const Light *light = light_owner.get_or_null(p_light); |
542 | ERR_FAIL_COND_V(!light, RS::LIGHT_DIRECTIONAL); |
543 | |
544 | return light->shadow; |
545 | } |
546 | |
547 | virtual bool light_has_projector(RID p_light) const override { |
548 | const Light *light = light_owner.get_or_null(p_light); |
549 | ERR_FAIL_COND_V(!light, RS::LIGHT_DIRECTIONAL); |
550 | |
551 | return TextureStorage::get_singleton()->owns_texture(light->projector); |
552 | } |
553 | |
554 | _FORCE_INLINE_ bool light_is_negative(RID p_light) const { |
555 | const Light *light = light_owner.get_or_null(p_light); |
556 | ERR_FAIL_COND_V(!light, RS::LIGHT_DIRECTIONAL); |
557 | |
558 | return light->negative; |
559 | } |
560 | |
561 | _FORCE_INLINE_ float light_get_transmittance_bias(RID p_light) const { |
562 | const Light *light = light_owner.get_or_null(p_light); |
563 | ERR_FAIL_COND_V(!light, 0.0); |
564 | |
565 | return light->param[RS::LIGHT_PARAM_TRANSMITTANCE_BIAS]; |
566 | } |
567 | |
568 | virtual bool light_get_reverse_cull_face_mode(RID p_light) const override { |
569 | const Light *light = light_owner.get_or_null(p_light); |
570 | ERR_FAIL_COND_V(!light, false); |
571 | |
572 | return light->reverse_cull; |
573 | } |
574 | |
575 | virtual RS::LightBakeMode light_get_bake_mode(RID p_light) override; |
576 | virtual uint32_t light_get_max_sdfgi_cascade(RID p_light) override; |
577 | virtual uint64_t light_get_version(RID p_light) const override; |
578 | virtual uint32_t light_get_cull_mask(RID p_light) const override; |
579 | |
580 | Dependency *light_get_dependency(RID p_light) const; |
581 | |
582 | /* LIGHT INSTANCE API */ |
583 | |
584 | bool owns_light_instance(RID p_rid) { return light_instance_owner.owns(p_rid); }; |
585 | |
586 | virtual RID light_instance_create(RID p_light) override; |
587 | virtual void light_instance_free(RID p_light) override; |
588 | virtual void light_instance_set_transform(RID p_light_instance, const Transform3D &p_transform) override; |
589 | virtual void light_instance_set_aabb(RID p_light_instance, const AABB &p_aabb) override; |
590 | 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; |
591 | virtual void light_instance_mark_visible(RID p_light_instance) override; |
592 | |
593 | _FORCE_INLINE_ RID light_instance_get_base_light(RID p_light_instance) { |
594 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
595 | return li->light; |
596 | } |
597 | |
598 | _FORCE_INLINE_ Transform3D light_instance_get_base_transform(RID p_light_instance) { |
599 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
600 | return li->transform; |
601 | } |
602 | |
603 | _FORCE_INLINE_ AABB light_instance_get_base_aabb(RID p_light_instance) { |
604 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
605 | return li->aabb; |
606 | } |
607 | |
608 | _FORCE_INLINE_ void light_instance_set_cull_mask(RID p_light_instance, uint32_t p_cull_mask) { |
609 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
610 | li->cull_mask = p_cull_mask; |
611 | } |
612 | |
613 | _FORCE_INLINE_ uint32_t light_instance_get_cull_mask(RID p_light_instance) { |
614 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
615 | return li->cull_mask; |
616 | } |
617 | |
618 | _FORCE_INLINE_ Rect2 light_instance_get_shadow_atlas_rect(RID p_light_instance, RID p_shadow_atlas, Vector2i &r_omni_offset) { |
619 | ShadowAtlas *shadow_atlas = shadow_atlas_owner.get_or_null(p_shadow_atlas); |
620 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
621 | uint32_t key = shadow_atlas->shadow_owners[li->self]; |
622 | |
623 | uint32_t quadrant = (key >> QUADRANT_SHIFT) & 0x3; |
624 | uint32_t shadow = key & SHADOW_INDEX_MASK; |
625 | |
626 | ERR_FAIL_COND_V(shadow >= (uint32_t)shadow_atlas->quadrants[quadrant].shadows.size(), Rect2()); |
627 | |
628 | uint32_t atlas_size = shadow_atlas->size; |
629 | uint32_t quadrant_size = atlas_size >> 1; |
630 | |
631 | uint32_t x = (quadrant & 1) * quadrant_size; |
632 | uint32_t y = (quadrant >> 1) * quadrant_size; |
633 | |
634 | uint32_t shadow_size = (quadrant_size / shadow_atlas->quadrants[quadrant].subdivision); |
635 | x += (shadow % shadow_atlas->quadrants[quadrant].subdivision) * shadow_size; |
636 | y += (shadow / shadow_atlas->quadrants[quadrant].subdivision) * shadow_size; |
637 | |
638 | if (key & OMNI_LIGHT_FLAG) { |
639 | if (((shadow + 1) % shadow_atlas->quadrants[quadrant].subdivision) == 0) { |
640 | r_omni_offset.x = 1 - int(shadow_atlas->quadrants[quadrant].subdivision); |
641 | r_omni_offset.y = 1; |
642 | } else { |
643 | r_omni_offset.x = 1; |
644 | r_omni_offset.y = 0; |
645 | } |
646 | } |
647 | |
648 | uint32_t width = shadow_size; |
649 | uint32_t height = shadow_size; |
650 | |
651 | return Rect2(x / float(shadow_atlas->size), y / float(shadow_atlas->size), width / float(shadow_atlas->size), height / float(shadow_atlas->size)); |
652 | } |
653 | |
654 | _FORCE_INLINE_ float light_instance_get_shadow_texel_size(RID p_light_instance, RID p_shadow_atlas) { |
655 | #ifdef DEBUG_ENABLED |
656 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
657 | ERR_FAIL_COND_V(!li->shadow_atlases.has(p_shadow_atlas), 0); |
658 | #endif |
659 | ShadowAtlas *shadow_atlas = shadow_atlas_owner.get_or_null(p_shadow_atlas); |
660 | ERR_FAIL_COND_V(!shadow_atlas, 0); |
661 | #ifdef DEBUG_ENABLED |
662 | ERR_FAIL_COND_V(!shadow_atlas->shadow_owners.has(p_light_instance), 0); |
663 | #endif |
664 | uint32_t key = shadow_atlas->shadow_owners[p_light_instance]; |
665 | |
666 | uint32_t quadrant = (key >> QUADRANT_SHIFT) & 0x3; |
667 | |
668 | uint32_t quadrant_size = shadow_atlas->size >> 1; |
669 | |
670 | uint32_t shadow_size = (quadrant_size / shadow_atlas->quadrants[quadrant].subdivision); |
671 | |
672 | return float(1.0) / shadow_size; |
673 | } |
674 | |
675 | _FORCE_INLINE_ Projection light_instance_get_shadow_camera(RID p_light_instance, int p_index) { |
676 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
677 | return li->shadow_transform[p_index].camera; |
678 | } |
679 | |
680 | _FORCE_INLINE_ Transform3D |
681 | light_instance_get_shadow_transform(RID p_light_instance, int p_index) { |
682 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
683 | return li->shadow_transform[p_index].transform; |
684 | } |
685 | _FORCE_INLINE_ float light_instance_get_shadow_bias_scale(RID p_light_instance, int p_index) { |
686 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
687 | return li->shadow_transform[p_index].bias_scale; |
688 | } |
689 | _FORCE_INLINE_ float light_instance_get_shadow_range(RID p_light_instance, int p_index) { |
690 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
691 | return li->shadow_transform[p_index].farplane; |
692 | } |
693 | _FORCE_INLINE_ float light_instance_get_shadow_range_begin(RID p_light_instance, int p_index) { |
694 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
695 | return li->shadow_transform[p_index].range_begin; |
696 | } |
697 | |
698 | _FORCE_INLINE_ Vector2 light_instance_get_shadow_uv_scale(RID p_light_instance, int p_index) { |
699 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
700 | return li->shadow_transform[p_index].uv_scale; |
701 | } |
702 | |
703 | _FORCE_INLINE_ void light_instance_set_directional_shadow_atlas_rect(RID p_light_instance, int p_index, const Rect2 p_atlas_rect) { |
704 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
705 | li->shadow_transform[p_index].atlas_rect = p_atlas_rect; |
706 | } |
707 | |
708 | _FORCE_INLINE_ Rect2 light_instance_get_directional_shadow_atlas_rect(RID p_light_instance, int p_index) { |
709 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
710 | return li->shadow_transform[p_index].atlas_rect; |
711 | } |
712 | |
713 | _FORCE_INLINE_ float light_instance_get_directional_shadow_split(RID p_light_instance, int p_index) { |
714 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
715 | return li->shadow_transform[p_index].split; |
716 | } |
717 | |
718 | _FORCE_INLINE_ float light_instance_get_directional_shadow_texel_size(RID p_light_instance, int p_index) { |
719 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
720 | return li->shadow_transform[p_index].shadow_texel_size; |
721 | } |
722 | |
723 | _FORCE_INLINE_ void light_instance_set_render_pass(RID p_light_instance, uint64_t p_pass) { |
724 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
725 | li->last_pass = p_pass; |
726 | } |
727 | |
728 | _FORCE_INLINE_ uint64_t light_instance_get_render_pass(RID p_light_instance) { |
729 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
730 | return li->last_pass; |
731 | } |
732 | |
733 | _FORCE_INLINE_ void light_instance_set_shadow_pass(RID p_light_instance, uint64_t p_pass) { |
734 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
735 | li->last_scene_shadow_pass = p_pass; |
736 | } |
737 | |
738 | _FORCE_INLINE_ uint64_t light_instance_get_shadow_pass(RID p_light_instance) { |
739 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
740 | return li->last_scene_shadow_pass; |
741 | } |
742 | |
743 | _FORCE_INLINE_ ForwardID light_instance_get_forward_id(RID p_light_instance) { |
744 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
745 | return li->forward_id; |
746 | } |
747 | |
748 | _FORCE_INLINE_ RS::LightType light_instance_get_type(RID p_light_instance) { |
749 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
750 | return li->light_type; |
751 | } |
752 | |
753 | _FORCE_INLINE_ void light_instance_set_directional_rect(RID p_light_instance, const Rect2 &p_directional_rect) { |
754 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
755 | li->directional_rect = p_directional_rect; |
756 | } |
757 | |
758 | _FORCE_INLINE_ Rect2 light_instance_get_directional_rect(RID p_light_instance) { |
759 | LightInstance *li = light_instance_owner.get_or_null(p_light_instance); |
760 | return li->directional_rect; |
761 | } |
762 | |
763 | /* LIGHT DATA */ |
764 | |
765 | void free_light_data(); |
766 | void set_max_lights(const uint32_t p_max_lights); |
767 | RID get_omni_light_buffer() { return omni_light_buffer; } |
768 | RID get_spot_light_buffer() { return spot_light_buffer; } |
769 | RID get_directional_light_buffer() { return directional_light_buffer; } |
770 | uint32_t get_max_directional_lights() { return max_directional_lights; } |
771 | bool has_directional_shadows(const uint32_t p_directional_light_count) { |
772 | for (uint32_t i = 0; i < p_directional_light_count; i++) { |
773 | if (directional_lights[i].shadow_opacity > 0.001) { |
774 | return true; |
775 | } |
776 | } |
777 | return false; |
778 | } |
779 | 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); |
780 | |
781 | /* REFLECTION PROBE */ |
782 | |
783 | bool owns_reflection_probe(RID p_rid) { return reflection_probe_owner.owns(p_rid); }; |
784 | |
785 | virtual RID reflection_probe_allocate() override; |
786 | virtual void reflection_probe_initialize(RID p_reflection_probe) override; |
787 | virtual void reflection_probe_free(RID p_rid) override; |
788 | |
789 | virtual void reflection_probe_set_update_mode(RID p_probe, RS::ReflectionProbeUpdateMode p_mode) override; |
790 | virtual void reflection_probe_set_intensity(RID p_probe, float p_intensity) override; |
791 | virtual void reflection_probe_set_ambient_mode(RID p_probe, RS::ReflectionProbeAmbientMode p_mode) override; |
792 | virtual void reflection_probe_set_ambient_color(RID p_probe, const Color &p_color) override; |
793 | virtual void reflection_probe_set_ambient_energy(RID p_probe, float p_energy) override; |
794 | virtual void reflection_probe_set_max_distance(RID p_probe, float p_distance) override; |
795 | virtual void reflection_probe_set_size(RID p_probe, const Vector3 &p_size) override; |
796 | virtual void reflection_probe_set_origin_offset(RID p_probe, const Vector3 &p_offset) override; |
797 | virtual void reflection_probe_set_as_interior(RID p_probe, bool p_enable) override; |
798 | virtual void reflection_probe_set_enable_box_projection(RID p_probe, bool p_enable) override; |
799 | virtual void reflection_probe_set_enable_shadows(RID p_probe, bool p_enable) override; |
800 | virtual void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers) override; |
801 | virtual void reflection_probe_set_resolution(RID p_probe, int p_resolution) override; |
802 | virtual void reflection_probe_set_mesh_lod_threshold(RID p_probe, float p_ratio) override; |
803 | |
804 | void reflection_probe_set_baked_exposure(RID p_probe, float p_exposure); |
805 | |
806 | virtual AABB reflection_probe_get_aabb(RID p_probe) const override; |
807 | virtual RS::ReflectionProbeUpdateMode reflection_probe_get_update_mode(RID p_probe) const override; |
808 | virtual uint32_t reflection_probe_get_cull_mask(RID p_probe) const override; |
809 | virtual Vector3 reflection_probe_get_size(RID p_probe) const override; |
810 | virtual Vector3 reflection_probe_get_origin_offset(RID p_probe) const override; |
811 | virtual float reflection_probe_get_origin_max_distance(RID p_probe) const override; |
812 | virtual float reflection_probe_get_mesh_lod_threshold(RID p_probe) const override; |
813 | |
814 | int reflection_probe_get_resolution(RID p_probe) const; |
815 | float reflection_probe_get_baked_exposure(RID p_probe) const; |
816 | virtual bool reflection_probe_renders_shadows(RID p_probe) const override; |
817 | |
818 | float reflection_probe_get_intensity(RID p_probe) const; |
819 | bool reflection_probe_is_interior(RID p_probe) const; |
820 | bool reflection_probe_is_box_projection(RID p_probe) const; |
821 | RS::ReflectionProbeAmbientMode reflection_probe_get_ambient_mode(RID p_probe) const; |
822 | Color reflection_probe_get_ambient_color(RID p_probe) const; |
823 | float reflection_probe_get_ambient_color_energy(RID p_probe) const; |
824 | |
825 | Dependency *reflection_probe_get_dependency(RID p_probe) const; |
826 | |
827 | /* REFLECTION ATLAS */ |
828 | |
829 | bool owns_reflection_atlas(RID p_rid) { return reflection_atlas_owner.owns(p_rid); } |
830 | |
831 | virtual RID reflection_atlas_create() override; |
832 | virtual void reflection_atlas_free(RID p_ref_atlas) override; |
833 | virtual void reflection_atlas_set_size(RID p_ref_atlas, int p_reflection_size, int p_reflection_count) override; |
834 | virtual int reflection_atlas_get_size(RID p_ref_atlas) const override; |
835 | |
836 | _FORCE_INLINE_ RID reflection_atlas_get_texture(RID p_ref_atlas) { |
837 | ReflectionAtlas *atlas = reflection_atlas_owner.get_or_null(p_ref_atlas); |
838 | ERR_FAIL_COND_V(!atlas, RID()); |
839 | return atlas->reflection; |
840 | } |
841 | |
842 | /* REFLECTION PROBE INSTANCE */ |
843 | |
844 | bool owns_reflection_probe_instance(RID p_rid) { return reflection_probe_instance_owner.owns(p_rid); } |
845 | |
846 | virtual RID reflection_probe_instance_create(RID p_probe) override; |
847 | virtual void reflection_probe_instance_free(RID p_instance) override; |
848 | virtual void reflection_probe_instance_set_transform(RID p_instance, const Transform3D &p_transform) override; |
849 | virtual void reflection_probe_release_atlas_index(RID p_instance) override; |
850 | virtual bool reflection_probe_instance_needs_redraw(RID p_instance) override; |
851 | virtual bool reflection_probe_instance_has_reflection(RID p_instance) override; |
852 | virtual bool reflection_probe_instance_begin_render(RID p_instance, RID p_reflection_atlas) override; |
853 | virtual Ref<RenderSceneBuffers> reflection_probe_atlas_get_render_buffers(RID p_reflection_atlas) override; |
854 | virtual bool reflection_probe_instance_postprocess_step(RID p_instance) override; |
855 | |
856 | uint32_t reflection_probe_instance_get_resolution(RID p_instance); |
857 | RID reflection_probe_instance_get_framebuffer(RID p_instance, int p_index); |
858 | RID reflection_probe_instance_get_depth_framebuffer(RID p_instance, int p_index); |
859 | |
860 | _FORCE_INLINE_ RID reflection_probe_instance_get_probe(RID p_instance) { |
861 | ReflectionProbeInstance *rpi = reflection_probe_instance_owner.get_or_null(p_instance); |
862 | ERR_FAIL_COND_V(!rpi, RID()); |
863 | |
864 | return rpi->probe; |
865 | } |
866 | |
867 | _FORCE_INLINE_ RendererRD::ForwardID reflection_probe_instance_get_forward_id(RID p_instance) { |
868 | ReflectionProbeInstance *rpi = reflection_probe_instance_owner.get_or_null(p_instance); |
869 | ERR_FAIL_COND_V(!rpi, 0); |
870 | |
871 | return rpi->forward_id; |
872 | } |
873 | |
874 | _FORCE_INLINE_ void reflection_probe_instance_set_cull_mask(RID p_instance, uint32_t p_render_pass) { |
875 | ReflectionProbeInstance *rpi = reflection_probe_instance_owner.get_or_null(p_instance); |
876 | ERR_FAIL_COND(!rpi); |
877 | rpi->cull_mask = p_render_pass; |
878 | } |
879 | |
880 | _FORCE_INLINE_ void reflection_probe_instance_set_render_pass(RID p_instance, uint32_t p_render_pass) { |
881 | ReflectionProbeInstance *rpi = reflection_probe_instance_owner.get_or_null(p_instance); |
882 | ERR_FAIL_COND(!rpi); |
883 | rpi->last_pass = p_render_pass; |
884 | } |
885 | |
886 | _FORCE_INLINE_ uint32_t reflection_probe_instance_get_render_pass(RID p_instance) { |
887 | ReflectionProbeInstance *rpi = reflection_probe_instance_owner.get_or_null(p_instance); |
888 | ERR_FAIL_COND_V(!rpi, 0); |
889 | |
890 | return rpi->last_pass; |
891 | } |
892 | |
893 | _FORCE_INLINE_ Transform3D reflection_probe_instance_get_transform(RID p_instance) { |
894 | ReflectionProbeInstance *rpi = reflection_probe_instance_owner.get_or_null(p_instance); |
895 | ERR_FAIL_COND_V(!rpi, Transform3D()); |
896 | |
897 | return rpi->transform; |
898 | } |
899 | |
900 | _FORCE_INLINE_ int reflection_probe_instance_get_atlas_index(RID p_instance) { |
901 | ReflectionProbeInstance *rpi = reflection_probe_instance_owner.get_or_null(p_instance); |
902 | ERR_FAIL_COND_V(!rpi, -1); |
903 | |
904 | return rpi->atlas_index; |
905 | } |
906 | |
907 | ClusterBuilderRD *reflection_probe_instance_get_cluster_builder(RID p_instance, ClusterBuilderSharedDataRD *p_cluster_builder_shared); |
908 | |
909 | /* REFLECTION DATA */ |
910 | |
911 | void free_reflection_data(); |
912 | void set_max_reflection_probes(const uint32_t p_max_reflection_probes); |
913 | RID get_reflection_probe_buffer() { return reflection_buffer; } |
914 | void update_reflection_probe_buffer(RenderDataRD *p_render_data, const PagedArray<RID> &p_reflections, const Transform3D &p_camera_inverse_transform, RID p_environment); |
915 | |
916 | /* LIGHTMAP */ |
917 | |
918 | bool owns_lightmap(RID p_rid) { return lightmap_owner.owns(p_rid); }; |
919 | |
920 | virtual RID lightmap_allocate() override; |
921 | virtual void lightmap_initialize(RID p_lightmap) override; |
922 | virtual void lightmap_free(RID p_rid) override; |
923 | |
924 | virtual void lightmap_set_textures(RID p_lightmap, RID p_light, bool p_uses_spherical_haromics) override; |
925 | virtual void lightmap_set_probe_bounds(RID p_lightmap, const AABB &p_bounds) override; |
926 | virtual void lightmap_set_probe_interior(RID p_lightmap, bool p_interior) override; |
927 | 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; |
928 | virtual void lightmap_set_baked_exposure_normalization(RID p_lightmap, float p_exposure) override; |
929 | virtual PackedVector3Array lightmap_get_probe_capture_points(RID p_lightmap) const override; |
930 | virtual PackedColorArray lightmap_get_probe_capture_sh(RID p_lightmap) const override; |
931 | virtual PackedInt32Array lightmap_get_probe_capture_tetrahedra(RID p_lightmap) const override; |
932 | virtual PackedInt32Array lightmap_get_probe_capture_bsp_tree(RID p_lightmap) const override; |
933 | virtual AABB lightmap_get_aabb(RID p_lightmap) const override; |
934 | virtual bool lightmap_is_interior(RID p_lightmap) const override; |
935 | virtual void lightmap_tap_sh_light(RID p_lightmap, const Vector3 &p_point, Color *r_sh) override; |
936 | virtual void lightmap_set_probe_capture_update_speed(float p_speed) override; |
937 | |
938 | Dependency *lightmap_get_dependency(RID p_lightmap) const; |
939 | |
940 | virtual float lightmap_get_probe_capture_update_speed() const override { |
941 | return lightmap_probe_capture_update_speed; |
942 | } |
943 | _FORCE_INLINE_ RID lightmap_get_texture(RID p_lightmap) const { |
944 | const Lightmap *lm = lightmap_owner.get_or_null(p_lightmap); |
945 | ERR_FAIL_COND_V(!lm, RID()); |
946 | return lm->light_texture; |
947 | } |
948 | _FORCE_INLINE_ float lightmap_get_baked_exposure_normalization(RID p_lightmap) const { |
949 | const Lightmap *lm = lightmap_owner.get_or_null(p_lightmap); |
950 | ERR_FAIL_COND_V(!lm, 1.0); |
951 | return lm->baked_exposure; |
952 | } |
953 | _FORCE_INLINE_ int32_t lightmap_get_array_index(RID p_lightmap) const { |
954 | ERR_FAIL_COND_V(!using_lightmap_array, -1); //only for arrays |
955 | const Lightmap *lm = lightmap_owner.get_or_null(p_lightmap); |
956 | return lm->array_index; |
957 | } |
958 | _FORCE_INLINE_ bool lightmap_uses_spherical_harmonics(RID p_lightmap) const { |
959 | ERR_FAIL_COND_V(!using_lightmap_array, false); //only for arrays |
960 | const Lightmap *lm = lightmap_owner.get_or_null(p_lightmap); |
961 | return lm->uses_spherical_harmonics; |
962 | } |
963 | _FORCE_INLINE_ uint64_t lightmap_array_get_version() const { |
964 | ERR_FAIL_COND_V(!using_lightmap_array, 0); //only for arrays |
965 | return lightmap_array_version; |
966 | } |
967 | |
968 | _FORCE_INLINE_ int lightmap_array_get_size() const { |
969 | ERR_FAIL_COND_V(!using_lightmap_array, 0); //only for arrays |
970 | return lightmap_textures.size(); |
971 | } |
972 | |
973 | _FORCE_INLINE_ const Vector<RID> &lightmap_array_get_textures() const { |
974 | ERR_FAIL_COND_V(!using_lightmap_array, lightmap_textures); //only for arrays |
975 | return lightmap_textures; |
976 | } |
977 | |
978 | /* LIGHTMAP INSTANCE */ |
979 | |
980 | bool owns_lightmap_instance(RID p_rid) { return lightmap_instance_owner.owns(p_rid); }; |
981 | |
982 | virtual RID lightmap_instance_create(RID p_lightmap) override; |
983 | virtual void lightmap_instance_free(RID p_lightmap) override; |
984 | virtual void lightmap_instance_set_transform(RID p_lightmap, const Transform3D &p_transform) override; |
985 | _FORCE_INLINE_ bool lightmap_instance_is_valid(RID p_lightmap_instance) { |
986 | return lightmap_instance_owner.get_or_null(p_lightmap_instance) != nullptr; |
987 | } |
988 | |
989 | _FORCE_INLINE_ RID lightmap_instance_get_lightmap(RID p_lightmap_instance) { |
990 | LightmapInstance *li = lightmap_instance_owner.get_or_null(p_lightmap_instance); |
991 | return li->lightmap; |
992 | } |
993 | _FORCE_INLINE_ Transform3D lightmap_instance_get_transform(RID p_lightmap_instance) { |
994 | LightmapInstance *li = lightmap_instance_owner.get_or_null(p_lightmap_instance); |
995 | return li->transform; |
996 | } |
997 | |
998 | /* SHADOW ATLAS API */ |
999 | |
1000 | bool owns_shadow_atlas(RID p_rid) { return shadow_atlas_owner.owns(p_rid); }; |
1001 | |
1002 | virtual RID shadow_atlas_create() override; |
1003 | virtual void shadow_atlas_free(RID p_atlas) override; |
1004 | |
1005 | virtual void shadow_atlas_set_size(RID p_atlas, int p_size, bool p_16_bits = true) override; |
1006 | virtual void shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p_quadrant, int p_subdivision) override; |
1007 | virtual bool shadow_atlas_update_light(RID p_atlas, RID p_light_instance, float p_coverage, uint64_t p_light_version) override; |
1008 | _FORCE_INLINE_ bool shadow_atlas_owns_light_instance(RID p_atlas, RID p_light_intance) { |
1009 | ShadowAtlas *atlas = shadow_atlas_owner.get_or_null(p_atlas); |
1010 | ERR_FAIL_COND_V(!atlas, false); |
1011 | return atlas->shadow_owners.has(p_light_intance); |
1012 | } |
1013 | _FORCE_INLINE_ uint32_t shadow_atlas_get_light_instance_key(RID p_atlas, RID p_light_intance) { |
1014 | ShadowAtlas *atlas = shadow_atlas_owner.get_or_null(p_atlas); |
1015 | ERR_FAIL_COND_V(!atlas, -1); |
1016 | return atlas->shadow_owners[p_light_intance]; |
1017 | } |
1018 | |
1019 | _FORCE_INLINE_ RID shadow_atlas_get_texture(RID p_atlas) { |
1020 | ShadowAtlas *atlas = shadow_atlas_owner.get_or_null(p_atlas); |
1021 | ERR_FAIL_COND_V(!atlas, RID()); |
1022 | return atlas->depth; |
1023 | } |
1024 | |
1025 | _FORCE_INLINE_ int shadow_atlas_get_size(RID p_atlas) { |
1026 | ShadowAtlas *atlas = shadow_atlas_owner.get_or_null(p_atlas); |
1027 | ERR_FAIL_COND_V(!atlas, 0); |
1028 | return atlas->size; |
1029 | } |
1030 | |
1031 | _FORCE_INLINE_ int shadow_atlas_get_quadrant_shadow_size(RID p_atlas, uint32_t p_quadrant) { |
1032 | ShadowAtlas *atlas = shadow_atlas_owner.get_or_null(p_atlas); |
1033 | ERR_FAIL_COND_V(!atlas, 0); |
1034 | ERR_FAIL_UNSIGNED_INDEX_V(p_quadrant, 4, 0); |
1035 | return atlas->quadrants[p_quadrant].shadows.size(); |
1036 | } |
1037 | |
1038 | _FORCE_INLINE_ uint32_t shadow_atlas_get_quadrant_subdivision(RID p_atlas, uint32_t p_quadrant) { |
1039 | ShadowAtlas *atlas = shadow_atlas_owner.get_or_null(p_atlas); |
1040 | ERR_FAIL_COND_V(!atlas, 0); |
1041 | ERR_FAIL_UNSIGNED_INDEX_V(p_quadrant, 4, 0); |
1042 | return atlas->quadrants[p_quadrant].subdivision; |
1043 | } |
1044 | |
1045 | _FORCE_INLINE_ RID shadow_atlas_get_fb(RID p_atlas) { |
1046 | ShadowAtlas *atlas = shadow_atlas_owner.get_or_null(p_atlas); |
1047 | ERR_FAIL_COND_V(!atlas, RID()); |
1048 | return atlas->fb; |
1049 | } |
1050 | |
1051 | virtual void shadow_atlas_update(RID p_atlas) override; |
1052 | |
1053 | /* DIRECTIONAL SHADOW */ |
1054 | |
1055 | virtual void directional_shadow_atlas_set_size(int p_size, bool p_16_bits = true) override; |
1056 | virtual int get_directional_light_shadow_size(RID p_light_intance) override; |
1057 | virtual void set_directional_shadow_count(int p_count) override; |
1058 | |
1059 | Rect2i get_directional_shadow_rect(); |
1060 | void update_directional_shadow_atlas(); |
1061 | |
1062 | _FORCE_INLINE_ RID directional_shadow_get_texture() { |
1063 | return directional_shadow.depth; |
1064 | } |
1065 | |
1066 | _FORCE_INLINE_ int directional_shadow_get_size() { |
1067 | return directional_shadow.size; |
1068 | } |
1069 | |
1070 | _FORCE_INLINE_ RID direction_shadow_get_fb() { |
1071 | return directional_shadow.fb; |
1072 | } |
1073 | |
1074 | _FORCE_INLINE_ void directional_shadow_increase_current_light() { |
1075 | directional_shadow.current_light++; |
1076 | } |
1077 | |
1078 | /* SHADOW CUBEMAPS */ |
1079 | |
1080 | RID get_cubemap(int p_size); |
1081 | RID get_cubemap_fb(int p_size, int p_pass); |
1082 | }; |
1083 | |
1084 | } // namespace RendererRD |
1085 | |
1086 | #endif // LIGHT_STORAGE_RD_H |
1087 | |