@@ -59,7 +59,6 @@ enum RenderListType {
59
59
enum PassMode {
60
60
PASS_MODE_COLOR,
61
61
PASS_MODE_COLOR_TRANSPARENT,
62
- PASS_MODE_COLOR_ADDITIVE,
63
62
PASS_MODE_SHADOW,
64
63
PASS_MODE_DEPTH,
65
64
};
@@ -75,6 +74,8 @@ enum SceneUniformLocation {
75
74
SCENE_SPOTLIGHT_UNIFORM_LOCATION,
76
75
SCENE_DIRECTIONAL_LIGHT_UNIFORM_LOCATION,
77
76
SCENE_MULTIVIEW_UNIFORM_LOCATION,
77
+ SCENE_POSITIONAL_SHADOW_UNIFORM_LOCATION,
78
+ SCENE_DIRECTIONAL_SHADOW_UNIFORM_LOCATION,
78
79
};
79
80
80
81
enum SkyUniformLocation {
@@ -109,17 +110,24 @@ struct RenderDataGLES3 {
109
110
const PagedArray<RID> *reflection_probes = nullptr ;
110
111
RID environment;
111
112
RID camera_attributes;
113
+ RID shadow_atlas;
112
114
RID reflection_probe;
113
115
int reflection_probe_pass = 0 ;
114
116
115
117
float lod_distance_multiplier = 0.0 ;
116
118
float screen_mesh_lod_threshold = 0.0 ;
117
119
118
120
uint32_t directional_light_count = 0 ;
121
+ uint32_t directional_shadow_count = 0 ;
122
+
119
123
uint32_t spot_light_count = 0 ;
120
124
uint32_t omni_light_count = 0 ;
121
125
122
126
RenderingMethod::RenderInfo *render_info = nullptr ;
127
+
128
+ /* Shadow data */
129
+ const RendererSceneRender::RenderShadowData *render_shadows = nullptr ;
130
+ int render_shadow_count = 0 ;
123
131
};
124
132
125
133
class RasterizerCanvasGLES3 ;
@@ -173,11 +181,36 @@ class RasterizerSceneGLES3 : public RendererSceneRender {
173
181
float size;
174
182
175
183
uint32_t enabled; // For use by SkyShaders
176
- float pad[2 ];
184
+ float pad;
185
+ float shadow_opacity;
177
186
float specular;
178
187
};
179
188
static_assert (sizeof (DirectionalLightData) % 16 == 0 , " DirectionalLightData size must be a multiple of 16 bytes" );
180
189
190
+ struct ShadowData {
191
+ float shadow_matrix[16 ];
192
+
193
+ float light_position[3 ];
194
+ float shadow_normal_bias;
195
+
196
+ float pad[3 ];
197
+ float shadow_atlas_pixel_size;
198
+ };
199
+ static_assert (sizeof (ShadowData) % 16 == 0 , " ShadowData size must be a multiple of 16 bytes" );
200
+
201
+ struct DirectionalShadowData {
202
+ float direction[3 ];
203
+ float shadow_atlas_pixel_size;
204
+ float shadow_normal_bias[4 ];
205
+ float shadow_split_offsets[4 ];
206
+ float shadow_matrices[4 ][16 ];
207
+ float fade_from;
208
+ float fade_to;
209
+ uint32_t blend_splits; // Not exposed to the shader.
210
+ uint32_t pad;
211
+ };
212
+ static_assert (sizeof (DirectionalShadowData) % 16 == 0 , " DirectionalShadowData size must be a multiple of 16 bytes" );
213
+
181
214
class GeometryInstanceGLES3 ;
182
215
183
216
// Cached data for drawing surfaces
@@ -221,6 +254,8 @@ class RasterizerSceneGLES3 : public RendererSceneRender {
221
254
uint32_t surface_index = 0 ;
222
255
uint32_t lod_index = 0 ;
223
256
uint32_t index_count = 0 ;
257
+ int32_t light_pass_index = -1 ;
258
+ bool finished_base_pass = false ;
224
259
225
260
void *surface = nullptr ;
226
261
GLES3::SceneShaderData *shader = nullptr ;
@@ -245,14 +280,23 @@ class RasterizerSceneGLES3 : public RendererSceneRender {
245
280
bool using_projectors = false ;
246
281
bool using_softshadows = false ;
247
282
248
- uint32_t omni_light_count = 0 ;
249
- LocalVector<RID> omni_lights;
250
- uint32_t spot_light_count = 0 ;
251
- LocalVector<RID> spot_lights;
283
+ struct LightPass {
284
+ int32_t light_id = -1 ; // Position in the light uniform buffer.
285
+ int32_t shadow_id = -1 ; // Position in the shadow uniform buffer.
286
+ RID light_instance_rid;
287
+ bool is_omni = false ;
288
+ };
289
+
290
+ LocalVector<LightPass> light_passes;
291
+
292
+ uint32_t paired_omni_light_count = 0 ;
293
+ uint32_t paired_spot_light_count = 0 ;
294
+ LocalVector<RID> paired_omni_lights;
295
+ LocalVector<RID> paired_spot_lights;
252
296
LocalVector<uint32_t > omni_light_gl_cache;
253
297
LocalVector<uint32_t > spot_light_gl_cache;
254
298
255
- // used during setup
299
+ // Used during setup.
256
300
GeometryInstanceSurface *surface_caches = nullptr ;
257
301
SelfList<GeometryInstanceGLES3> dirty_list_element;
258
302
@@ -336,10 +380,11 @@ class RasterizerSceneGLES3 : public RendererSceneRender {
336
380
337
381
float fog_light_color[3 ];
338
382
float fog_sun_scatter;
383
+
384
+ float shadow_bias;
385
+ float pad;
339
386
uint32_t camera_visible_layers;
340
- uint32_t pad1;
341
- uint32_t pad2;
342
- uint32_t pad3;
387
+ bool pancake_shadows;
343
388
};
344
389
static_assert (sizeof (UBO) % 16 == 0 , " Scene UBO size must be a multiple of 16 bytes" );
345
390
@@ -378,16 +423,22 @@ class RasterizerSceneGLES3 : public RendererSceneRender {
378
423
379
424
LightData *omni_lights = nullptr ;
380
425
LightData *spot_lights = nullptr ;
426
+ ShadowData *positional_shadows = nullptr ;
381
427
382
428
InstanceSort<GLES3::LightInstance> *omni_light_sort;
383
429
InstanceSort<GLES3::LightInstance> *spot_light_sort;
384
430
GLuint omni_light_buffer = 0 ;
385
431
GLuint spot_light_buffer = 0 ;
432
+ GLuint positional_shadow_buffer = 0 ;
386
433
uint32_t omni_light_count = 0 ;
387
434
uint32_t spot_light_count = 0 ;
435
+ RS::ShadowQuality positional_shadow_quality = RS::ShadowQuality::SHADOW_QUALITY_SOFT_LOW;
388
436
389
437
DirectionalLightData *directional_lights = nullptr ;
390
438
GLuint directional_light_buffer = 0 ;
439
+ DirectionalShadowData *directional_shadows = nullptr ;
440
+ GLuint directional_shadow_buffer = 0 ;
441
+ RS::ShadowQuality directional_shadow_quality = RS::ShadowQuality::SHADOW_QUALITY_SOFT_LOW;
391
442
} scene_state;
392
443
393
444
struct RenderListParameters {
@@ -462,9 +513,11 @@ class RasterizerSceneGLES3 : public RendererSceneRender {
462
513
463
514
RenderList render_list[RENDER_LIST_MAX];
464
515
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);
516
+ 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, uint32_t &r_directional_shadow_count );
517
+ 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, float p_shadow_bias = 0.0 );
467
518
void _fill_render_list (RenderListType p_render_list, const RenderDataGLES3 *p_render_data, PassMode p_pass_mode, bool p_append = false );
519
+ void _render_shadows (const RenderDataGLES3 *p_render_data);
520
+ void _render_shadow_pass (RID p_light, RID p_shadow_atlas, int p_pass, const PagedArray<RenderGeometryInstance *> &p_instances, const Plane &p_camera_plane = Plane(), float p_lod_distance_multiplier = 0, float p_screen_mesh_lod_threshold = 0.0, RenderingMethod::RenderInfo *p_render_info = nullptr);
468
521
469
522
template <PassMode p_pass_mode>
470
523
_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 );
@@ -477,7 +530,7 @@ class RasterizerSceneGLES3 : public RendererSceneRender {
477
530
float screen_space_roughness_limiter_amount = 0.25 ;
478
531
float screen_space_roughness_limiter_limit = 0.18 ;
479
532
480
- void _render_buffers_debug_draw (Ref<RenderSceneBuffersGLES3> p_render_buffers, RID p_shadow_atlas, RID p_occlusion_buffer );
533
+ void _render_buffers_debug_draw (Ref<RenderSceneBuffersGLES3> p_render_buffers, RID p_shadow_atlas);
481
534
482
535
/* Camera Attributes */
483
536
0 commit comments