1/**************************************************************************/
2/* rasterizer_scene_gles3.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 RASTERIZER_SCENE_GLES3_H
32#define RASTERIZER_SCENE_GLES3_H
33
34#ifdef GLES3_ENABLED
35
36#include "core/math/projection.h"
37#include "core/templates/paged_allocator.h"
38#include "core/templates/rid_owner.h"
39#include "core/templates/self_list.h"
40#include "drivers/gles3/shaders/cubemap_filter.glsl.gen.h"
41#include "drivers/gles3/shaders/sky.glsl.gen.h"
42#include "scene/resources/mesh.h"
43#include "servers/rendering/renderer_compositor.h"
44#include "servers/rendering/renderer_scene_render.h"
45#include "servers/rendering_server.h"
46#include "shader_gles3.h"
47#include "storage/light_storage.h"
48#include "storage/material_storage.h"
49#include "storage/render_scene_buffers_gles3.h"
50#include "storage/utilities.h"
51
52enum RenderListType {
53 RENDER_LIST_OPAQUE, //used for opaque objects
54 RENDER_LIST_ALPHA, //used for transparent objects
55 RENDER_LIST_SECONDARY, //used for shadows and other objects
56 RENDER_LIST_MAX
57};
58
59enum PassMode {
60 PASS_MODE_COLOR,
61 PASS_MODE_COLOR_TRANSPARENT,
62 PASS_MODE_COLOR_ADDITIVE,
63 PASS_MODE_SHADOW,
64 PASS_MODE_DEPTH,
65};
66
67// These should share as much as possible with SkyUniform Location
68enum SceneUniformLocation {
69 SCENE_TONEMAP_UNIFORM_LOCATION,
70 SCENE_GLOBALS_UNIFORM_LOCATION,
71 SCENE_DATA_UNIFORM_LOCATION,
72 SCENE_MATERIAL_UNIFORM_LOCATION,
73 SCENE_EMPTY, // Unused, put here to avoid conflicts with SKY_DIRECTIONAL_LIGHT_UNIFORM_LOCATION.
74 SCENE_OMNILIGHT_UNIFORM_LOCATION,
75 SCENE_SPOTLIGHT_UNIFORM_LOCATION,
76 SCENE_DIRECTIONAL_LIGHT_UNIFORM_LOCATION,
77 SCENE_MULTIVIEW_UNIFORM_LOCATION,
78};
79
80enum SkyUniformLocation {
81 SKY_TONEMAP_UNIFORM_LOCATION,
82 SKY_GLOBALS_UNIFORM_LOCATION,
83 SKY_EMPTY, // Unused, put here to avoid conflicts with SCENE_DATA_UNIFORM_LOCATION.
84 SKY_MATERIAL_UNIFORM_LOCATION,
85 SKY_DIRECTIONAL_LIGHT_UNIFORM_LOCATION,
86 SKY_MULTIVIEW_UNIFORM_LOCATION,
87};
88
89struct RenderDataGLES3 {
90 Ref<RenderSceneBuffersGLES3> render_buffers;
91 bool transparent_bg = false;
92
93 Transform3D cam_transform;
94 Transform3D inv_cam_transform;
95 Projection cam_projection;
96 bool cam_orthogonal = false;
97 uint32_t camera_visible_layers = 0xFFFFFFFF;
98
99 // For stereo rendering
100 uint32_t view_count = 1;
101 Vector3 view_eye_offset[RendererSceneRender::MAX_RENDER_VIEWS];
102 Projection view_projection[RendererSceneRender::MAX_RENDER_VIEWS];
103
104 float z_near = 0.0;
105 float z_far = 0.0;
106
107 const PagedArray<RenderGeometryInstance *> *instances = nullptr;
108 const PagedArray<RID> *lights = nullptr;
109 const PagedArray<RID> *reflection_probes = nullptr;
110 RID environment;
111 RID camera_attributes;
112 RID reflection_probe;
113 int reflection_probe_pass = 0;
114
115 float lod_distance_multiplier = 0.0;
116 float screen_mesh_lod_threshold = 0.0;
117
118 uint32_t directional_light_count = 0;
119 uint32_t spot_light_count = 0;
120 uint32_t omni_light_count = 0;
121
122 RenderingMethod::RenderInfo *render_info = nullptr;
123};
124
125class RasterizerCanvasGLES3;
126
127class RasterizerSceneGLES3 : public RendererSceneRender {
128private:
129 static RasterizerSceneGLES3 *singleton;
130 RS::ViewportDebugDraw debug_draw = RS::VIEWPORT_DEBUG_DRAW_DISABLED;
131 uint64_t scene_pass = 0;
132
133 template <class T>
134 struct InstanceSort {
135 float depth;
136 T *instance = nullptr;
137 bool operator<(const InstanceSort &p_sort) const {
138 return depth < p_sort.depth;
139 }
140 };
141
142 struct SceneGlobals {
143 RID shader_default_version;
144 RID default_material;
145 RID default_shader;
146 RID cubemap_filter_shader_version;
147 } scene_globals;
148
149 /* LIGHT INSTANCE */
150
151 struct LightData {
152 float position[3];
153 float inv_radius;
154
155 float direction[3]; // Only used by SpotLight
156 float size;
157
158 float color[3];
159 float attenuation;
160
161 float inv_spot_attenuation;
162 float cos_spot_angle;
163 float specular_amount;
164 float shadow_opacity;
165 };
166 static_assert(sizeof(LightData) % 16 == 0, "LightData size must be a multiple of 16 bytes");
167
168 struct DirectionalLightData {
169 float direction[3];
170 float energy;
171
172 float color[3];
173 float size;
174
175 uint32_t enabled; // For use by SkyShaders
176 float pad[2];
177 float specular;
178 };
179 static_assert(sizeof(DirectionalLightData) % 16 == 0, "DirectionalLightData size must be a multiple of 16 bytes");
180
181 class GeometryInstanceGLES3;
182
183 // Cached data for drawing surfaces
184 struct GeometryInstanceSurface {
185 enum {
186 FLAG_PASS_DEPTH = 1,
187 FLAG_PASS_OPAQUE = 2,
188 FLAG_PASS_ALPHA = 4,
189 FLAG_PASS_SHADOW = 8,
190 FLAG_USES_SHARED_SHADOW_MATERIAL = 128,
191 FLAG_USES_SCREEN_TEXTURE = 2048,
192 FLAG_USES_DEPTH_TEXTURE = 4096,
193 FLAG_USES_NORMAL_TEXTURE = 8192,
194 FLAG_USES_DOUBLE_SIDED_SHADOWS = 16384,
195 };
196
197 union {
198 struct {
199 uint64_t lod_index : 8;
200 uint64_t surface_index : 8;
201 uint64_t geometry_id : 32;
202 uint64_t material_id_low : 16;
203
204 uint64_t material_id_hi : 16;
205 uint64_t shader_id : 32;
206 uint64_t uses_softshadow : 1;
207 uint64_t uses_projector : 1;
208 uint64_t uses_forward_gi : 1;
209 uint64_t uses_lightmap : 1;
210 uint64_t depth_layer : 4;
211 uint64_t priority : 8;
212 };
213 struct {
214 uint64_t sort_key1;
215 uint64_t sort_key2;
216 };
217 } sort;
218
219 RS::PrimitiveType primitive = RS::PRIMITIVE_MAX;
220 uint32_t flags = 0;
221 uint32_t surface_index = 0;
222 uint32_t lod_index = 0;
223 uint32_t index_count = 0;
224
225 void *surface = nullptr;
226 GLES3::SceneShaderData *shader = nullptr;
227 GLES3::SceneMaterialData *material = nullptr;
228
229 void *surface_shadow = nullptr;
230 GLES3::SceneShaderData *shader_shadow = nullptr;
231 GLES3::SceneMaterialData *material_shadow = nullptr;
232
233 GeometryInstanceSurface *next = nullptr;
234 GeometryInstanceGLES3 *owner = nullptr;
235 };
236
237 class GeometryInstanceGLES3 : public RenderGeometryInstanceBase {
238 public:
239 //used during rendering
240 bool store_transform_cache = true;
241
242 int32_t instance_count = 0;
243
244 bool can_sdfgi = false;
245 bool using_projectors = false;
246 bool using_softshadows = false;
247
248 uint32_t omni_light_count = 0;
249 LocalVector<RID> omni_lights;
250 uint32_t spot_light_count = 0;
251 LocalVector<RID> spot_lights;
252 LocalVector<uint32_t> omni_light_gl_cache;
253 LocalVector<uint32_t> spot_light_gl_cache;
254
255 //used during setup
256 GeometryInstanceSurface *surface_caches = nullptr;
257 SelfList<GeometryInstanceGLES3> dirty_list_element;
258
259 GeometryInstanceGLES3() :
260 dirty_list_element(this) {}
261
262 virtual void _mark_dirty() override;
263 virtual void set_use_lightmap(RID p_lightmap_instance, const Rect2 &p_lightmap_uv_scale, int p_lightmap_slice_index) override;
264 virtual void set_lightmap_capture(const Color *p_sh9) override;
265
266 virtual void pair_light_instances(const RID *p_light_instances, uint32_t p_light_instance_count) override;
267 virtual void pair_reflection_probe_instances(const RID *p_reflection_probe_instances, uint32_t p_reflection_probe_instance_count) override {}
268 virtual void pair_decal_instances(const RID *p_decal_instances, uint32_t p_decal_instance_count) override {}
269 virtual void pair_voxel_gi_instances(const RID *p_voxel_gi_instances, uint32_t p_voxel_gi_instance_count) override {}
270
271 virtual void set_softshadow_projector_pairing(bool p_softshadow, bool p_projector) override {}
272 };
273
274 enum {
275 INSTANCE_DATA_FLAGS_NON_UNIFORM_SCALE = 1 << 4,
276 INSTANCE_DATA_FLAG_USE_GI_BUFFERS = 1 << 5,
277 INSTANCE_DATA_FLAG_USE_LIGHTMAP_CAPTURE = 1 << 7,
278 INSTANCE_DATA_FLAG_USE_LIGHTMAP = 1 << 8,
279 INSTANCE_DATA_FLAG_USE_SH_LIGHTMAP = 1 << 9,
280 INSTANCE_DATA_FLAG_USE_VOXEL_GI = 1 << 10,
281 INSTANCE_DATA_FLAG_PARTICLES = 1 << 11,
282 INSTANCE_DATA_FLAG_MULTIMESH = 1 << 12,
283 INSTANCE_DATA_FLAG_MULTIMESH_FORMAT_2D = 1 << 13,
284 INSTANCE_DATA_FLAG_MULTIMESH_HAS_COLOR = 1 << 14,
285 INSTANCE_DATA_FLAG_MULTIMESH_HAS_CUSTOM_DATA = 1 << 15,
286 };
287
288 static void _geometry_instance_dependency_changed(Dependency::DependencyChangedNotification p_notification, DependencyTracker *p_tracker);
289 static void _geometry_instance_dependency_deleted(const RID &p_dependency, DependencyTracker *p_tracker);
290
291 SelfList<GeometryInstanceGLES3>::List geometry_instance_dirty_list;
292
293 // Use PagedAllocator instead of RID to maximize performance
294 PagedAllocator<GeometryInstanceGLES3> geometry_instance_alloc;
295 PagedAllocator<GeometryInstanceSurface> geometry_instance_surface_alloc;
296
297 void _geometry_instance_add_surface_with_material(GeometryInstanceGLES3 *ginstance, uint32_t p_surface, GLES3::SceneMaterialData *p_material, uint32_t p_material_id, uint32_t p_shader_id, RID p_mesh);
298 void _geometry_instance_add_surface_with_material_chain(GeometryInstanceGLES3 *ginstance, uint32_t p_surface, GLES3::SceneMaterialData *p_material, RID p_mat_src, RID p_mesh);
299 void _geometry_instance_add_surface(GeometryInstanceGLES3 *ginstance, uint32_t p_surface, RID p_material, RID p_mesh);
300 void _geometry_instance_update(RenderGeometryInstance *p_geometry_instance);
301 void _update_dirty_geometry_instances();
302
303 struct SceneState {
304 struct UBO {
305 float projection_matrix[16];
306 float inv_projection_matrix[16];
307 float inv_view_matrix[16];
308 float view_matrix[16];
309
310 float viewport_size[2];
311 float screen_pixel_size[2];
312
313 float ambient_light_color_energy[4];
314
315 float ambient_color_sky_mix;
316 uint32_t material_uv2_mode;
317 float emissive_exposure_normalization;
318 uint32_t use_ambient_light = 0;
319
320 uint32_t use_ambient_cubemap = 0;
321 uint32_t use_reflection_cubemap = 0;
322 float fog_aerial_perspective;
323 float time;
324
325 float radiance_inverse_xform[12];
326
327 uint32_t directional_light_count;
328 float z_far;
329 float z_near;
330 float IBL_exposure_normalization;
331
332 uint32_t fog_enabled;
333 float fog_density;
334 float fog_height;
335 float fog_height_density;
336
337 float fog_light_color[3];
338 float fog_sun_scatter;
339 uint32_t camera_visible_layers;
340 uint32_t pad1;
341 uint32_t pad2;
342 uint32_t pad3;
343 };
344 static_assert(sizeof(UBO) % 16 == 0, "Scene UBO size must be a multiple of 16 bytes");
345
346 struct MultiviewUBO {
347 float projection_matrix_view[RendererSceneRender::MAX_RENDER_VIEWS][16];
348 float inv_projection_matrix_view[RendererSceneRender::MAX_RENDER_VIEWS][16];
349 float eye_offset[RendererSceneRender::MAX_RENDER_VIEWS][4];
350 };
351 static_assert(sizeof(MultiviewUBO) % 16 == 0, "Multiview UBO size must be a multiple of 16 bytes");
352
353 struct TonemapUBO {
354 float exposure = 1.0;
355 float white = 1.0;
356 int32_t tonemapper = 0;
357 int32_t pad = 0;
358 };
359 static_assert(sizeof(TonemapUBO) % 16 == 0, "Tonemap UBO size must be a multiple of 16 bytes");
360
361 UBO ubo;
362 GLuint ubo_buffer = 0;
363 MultiviewUBO multiview_ubo;
364 GLuint multiview_buffer = 0;
365 GLuint tonemap_buffer = 0;
366
367 bool used_depth_prepass = false;
368
369 GLES3::SceneShaderData::BlendMode current_blend_mode = GLES3::SceneShaderData::BLEND_MODE_MIX;
370 GLES3::SceneShaderData::DepthDraw current_depth_draw = GLES3::SceneShaderData::DEPTH_DRAW_OPAQUE;
371 GLES3::SceneShaderData::DepthTest current_depth_test = GLES3::SceneShaderData::DEPTH_TEST_DISABLED;
372 GLES3::SceneShaderData::Cull cull_mode = GLES3::SceneShaderData::CULL_BACK;
373
374 bool texscreen_copied = false;
375 bool used_screen_texture = false;
376 bool used_normal_texture = false;
377 bool used_depth_texture = false;
378
379 LightData *omni_lights = nullptr;
380 LightData *spot_lights = nullptr;
381
382 InstanceSort<GLES3::LightInstance> *omni_light_sort;
383 InstanceSort<GLES3::LightInstance> *spot_light_sort;
384 GLuint omni_light_buffer = 0;
385 GLuint spot_light_buffer = 0;
386 uint32_t omni_light_count = 0;
387 uint32_t spot_light_count = 0;
388
389 DirectionalLightData *directional_lights = nullptr;
390 GLuint directional_light_buffer = 0;
391 } scene_state;
392
393 struct RenderListParameters {
394 GeometryInstanceSurface **elements = nullptr;
395 int element_count = 0;
396 bool reverse_cull = false;
397 uint64_t spec_constant_base_flags = 0;
398 bool force_wireframe = false;
399
400 RenderListParameters(GeometryInstanceSurface **p_elements, int p_element_count, bool p_reverse_cull, uint64_t p_spec_constant_base_flags, bool p_force_wireframe = false) {
401 elements = p_elements;
402 element_count = p_element_count;
403 reverse_cull = p_reverse_cull;
404 spec_constant_base_flags = p_spec_constant_base_flags;
405 force_wireframe = p_force_wireframe;
406 }
407 };
408
409 struct RenderList {
410 LocalVector<GeometryInstanceSurface *> elements;
411
412 void clear() {
413 elements.clear();
414 }
415
416 //should eventually be replaced by radix
417
418 struct SortByKey {
419 _FORCE_INLINE_ bool operator()(const GeometryInstanceSurface *A, const GeometryInstanceSurface *B) const {
420 return (A->sort.sort_key2 == B->sort.sort_key2) ? (A->sort.sort_key1 < B->sort.sort_key1) : (A->sort.sort_key2 < B->sort.sort_key2);
421 }
422 };
423
424 void sort_by_key() {
425 SortArray<GeometryInstanceSurface *, SortByKey> sorter;
426 sorter.sort(elements.ptr(), elements.size());
427 }
428
429 void sort_by_key_range(uint32_t p_from, uint32_t p_size) {
430 SortArray<GeometryInstanceSurface *, SortByKey> sorter;
431 sorter.sort(elements.ptr() + p_from, p_size);
432 }
433
434 struct SortByDepth {
435 _FORCE_INLINE_ bool operator()(const GeometryInstanceSurface *A, const GeometryInstanceSurface *B) const {
436 return (A->owner->depth < B->owner->depth);
437 }
438 };
439
440 void sort_by_depth() { //used for shadows
441
442 SortArray<GeometryInstanceSurface *, SortByDepth> sorter;
443 sorter.sort(elements.ptr(), elements.size());
444 }
445
446 struct SortByReverseDepthAndPriority {
447 _FORCE_INLINE_ bool operator()(const GeometryInstanceSurface *A, const GeometryInstanceSurface *B) const {
448 return (A->sort.priority == B->sort.priority) ? (A->owner->depth > B->owner->depth) : (A->sort.priority < B->sort.priority);
449 }
450 };
451
452 void sort_by_reverse_depth_and_priority() { //used for alpha
453
454 SortArray<GeometryInstanceSurface *, SortByReverseDepthAndPriority> sorter;
455 sorter.sort(elements.ptr(), elements.size());
456 }
457
458 _FORCE_INLINE_ void add_element(GeometryInstanceSurface *p_element) {
459 elements.push_back(p_element);
460 }
461 };
462
463 RenderList render_list[RENDER_LIST_MAX];
464
465 void _setup_lights(const RenderDataGLES3 *p_render_data, bool p_using_shadows, uint32_t &r_directional_light_count, uint32_t &r_omni_light_count, uint32_t &r_spot_light_count);
466 void _setup_environment(const RenderDataGLES3 *p_render_data, bool p_no_fog, const Size2i &p_screen_size, bool p_flip_y, const Color &p_default_bg_color, bool p_pancake_shadows);
467 void _fill_render_list(RenderListType p_render_list, const RenderDataGLES3 *p_render_data, PassMode p_pass_mode, bool p_append = false);
468
469 template <PassMode p_pass_mode>
470 _FORCE_INLINE_ void _render_list_template(RenderListParameters *p_params, const RenderDataGLES3 *p_render_data, uint32_t p_from_element, uint32_t p_to_element, bool p_alpha_pass = false);
471
472protected:
473 double time;
474 double time_step = 0;
475
476 bool screen_space_roughness_limiter = false;
477 float screen_space_roughness_limiter_amount = 0.25;
478 float screen_space_roughness_limiter_limit = 0.18;
479
480 void _render_buffers_debug_draw(Ref<RenderSceneBuffersGLES3> p_render_buffers, RID p_shadow_atlas, RID p_occlusion_buffer);
481
482 /* Camera Attributes */
483
484 struct CameraAttributes {
485 float exposure_multiplier = 1.0;
486 float exposure_normalization = 1.0;
487 };
488
489 bool use_physical_light_units = false;
490 mutable RID_Owner<CameraAttributes, true> camera_attributes_owner;
491
492 /* Environment */
493
494 RS::EnvironmentSSAOQuality ssao_quality = RS::ENV_SSAO_QUALITY_MEDIUM;
495 bool ssao_half_size = false;
496 float ssao_adaptive_target = 0.5;
497 int ssao_blur_passes = 2;
498 float ssao_fadeout_from = 50.0;
499 float ssao_fadeout_to = 300.0;
500
501 bool glow_bicubic_upscale = false;
502 RS::EnvironmentSSRRoughnessQuality ssr_roughness_quality = RS::ENV_SSR_ROUGHNESS_QUALITY_LOW;
503
504 /* Sky */
505
506 struct SkyGlobals {
507 float fog_aerial_perspective = 0.0;
508 Color fog_light_color;
509 float fog_sun_scatter = 0.0;
510 bool fog_enabled = false;
511 float fog_density = 0.0;
512 float z_far = 0.0;
513 uint32_t directional_light_count = 0;
514
515 DirectionalLightData *directional_lights = nullptr;
516 DirectionalLightData *last_frame_directional_lights = nullptr;
517 uint32_t last_frame_directional_light_count = 0;
518 GLuint directional_light_buffer = 0;
519
520 RID shader_default_version;
521 RID default_material;
522 RID default_shader;
523 RID fog_material;
524 RID fog_shader;
525 GLuint screen_triangle = 0;
526 GLuint screen_triangle_array = 0;
527 GLuint radical_inverse_vdc_cache_tex = 0;
528 uint32_t max_directional_lights = 4;
529 uint32_t roughness_layers = 8;
530 uint32_t ggx_samples = 128;
531 } sky_globals;
532
533 struct Sky {
534 // Screen Buffers
535 GLuint half_res_pass = 0;
536 GLuint half_res_framebuffer = 0;
537 GLuint quarter_res_pass = 0;
538 GLuint quarter_res_framebuffer = 0;
539 Size2i screen_size = Size2i(0, 0);
540
541 // Radiance Cubemap
542 GLuint radiance = 0;
543 GLuint radiance_framebuffer = 0;
544 GLuint raw_radiance = 0;
545
546 RID material;
547 GLuint uniform_buffer;
548
549 int radiance_size = 256;
550 int mipmap_count = 1;
551
552 RS::SkyMode mode = RS::SKY_MODE_AUTOMATIC;
553
554 //ReflectionData reflection;
555 bool reflection_dirty = false;
556 bool dirty = false;
557 int processing_layer = 0;
558 Sky *dirty_list = nullptr;
559 float baked_exposure = 1.0;
560
561 //State to track when radiance cubemap needs updating
562 GLES3::SkyMaterialData *prev_material;
563 Vector3 prev_position = Vector3(0.0, 0.0, 0.0);
564 float prev_time = 0.0f;
565 };
566
567 Sky *dirty_sky_list = nullptr;
568 mutable RID_Owner<Sky, true> sky_owner;
569
570 void _setup_sky(const RenderDataGLES3 *p_render_data, const PagedArray<RID> &p_lights, const Projection &p_projection, const Transform3D &p_transform, const Size2i p_screen_size);
571 void _invalidate_sky(Sky *p_sky);
572 void _update_dirty_skys();
573 void _update_sky_radiance(RID p_env, const Projection &p_projection, const Transform3D &p_transform, float p_luminance_multiplier);
574 void _filter_sky_radiance(Sky *p_sky, int p_base_layer);
575 void _draw_sky(RID p_env, const Projection &p_projection, const Transform3D &p_transform, float p_luminance_multiplier, bool p_use_multiview, bool p_flip_y);
576 void _free_sky_data(Sky *p_sky);
577
578public:
579 static RasterizerSceneGLES3 *get_singleton() { return singleton; }
580
581 RasterizerCanvasGLES3 *canvas = nullptr;
582
583 RenderGeometryInstance *geometry_instance_create(RID p_base) override;
584 void geometry_instance_free(RenderGeometryInstance *p_geometry_instance) override;
585
586 uint32_t geometry_instance_get_pair_mask() override;
587
588 /* SDFGI UPDATE */
589
590 void sdfgi_update(const Ref<RenderSceneBuffers> &p_render_buffers, RID p_environment, const Vector3 &p_world_position) override {}
591 int sdfgi_get_pending_region_count(const Ref<RenderSceneBuffers> &p_render_buffers) const override {
592 return 0;
593 }
594 AABB sdfgi_get_pending_region_bounds(const Ref<RenderSceneBuffers> &p_render_buffers, int p_region) const override {
595 return AABB();
596 }
597 uint32_t sdfgi_get_pending_region_cascade(const Ref<RenderSceneBuffers> &p_render_buffers, int p_region) const override {
598 return 0;
599 }
600
601 /* SKY API */
602
603 RID sky_allocate() override;
604 void sky_initialize(RID p_rid) override;
605 void sky_set_radiance_size(RID p_sky, int p_radiance_size) override;
606 void sky_set_mode(RID p_sky, RS::SkyMode p_mode) override;
607 void sky_set_material(RID p_sky, RID p_material) override;
608 Ref<Image> sky_bake_panorama(RID p_sky, float p_energy, bool p_bake_irradiance, const Size2i &p_size) override;
609 float sky_get_baked_exposure(RID p_sky) const;
610
611 /* ENVIRONMENT API */
612
613 void environment_glow_set_use_bicubic_upscale(bool p_enable) override;
614
615 void environment_set_ssr_roughness_quality(RS::EnvironmentSSRRoughnessQuality p_quality) override;
616
617 void environment_set_ssao_quality(RS::EnvironmentSSAOQuality p_quality, bool p_half_size, float p_adaptive_target, int p_blur_passes, float p_fadeout_from, float p_fadeout_to) override;
618
619 void environment_set_ssil_quality(RS::EnvironmentSSILQuality p_quality, bool p_half_size, float p_adaptive_target, int p_blur_passes, float p_fadeout_from, float p_fadeout_to) override;
620
621 void environment_set_sdfgi_ray_count(RS::EnvironmentSDFGIRayCount p_ray_count) override;
622 void environment_set_sdfgi_frames_to_converge(RS::EnvironmentSDFGIFramesToConverge p_frames) override;
623 void environment_set_sdfgi_frames_to_update_light(RS::EnvironmentSDFGIFramesToUpdateLight p_update) override;
624
625 void environment_set_volumetric_fog_volume_size(int p_size, int p_depth) override;
626 void environment_set_volumetric_fog_filter_active(bool p_enable) override;
627
628 Ref<Image> environment_bake_panorama(RID p_env, bool p_bake_irradiance, const Size2i &p_size) override;
629
630 _FORCE_INLINE_ bool is_using_physical_light_units() {
631 return use_physical_light_units;
632 }
633
634 void positional_soft_shadow_filter_set_quality(RS::ShadowQuality p_quality) override;
635 void directional_soft_shadow_filter_set_quality(RS::ShadowQuality p_quality) override;
636
637 RID fog_volume_instance_create(RID p_fog_volume) override;
638 void fog_volume_instance_set_transform(RID p_fog_volume_instance, const Transform3D &p_transform) override;
639 void fog_volume_instance_set_active(RID p_fog_volume_instance, bool p_active) override;
640 RID fog_volume_instance_get_volume(RID p_fog_volume_instance) const override;
641 Vector3 fog_volume_instance_get_position(RID p_fog_volume_instance) const override;
642
643 RID voxel_gi_instance_create(RID p_voxel_gi) override;
644 void voxel_gi_instance_set_transform_to_data(RID p_probe, const Transform3D &p_xform) override;
645 bool voxel_gi_needs_update(RID p_probe) const override;
646 void voxel_gi_update(RID p_probe, bool p_update_light_instances, const Vector<RID> &p_light_instances, const PagedArray<RenderGeometryInstance *> &p_dynamic_objects) override;
647
648 void voxel_gi_set_quality(RS::VoxelGIQuality) override;
649
650 void render_scene(const Ref<RenderSceneBuffers> &p_render_buffers, const CameraData *p_camera_data, const CameraData *p_prev_camera_data, const PagedArray<RenderGeometryInstance *> &p_instances, const PagedArray<RID> &p_lights, const PagedArray<RID> &p_reflection_probes, const PagedArray<RID> &p_voxel_gi_instances, const PagedArray<RID> &p_decals, const PagedArray<RID> &p_lightmaps, const PagedArray<RID> &p_fog_volumes, RID p_environment, RID p_camera_attributes, RID p_shadow_atlas, RID p_occluder_debug_tex, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_mesh_lod_threshold, const RenderShadowData *p_render_shadows, int p_render_shadow_count, const RenderSDFGIData *p_render_sdfgi_regions, int p_render_sdfgi_region_count, const RenderSDFGIUpdateData *p_sdfgi_update_data = nullptr, RenderingMethod::RenderInfo *r_render_info = nullptr) override;
651 void render_material(const Transform3D &p_cam_transform, const Projection &p_cam_projection, bool p_cam_orthogonal, const PagedArray<RenderGeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override;
652 void render_particle_collider_heightfield(RID p_collider, const Transform3D &p_transform, const PagedArray<RenderGeometryInstance *> &p_instances) override;
653
654 void set_scene_pass(uint64_t p_pass) override {
655 scene_pass = p_pass;
656 }
657
658 _FORCE_INLINE_ uint64_t get_scene_pass() {
659 return scene_pass;
660 }
661
662 void set_time(double p_time, double p_step) override;
663 void set_debug_draw_mode(RS::ViewportDebugDraw p_debug_draw) override;
664 _FORCE_INLINE_ RS::ViewportDebugDraw get_debug_draw_mode() const {
665 return debug_draw;
666 }
667
668 Ref<RenderSceneBuffers> render_buffers_create() override;
669 void gi_set_use_half_resolution(bool p_enable) override;
670
671 void screen_space_roughness_limiter_set_active(bool p_enable, float p_amount, float p_curve) override;
672 bool screen_space_roughness_limiter_is_active() const override;
673
674 void sub_surface_scattering_set_quality(RS::SubSurfaceScatteringQuality p_quality) override;
675 void sub_surface_scattering_set_scale(float p_scale, float p_depth_scale) override;
676
677 TypedArray<Image> bake_render_uv2(RID p_base, const TypedArray<RID> &p_material_overrides, const Size2i &p_image_size) override;
678
679 bool free(RID p_rid) override;
680 void update() override;
681 void sdfgi_set_debug_probe_select(const Vector3 &p_position, const Vector3 &p_dir) override;
682
683 void decals_set_filter(RS::DecalFilter p_filter) override;
684 void light_projectors_set_filter(RS::LightProjectorFilter p_filter) override;
685
686 RasterizerSceneGLES3();
687 ~RasterizerSceneGLES3();
688};
689
690#endif // GLES3_ENABLED
691
692#endif // RASTERIZER_SCENE_GLES3_H
693