| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/templates/paged_allocator.h" |
| 34 |
#include "servers/rendering/multi_uma_buffer.h" |
| 35 |
#include "servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h" |
| 36 |
#include "servers/rendering/renderer_rd/renderer_scene_render_rd.h" |
| 37 |
|
| 38 |
#define RB_SCOPE_MOBILE SNAME("mobile") |
| 39 |
|
| 40 |
namespace RendererSceneRenderImplementation { |
| 41 |
|
| 42 |
class RenderForwardMobile : public RendererSceneRenderRD { |
| 43 |
friend SceneShaderForwardMobile; |
| 44 |
|
| 45 |
protected: |
| 46 |
struct GeometryInstanceSurfaceDataCache; |
| 47 |
|
| 48 |
private: |
| 49 |
static RenderForwardMobile *singleton; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
enum { |
| 54 |
SCENE_UNIFORM_SET = 0, |
| 55 |
RENDER_PASS_UNIFORM_SET = 1, |
| 56 |
TRANSFORMS_UNIFORM_SET = 2, |
| 57 |
MATERIAL_UNIFORM_SET = 3, |
| 58 |
}; |
| 59 |
|
| 60 |
enum { |
| 61 |
MAX_LIGHTMAPS = 8, |
| 62 |
MAX_RDL_CULL = 8, |
| 63 |
INSTANCE_DATA_BUFFER_MIN_SIZE = 4096 |
| 64 |
}; |
| 65 |
|
| 66 |
enum RenderListType { |
| 67 |
RENDER_LIST_OPAQUE, |
| 68 |
RENDER_LIST_ALPHA, |
| 69 |
RENDER_LIST_SECONDARY, |
| 70 |
RENDER_LIST_MAX |
| 71 |
}; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
SceneShaderForwardMobile scene_shader; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
class RenderBufferDataForwardMobile : public RenderBufferCustomDataRD { |
| 80 |
GDCLASS(RenderBufferDataForwardMobile, RenderBufferCustomDataRD); |
| 81 |
|
| 82 |
public: |
| 83 |
enum FramebufferConfigType { |
| 84 |
FB_CONFIG_RENDER_PASS, |
| 85 |
FB_CONFIG_RENDER_AND_POST_PASS, |
| 86 |
FB_CONFIG_MAX |
| 87 |
}; |
| 88 |
|
| 89 |
RID get_color_fbs(FramebufferConfigType p_config_type, bool p_resolve_depth = false); |
| 90 |
virtual void free_data() override; |
| 91 |
virtual void configure(RenderSceneBuffersRD *p_render_buffers) override; |
| 92 |
|
| 93 |
RID get_motion_vectors_fb(); |
| 94 |
|
| 95 |
private: |
| 96 |
RenderSceneBuffersRD *render_buffers = nullptr; |
| 97 |
}; |
| 98 |
|
| 99 |
virtual void setup_render_buffer_data(Ref<RenderSceneBuffersRD> p_render_buffers) override; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
enum PassMode { |
| 104 |
PASS_MODE_COLOR, |
| 105 |
|
| 106 |
PASS_MODE_COLOR_TRANSPARENT, |
| 107 |
PASS_MODE_SHADOW, |
| 108 |
PASS_MODE_SHADOW_DP, |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
PASS_MODE_DEPTH_MATERIAL, |
| 113 |
|
| 114 |
PASS_MODE_MOTION_VECTORS, |
| 115 |
}; |
| 116 |
|
| 117 |
struct RenderElementInfo; |
| 118 |
|
| 119 |
struct RenderListParameters { |
| 120 |
GeometryInstanceSurfaceDataCache **elements = nullptr; |
| 121 |
RenderElementInfo *element_info = nullptr; |
| 122 |
int element_count = 0; |
| 123 |
bool reverse_cull = false; |
| 124 |
PassMode pass_mode = PASS_MODE_COLOR; |
| 125 |
|
| 126 |
uint32_t view_count = 1; |
| 127 |
RID render_pass_uniform_set; |
| 128 |
bool force_wireframe = false; |
| 129 |
Vector2 uv_offset; |
| 130 |
SceneShaderForwardMobile::ShaderSpecialization base_specialization; |
| 131 |
float lod_distance_multiplier = 0.0; |
| 132 |
float screen_mesh_lod_threshold = 0.0; |
| 133 |
RD::FramebufferFormatID framebuffer_format = 0; |
| 134 |
uint32_t element_offset = 0; |
| 135 |
uint32_t subpass = 0; |
| 136 |
|
| 137 |
RenderListParameters(GeometryInstanceSurfaceDataCache **p_elements, RenderElementInfo *p_element_info, int p_element_count, bool p_reverse_cull, PassMode p_pass_mode, RID p_render_pass_uniform_set, SceneShaderForwardMobile::ShaderSpecialization p_base_specialization, bool p_force_wireframe = false, const Vector2 &p_uv_offset = Vector2(), float p_lod_distance_multiplier = 0.0, float p_screen_mesh_lod_threshold = 0.0, uint32_t p_view_count = 1, uint32_t p_element_offset = 0) { |
| 138 |
elements = p_elements; |
| 139 |
element_info = p_element_info; |
| 140 |
element_count = p_element_count; |
| 141 |
reverse_cull = p_reverse_cull; |
| 142 |
pass_mode = p_pass_mode; |
| 143 |
|
| 144 |
view_count = p_view_count; |
| 145 |
render_pass_uniform_set = p_render_pass_uniform_set; |
| 146 |
force_wireframe = p_force_wireframe; |
| 147 |
uv_offset = p_uv_offset; |
| 148 |
lod_distance_multiplier = p_lod_distance_multiplier; |
| 149 |
screen_mesh_lod_threshold = p_screen_mesh_lod_threshold; |
| 150 |
element_offset = p_element_offset; |
| 151 |
base_specialization = p_base_specialization; |
| 152 |
} |
| 153 |
}; |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
void _render_shadow_pass(RID p_light, RID p_shadow_atlas, int p_pass, const PagedArray<RenderGeometryInstance *> &p_instances, float p_lod_distance_multiplier = 0, float p_screen_mesh_lod_threshold = 0.0, bool p_open_pass = true, bool p_close_pass = true, bool p_clear_region = true, RenderingMethod::RenderInfo *p_render_info = nullptr, const Transform3D &p_main_cam_transform = Transform3D()); |
| 158 |
void _render_shadow_begin(); |
| 159 |
void _render_shadow_append(RID p_framebuffer, const PagedArray<RenderGeometryInstance *> &p_instances, const Projection &p_projection, const Transform3D &p_transform, float p_zfar, float p_bias, float p_normal_bias, bool p_use_dp, bool p_use_dp_flip, bool p_use_pancake, float p_lod_distance_multiplier = 0.0, float p_screen_mesh_lod_threshold = 0.0, const Rect2i &p_rect = Rect2i(), bool p_flip_y = false, bool p_clear_region = true, bool p_begin = true, bool p_end = true, RenderingMethod::RenderInfo *p_render_info = nullptr, const Transform3D &p_main_cam_transform = Transform3D()); |
| 160 |
void _render_shadow_process(); |
| 161 |
void _render_shadow_end(); |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
RID _setup_render_pass_uniform_set(RenderListType p_render_list, const RenderDataRD *p_render_data, RID p_radiance_texture, const RendererRD::MaterialStorage::Samplers &p_samplers, bool p_use_directional_shadow_atlas = false, uint32_t p_pass_offset = 0u); |
| 166 |
void _pre_opaque_render(RenderDataRD *p_render_data); |
| 167 |
|
| 168 |
uint64_t lightmap_texture_array_version = 0xFFFFFFFF; |
| 169 |
|
| 170 |
void _update_render_base_uniform_set(); |
| 171 |
|
| 172 |
void _fill_instance_data(RenderListType p_render_list, uint32_t p_offset = 0, int32_t p_max_elements = -1, bool p_update_buffer = true); |
| 173 |
void _fill_render_list(RenderListType p_render_list, const RenderDataRD *p_render_data, PassMode p_pass_mode, bool p_append = false); |
| 174 |
|
| 175 |
void _setup_environment(const RenderDataRD *p_render_data, bool p_no_fog, const Size2i &p_screen_size, const Size2 &p_viewport_size, const Color &p_default_bg_color, bool p_opaque_render_buffers = false, bool p_pancake_shadows = false); |
| 176 |
void _setup_lightmaps(const RenderDataRD *p_render_data, const PagedArray<RID> &p_lightmaps, const Transform3D &p_cam_transform); |
| 177 |
|
| 178 |
RID render_base_uniform_set; |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
struct LightmapData { |
| 183 |
float normal_xform[12]; |
| 184 |
float texture_size[2]; |
| 185 |
float exposure_normalization; |
| 186 |
uint32_t flags; |
| 187 |
}; |
| 188 |
|
| 189 |
struct LightmapCaptureData { |
| 190 |
float sh[9 * 4]; |
| 191 |
}; |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
struct SceneState { |
| 196 |
MultiUmaBuffer<1u> uniform_buffers = MultiUmaBuffer<1u>("SceneState::uniform_buffers"); |
| 197 |
|
| 198 |
struct PushConstantUbershader { |
| 199 |
SceneShaderForwardMobile::ShaderSpecialization specialization; |
| 200 |
SceneShaderForwardMobile::UbershaderConstants constants; |
| 201 |
}; |
| 202 |
|
| 203 |
struct PushConstant { |
| 204 |
uint32_t uv_offset; |
| 205 |
uint32_t base_index; |
| 206 |
uint32_t multimesh_motion_vectors_current_offset; |
| 207 |
uint32_t multimesh_motion_vectors_previous_offset; |
| 208 |
PushConstantUbershader ubershader; |
| 209 |
}; |
| 210 |
|
| 211 |
struct InstanceData { |
| 212 |
float transform[12]; |
| 213 |
float compressed_aabb_position[4]; |
| 214 |
float compressed_aabb_size[4]; |
| 215 |
float uv_scale[4]; |
| 216 |
uint32_t flags; |
| 217 |
uint32_t instance_uniforms_ofs; |
| 218 |
uint32_t gi_offset; |
| 219 |
uint32_t layer_mask; |
| 220 |
float prev_transform[12]; |
| 221 |
float lightmap_uv_scale[4]; |
| 222 |
uint32_t reflection_probes[2]; |
| 223 |
uint32_t omni_lights[2]; |
| 224 |
uint32_t spot_lights[2]; |
| 225 |
uint32_t decals[2]; |
| 226 |
#ifdef REAL_T_IS_DOUBLE |
| 227 |
float model_precision[4]; |
| 228 |
float prev_model_precision[4]; |
| 229 |
#endif |
| 230 |
|
| 231 |
|
| 232 |
inline void set_lightmap_uv_scale(const Rect2 &p_rect) { |
| 233 |
#ifdef REAL_T_IS_DOUBLE |
| 234 |
lightmap_uv_scale[0] = p_rect.position.x; |
| 235 |
lightmap_uv_scale[1] = p_rect.position.y; |
| 236 |
lightmap_uv_scale[2] = p_rect.size.x; |
| 237 |
lightmap_uv_scale[3] = p_rect.size.y; |
| 238 |
#else |
| 239 |
Rect2 *rect = reinterpret_cast<Rect2 *>(lightmap_uv_scale); |
| 240 |
*rect = p_rect; |
| 241 |
#endif |
| 242 |
} |
| 243 |
|
| 244 |
inline void set_compressed_aabb(const AABB &p_aabb) { |
| 245 |
#ifdef REAL_T_IS_DOUBLE |
| 246 |
compressed_aabb_position[0] = p_aabb.position.x; |
| 247 |
compressed_aabb_position[1] = p_aabb.position.y; |
| 248 |
compressed_aabb_position[2] = p_aabb.position.z; |
| 249 |
|
| 250 |
compressed_aabb_size[0] = p_aabb.size.x; |
| 251 |
compressed_aabb_size[1] = p_aabb.size.y; |
| 252 |
compressed_aabb_size[2] = p_aabb.size.z; |
| 253 |
#else |
| 254 |
Vector3 *compressed_aabb_position_vec3 = reinterpret_cast<Vector3 *>(compressed_aabb_position); |
| 255 |
Vector3 *compressed_aabb_size_vec3 = reinterpret_cast<Vector3 *>(compressed_aabb_size); |
| 256 |
*compressed_aabb_position_vec3 = p_aabb.position; |
| 257 |
*compressed_aabb_size_vec3 = p_aabb.size; |
| 258 |
#endif |
| 259 |
} |
| 260 |
|
| 261 |
inline void set_uv_scale(const Vector4 &p_uv_scale) { |
| 262 |
#ifdef REAL_T_IS_DOUBLE |
| 263 |
uv_scale[0] = p_uv_scale.x; |
| 264 |
uv_scale[1] = p_uv_scale.y; |
| 265 |
uv_scale[2] = p_uv_scale.z; |
| 266 |
uv_scale[3] = p_uv_scale.w; |
| 267 |
#else |
| 268 |
Vector4 *uv_scale_vec4 = reinterpret_cast<Vector4 *>(uv_scale); |
| 269 |
*uv_scale_vec4 = p_uv_scale; |
| 270 |
#endif |
| 271 |
} |
| 272 |
}; |
| 273 |
|
| 274 |
static_assert(std::is_trivially_destructible_v<InstanceData>); |
| 275 |
static_assert(std::is_trivially_constructible_v<InstanceData>); |
| 276 |
|
| 277 |
MultiUmaBuffer<1u> instance_buffer[RENDER_LIST_MAX] = { MultiUmaBuffer<1u>("RENDER_LIST_OPAQUE"), MultiUmaBuffer<1u>("RENDER_LIST_ALPHA"), MultiUmaBuffer<1u>("RENDER_LIST_SECONDARY") }; |
| 278 |
InstanceData *curr_gpu_ptr[RENDER_LIST_MAX] = {}; |
| 279 |
|
| 280 |
|
| 281 |
LightmapData lightmaps[MAX_LIGHTMAPS]; |
| 282 |
RID lightmap_ids[MAX_LIGHTMAPS]; |
| 283 |
bool lightmap_has_sh[MAX_LIGHTMAPS]; |
| 284 |
uint32_t lightmaps_used = 0; |
| 285 |
uint32_t max_lightmaps; |
| 286 |
RID lightmap_buffer; |
| 287 |
|
| 288 |
LightmapCaptureData *lightmap_captures = nullptr; |
| 289 |
uint32_t max_lightmap_captures; |
| 290 |
RID lightmap_capture_buffer; |
| 291 |
|
| 292 |
bool used_screen_texture = false; |
| 293 |
bool used_depth_texture = false; |
| 294 |
bool used_lightmap = false; |
| 295 |
bool used_opaque_stencil = false; |
| 296 |
|
| 297 |
struct ShadowPass { |
| 298 |
uint32_t element_from; |
| 299 |
uint32_t element_count; |
| 300 |
bool flip_cull; |
| 301 |
PassMode pass_mode; |
| 302 |
|
| 303 |
RID rp_uniform_set; |
| 304 |
float lod_distance_multiplier; |
| 305 |
float screen_mesh_lod_threshold; |
| 306 |
|
| 307 |
RID framebuffer; |
| 308 |
Rect2i rect; |
| 309 |
bool clear_depth; |
| 310 |
}; |
| 311 |
|
| 312 |
LocalVector<ShadowPass> shadow_passes; |
| 313 |
|
| 314 |
void grow_instance_buffer(RenderListType p_render_list, uint32_t p_req_element_count, bool p_append); |
| 315 |
} scene_state; |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
struct RenderList { |
| 321 |
LocalVector<GeometryInstanceSurfaceDataCache *> elements; |
| 322 |
LocalVector<RenderElementInfo> element_info; |
| 323 |
|
| 324 |
void clear() { |
| 325 |
elements.clear(); |
| 326 |
element_info.clear(); |
| 327 |
} |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
struct SortByKey { |
| 332 |
_FORCE_INLINE_ bool operator()(const GeometryInstanceSurfaceDataCache *A, const GeometryInstanceSurfaceDataCache *B) const { |
| 333 |
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); |
| 334 |
} |
| 335 |
}; |
| 336 |
|
| 337 |
void sort_by_key() { |
| 338 |
SortArray<GeometryInstanceSurfaceDataCache *, SortByKey> sorter; |
| 339 |
sorter.sort(elements.ptr(), elements.size()); |
| 340 |
} |
| 341 |
|
| 342 |
void sort_by_key_range(uint32_t p_from, uint32_t p_size) { |
| 343 |
SortArray<GeometryInstanceSurfaceDataCache *, SortByKey> sorter; |
| 344 |
sorter.sort(elements.ptr() + p_from, p_size); |
| 345 |
} |
| 346 |
|
| 347 |
struct SortByKeyAndStencil { |
| 348 |
_FORCE_INLINE_ bool operator()(const GeometryInstanceSurfaceDataCache *A, const GeometryInstanceSurfaceDataCache *B) const { |
| 349 |
bool a_stencil = A->flags & GeometryInstanceSurfaceDataCache::FLAG_USES_STENCIL; |
| 350 |
bool b_stencil = B->flags & GeometryInstanceSurfaceDataCache::FLAG_USES_STENCIL; |
| 351 |
if (a_stencil != b_stencil) { |
| 352 |
return a_stencil < b_stencil; |
| 353 |
} |
| 354 |
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); |
| 355 |
} |
| 356 |
}; |
| 357 |
|
| 358 |
void sort_by_key_and_stencil() { |
| 359 |
SortArray<GeometryInstanceSurfaceDataCache *, SortByKeyAndStencil> sorter; |
| 360 |
sorter.sort(elements.ptr(), elements.size()); |
| 361 |
} |
| 362 |
|
| 363 |
struct SortByDepth { |
| 364 |
_FORCE_INLINE_ bool operator()(const GeometryInstanceSurfaceDataCache *A, const GeometryInstanceSurfaceDataCache *B) const { |
| 365 |
return (A->owner->depth < B->owner->depth); |
| 366 |
} |
| 367 |
}; |
| 368 |
|
| 369 |
void sort_by_depth() { |
| 370 |
|
| 371 |
SortArray<GeometryInstanceSurfaceDataCache *, SortByDepth> sorter; |
| 372 |
sorter.sort(elements.ptr(), elements.size()); |
| 373 |
} |
| 374 |
|
| 375 |
struct SortByReverseDepthAndPriority { |
| 376 |
_FORCE_INLINE_ bool operator()(const GeometryInstanceSurfaceDataCache *A, const GeometryInstanceSurfaceDataCache *B) const { |
| 377 |
return (A->sort.priority == B->sort.priority) ? (A->owner->depth > B->owner->depth) : (A->sort.priority < B->sort.priority); |
| 378 |
} |
| 379 |
}; |
| 380 |
|
| 381 |
void sort_by_reverse_depth_and_priority() { |
| 382 |
|
| 383 |
SortArray<GeometryInstanceSurfaceDataCache *, SortByReverseDepthAndPriority> sorter; |
| 384 |
sorter.sort(elements.ptr(), elements.size()); |
| 385 |
} |
| 386 |
|
| 387 |
_FORCE_INLINE_ void add_element(GeometryInstanceSurfaceDataCache *p_element) { |
| 388 |
elements.push_back(p_element); |
| 389 |
} |
| 390 |
}; |
| 391 |
|
| 392 |
struct RenderElementInfo { |
| 393 |
union { |
| 394 |
struct { |
| 395 |
uint32_t lod_index : 8; |
| 396 |
uint32_t uses_lightmap : 1; |
| 397 |
uint32_t reserved : 23; |
| 398 |
}; |
| 399 |
uint32_t value; |
| 400 |
}; |
| 401 |
}; |
| 402 |
|
| 403 |
static_assert(std::is_trivially_destructible_v<RenderElementInfo>); |
| 404 |
static_assert(std::is_trivially_constructible_v<RenderElementInfo>); |
| 405 |
|
| 406 |
template <PassMode p_pass_mode> |
| 407 |
_FORCE_INLINE_ void _render_list_template(RenderingDevice::DrawListID p_draw_list, RenderingDevice::FramebufferFormatID p_framebuffer_Format, RenderListParameters *p_params, uint32_t p_from_element, uint32_t p_to_element); |
| 408 |
void _render_list(RenderingDevice::DrawListID p_draw_list, RenderingDevice::FramebufferFormatID p_framebuffer_Format, RenderListParameters *p_params, uint32_t p_from_element, uint32_t p_to_element); |
| 409 |
void _render_list_with_draw_list(RenderListParameters *p_params, RID p_framebuffer, BitField<RD::DrawFlags> p_clear_colors = RD::DRAW_DEFAULT_ALL, const Vector<Color> &p_clear_color_values = Vector<Color>(), float p_clear_depth_value = 0.0, uint32_t p_clear_stencil_value = 0, const Rect2 &p_region = Rect2()); |
| 410 |
|
| 411 |
RenderList render_list[RENDER_LIST_MAX]; |
| 412 |
|
| 413 |
protected: |
| 414 |
|
| 415 |
virtual void _update_shader_quality_settings() override; |
| 416 |
|
| 417 |
virtual RD::DataFormat _render_buffers_get_preferred_color_format() override; |
| 418 |
virtual bool _render_buffers_can_be_storage() override; |
| 419 |
|
| 420 |
virtual RID _render_buffers_get_normal_texture(Ref<RenderSceneBuffersRD> p_render_buffers) override; |
| 421 |
virtual RID _render_buffers_get_velocity_texture(Ref<RenderSceneBuffersRD> p_render_buffers) override; |
| 422 |
|
| 423 |
virtual 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 {} |
| 424 |
virtual 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 {} |
| 425 |
virtual void environment_set_ssr_half_size(bool p_half_size) override {} |
| 426 |
virtual void environment_set_ssr_roughness_quality(RS::EnvironmentSSRRoughnessQuality p_quality) override {} |
| 427 |
|
| 428 |
virtual void sub_surface_scattering_set_quality(RS::SubSurfaceScatteringQuality p_quality) override {} |
| 429 |
virtual void sub_surface_scattering_set_scale(float p_scale, float p_depth_scale) override {} |
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
class GeometryInstanceForwardMobile; |
| 434 |
|
| 435 |
|
| 436 |
enum { |
| 437 |
INSTANCE_DATA_FLAG_MULTIMESH_INDIRECT = 1 << 2, |
| 438 |
INSTANCE_DATA_FLAGS_DYNAMIC = 1 << 3, |
| 439 |
INSTANCE_DATA_FLAGS_NON_UNIFORM_SCALE = 1 << 4, |
| 440 |
INSTANCE_DATA_FLAG_USE_GI_BUFFERS = 1 << 5, |
| 441 |
INSTANCE_DATA_FLAG_USE_SDFGI = 1 << 6, |
| 442 |
INSTANCE_DATA_FLAG_USE_LIGHTMAP_CAPTURE = 1 << 7, |
| 443 |
INSTANCE_DATA_FLAG_USE_LIGHTMAP = 1 << 8, |
| 444 |
INSTANCE_DATA_FLAG_USE_SH_LIGHTMAP = 1 << 9, |
| 445 |
INSTANCE_DATA_FLAG_USE_VOXEL_GI = 1 << 10, |
| 446 |
INSTANCE_DATA_FLAG_PARTICLES = 1 << 11, |
| 447 |
INSTANCE_DATA_FLAG_MULTIMESH = 1 << 12, |
| 448 |
INSTANCE_DATA_FLAG_MULTIMESH_FORMAT_2D = 1 << 13, |
| 449 |
INSTANCE_DATA_FLAG_MULTIMESH_HAS_COLOR = 1 << 14, |
| 450 |
INSTANCE_DATA_FLAG_MULTIMESH_HAS_CUSTOM_DATA = 1 << 15, |
| 451 |
INSTANCE_DATA_FLAGS_PARTICLE_TRAIL_SHIFT = 16, |
| 452 |
INSTANCE_DATA_FLAGS_PARTICLE_TRAIL_MASK = 0xFF, |
| 453 |
}; |
| 454 |
|
| 455 |
struct GeometryInstanceLightmapSH { |
| 456 |
Color sh[9]; |
| 457 |
}; |
| 458 |
|
| 459 |
|
| 460 |
struct GeometryInstanceSurfaceDataCache { |
| 461 |
enum { |
| 462 |
FLAG_PASS_DEPTH = 1, |
| 463 |
FLAG_PASS_OPAQUE = 2, |
| 464 |
FLAG_PASS_ALPHA = 4, |
| 465 |
FLAG_PASS_SHADOW = 8, |
| 466 |
FLAG_USES_SHARED_SHADOW_MATERIAL = 128, |
| 467 |
FLAG_USES_SUBSURFACE_SCATTERING = 2048, |
| 468 |
FLAG_USES_SCREEN_TEXTURE = 4096, |
| 469 |
FLAG_USES_DEPTH_TEXTURE = 8192, |
| 470 |
FLAG_USES_NORMAL_TEXTURE = 16384, |
| 471 |
FLAG_USES_DOUBLE_SIDED_SHADOWS = 32768, |
| 472 |
FLAG_USES_PARTICLE_TRAILS = 65536, |
| 473 |
FLAG_USES_STENCIL = 131072, |
| 474 |
}; |
| 475 |
|
| 476 |
union { |
| 477 |
struct { |
| 478 |
uint64_t sort_key1; |
| 479 |
uint64_t sort_key2; |
| 480 |
}; |
| 481 |
struct { |
| 482 |
|
| 483 |
uint64_t lod_index : 8; |
| 484 |
uint64_t uses_lightmap : 1; |
| 485 |
uint64_t pad : 3; |
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
uint64_t depth_layer : 4; |
| 491 |
uint64_t surface_index : 8; |
| 492 |
uint64_t geometry_id : 32; |
| 493 |
uint64_t material_id_hi : 8; |
| 494 |
|
| 495 |
uint64_t material_id_lo : 24; |
| 496 |
uint64_t shader_id : 32; |
| 497 |
uint64_t priority : 8; |
| 498 |
}; |
| 499 |
} sort; |
| 500 |
|
| 501 |
RS::PrimitiveType primitive = RS::PRIMITIVE_MAX; |
| 502 |
uint32_t flags = 0; |
| 503 |
uint32_t surface_index = 0; |
| 504 |
|
| 505 |
void *surface = nullptr; |
| 506 |
RID material_uniform_set; |
| 507 |
SceneShaderForwardMobile::ShaderData *shader = nullptr; |
| 508 |
SceneShaderForwardMobile::MaterialData *material = nullptr; |
| 509 |
|
| 510 |
void *surface_shadow = nullptr; |
| 511 |
RID material_uniform_set_shadow; |
| 512 |
SceneShaderForwardMobile::ShaderData *shader_shadow = nullptr; |
| 513 |
|
| 514 |
GeometryInstanceSurfaceDataCache *next = nullptr; |
| 515 |
GeometryInstanceForwardMobile *owner = nullptr; |
| 516 |
|
| 517 |
SelfList<GeometryInstanceSurfaceDataCache> compilation_dirty_element; |
| 518 |
SelfList<GeometryInstanceSurfaceDataCache> compilation_all_element; |
| 519 |
|
| 520 |
GeometryInstanceSurfaceDataCache() : |
| 521 |
compilation_dirty_element(this), compilation_all_element(this) {} |
| 522 |
}; |
| 523 |
|
| 524 |
class GeometryInstanceForwardMobile : public RenderGeometryInstanceBase { |
| 525 |
public: |
| 526 |
|
| 527 |
RID transforms_uniform_set; |
| 528 |
bool use_projector = false; |
| 529 |
bool use_soft_shadow = false; |
| 530 |
bool store_transform_cache = true; |
| 531 |
uint32_t instance_count = 0; |
| 532 |
uint32_t trail_steps = 1; |
| 533 |
|
| 534 |
uint64_t prev_transform_change_frame = UINT_MAX; |
| 535 |
bool prev_transform_dirty = true; |
| 536 |
Transform3D prev_transform; |
| 537 |
|
| 538 |
|
| 539 |
uint32_t gi_offset_cache = 0; |
| 540 |
RID lightmap_instance; |
| 541 |
Rect2 lightmap_uv_scale; |
| 542 |
uint32_t lightmap_slice_index; |
| 543 |
GeometryInstanceLightmapSH *lightmap_sh = nullptr; |
| 544 |
|
| 545 |
|
| 546 |
uint32_t reflection_probe_count = 0; |
| 547 |
RendererRD::ForwardID reflection_probes[MAX_RDL_CULL]; |
| 548 |
uint32_t omni_light_count = 0; |
| 549 |
RendererRD::ForwardID omni_lights[MAX_RDL_CULL]; |
| 550 |
uint32_t spot_light_count = 0; |
| 551 |
RendererRD::ForwardID spot_lights[MAX_RDL_CULL]; |
| 552 |
uint32_t decals_count = 0; |
| 553 |
RendererRD::ForwardID decals[MAX_RDL_CULL]; |
| 554 |
|
| 555 |
GeometryInstanceSurfaceDataCache *surface_caches = nullptr; |
| 556 |
|
| 557 |
|
| 558 |
SelfList<GeometryInstanceForwardMobile> dirty_list_element; |
| 559 |
|
| 560 |
GeometryInstanceForwardMobile() : |
| 561 |
dirty_list_element(this) {} |
| 562 |
|
| 563 |
virtual void _mark_dirty() override; |
| 564 |
|
| 565 |
virtual void set_transform(const Transform3D &p_transform, const AABB &p_aabb, const AABB &p_transformed_aabb) override; |
| 566 |
virtual void set_use_lightmap(RID p_lightmap_instance, const Rect2 &p_lightmap_uv_scale, int p_lightmap_slice_index) override; |
| 567 |
virtual void set_lightmap_capture(const Color *p_sh9) override; |
| 568 |
|
| 569 |
virtual void clear_light_instances() override; |
| 570 |
virtual void pair_light_instance(const RID p_light_instance, RS::LightType light_type, uint32_t placement_idx) override; |
| 571 |
virtual void pair_reflection_probe_instances(const RID *p_reflection_probe_instances, uint32_t p_reflection_probe_instance_count) override; |
| 572 |
virtual void pair_decal_instances(const RID *p_decal_instances, uint32_t p_decal_instance_count) override; |
| 573 |
virtual void pair_voxel_gi_instances(const RID *p_voxel_gi_instances, uint32_t p_voxel_gi_instance_count) override {} |
| 574 |
|
| 575 |
virtual void set_softshadow_projector_pairing(bool p_softshadow, bool p_projector) override; |
| 576 |
}; |
| 577 |
|
| 578 |
virtual uint32_t get_max_lights_total() override; |
| 579 |
virtual uint32_t get_max_lights_per_mesh() override; |
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
virtual void _render_scene(RenderDataRD *p_render_data, const Color &p_default_bg_color) override; |
| 584 |
|
| 585 |
virtual 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, float p_exposure_normalization) override; |
| 586 |
virtual void _render_uv2(const PagedArray<RenderGeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override; |
| 587 |
virtual void _render_sdfgi(Ref<RenderSceneBuffersRD> p_render_buffers, const Vector3i &p_from, const Vector3i &p_size, const AABB &p_bounds, const PagedArray<RenderGeometryInstance *> &p_instances, const RID &p_albedo_texture, const RID &p_emission_texture, const RID &p_emission_aniso_texture, const RID &p_geom_facing_texture, float p_exposure_normalization) override; |
| 588 |
virtual void _render_particle_collider_heightfield(RID p_fb, const Transform3D &p_cam_transform, const Projection &p_cam_projection, const PagedArray<RenderGeometryInstance *> &p_instances) override; |
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
class ForwardIDStorageMobile : public RendererRD::ForwardIDStorage { |
| 593 |
public: |
| 594 |
struct ForwardIDAllocator { |
| 595 |
LocalVector<bool> allocations; |
| 596 |
LocalVector<uint8_t> map; |
| 597 |
LocalVector<uint64_t> last_pass; |
| 598 |
}; |
| 599 |
|
| 600 |
ForwardIDAllocator forward_id_allocators[RendererRD::FORWARD_ID_MAX]; |
| 601 |
|
| 602 |
public: |
| 603 |
virtual RendererRD::ForwardID allocate_forward_id(RendererRD::ForwardIDType p_type) override; |
| 604 |
virtual void free_forward_id(RendererRD::ForwardIDType p_type, RendererRD::ForwardID p_id) override; |
| 605 |
virtual void map_forward_id(RendererRD::ForwardIDType p_type, RendererRD::ForwardID p_id, uint32_t p_index, uint64_t p_last_pass) override; |
| 606 |
virtual bool uses_forward_ids() const override { return true; } |
| 607 |
}; |
| 608 |
|
| 609 |
ForwardIDStorageMobile *forward_id_storage_mobile = nullptr; |
| 610 |
|
| 611 |
void fill_push_constant_instance_indices(SceneState::InstanceData *p_instance_data, const GeometryInstanceForwardMobile *p_instance); |
| 612 |
|
| 613 |
virtual RendererRD::ForwardIDStorage *create_forward_id_storage() override { |
| 614 |
forward_id_storage_mobile = memnew(ForwardIDStorageMobile); |
| 615 |
return forward_id_storage_mobile; |
| 616 |
} |
| 617 |
|
| 618 |
struct ForwardIDByMapSort { |
| 619 |
uint8_t map; |
| 620 |
RendererRD::ForwardID forward_id; |
| 621 |
bool operator<(const ForwardIDByMapSort &p_sort) const { |
| 622 |
return map > p_sort.map; |
| 623 |
} |
| 624 |
}; |
| 625 |
|
| 626 |
public: |
| 627 |
static RenderForwardMobile *get_singleton() { return singleton; } |
| 628 |
|
| 629 |
virtual RID reflection_probe_create_framebuffer(RID p_color, RID p_depth) override; |
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
virtual void sdfgi_update(const Ref<RenderSceneBuffers> &p_render_buffers, RID p_environment, const Vector3 &p_world_position) override {} |
| 634 |
virtual int sdfgi_get_pending_region_count(const Ref<RenderSceneBuffers> &p_render_buffers) const override { return 0; } |
| 635 |
virtual AABB sdfgi_get_pending_region_bounds(const Ref<RenderSceneBuffers> &p_render_buffers, int p_region) const override { return AABB(); } |
| 636 |
virtual uint32_t sdfgi_get_pending_region_cascade(const Ref<RenderSceneBuffers> &p_render_buffers, int p_region) const override { return 0; } |
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
static void _geometry_instance_dependency_changed(Dependency::DependencyChangedNotification p_notification, DependencyTracker *p_tracker); |
| 641 |
static void _geometry_instance_dependency_deleted(const RID &p_dependency, DependencyTracker *p_tracker); |
| 642 |
|
| 643 |
SelfList<GeometryInstanceForwardMobile>::List geometry_instance_dirty_list; |
| 644 |
SelfList<GeometryInstanceSurfaceDataCache>::List geometry_surface_compilation_dirty_list; |
| 645 |
SelfList<GeometryInstanceSurfaceDataCache>::List geometry_surface_compilation_all_list; |
| 646 |
|
| 647 |
PagedAllocator<GeometryInstanceForwardMobile> geometry_instance_alloc; |
| 648 |
PagedAllocator<GeometryInstanceSurfaceDataCache> geometry_instance_surface_alloc; |
| 649 |
PagedAllocator<GeometryInstanceLightmapSH> geometry_instance_lightmap_sh; |
| 650 |
|
| 651 |
struct SurfacePipelineData { |
| 652 |
void *mesh_surface = nullptr; |
| 653 |
void *mesh_surface_shadow = nullptr; |
| 654 |
SceneShaderForwardMobile::ShaderData *shader = nullptr; |
| 655 |
SceneShaderForwardMobile::ShaderData *shader_shadow = nullptr; |
| 656 |
bool instanced = false; |
| 657 |
bool uses_opaque = false; |
| 658 |
bool uses_transparent = false; |
| 659 |
bool uses_depth = false; |
| 660 |
bool can_use_lightmap = false; |
| 661 |
}; |
| 662 |
|
| 663 |
struct GlobalPipelineData { |
| 664 |
union { |
| 665 |
uint32_t key; |
| 666 |
|
| 667 |
struct { |
| 668 |
uint32_t texture_samples : 3; |
| 669 |
uint32_t target_samples : 3; |
| 670 |
uint32_t use_reflection_probes : 1; |
| 671 |
uint32_t use_lightmaps : 1; |
| 672 |
uint32_t use_multiview : 1; |
| 673 |
uint32_t use_16_bit_shadows : 1; |
| 674 |
uint32_t use_32_bit_shadows : 1; |
| 675 |
uint32_t use_shadow_cubemaps : 1; |
| 676 |
uint32_t use_shadow_dual_paraboloid : 1; |
| 677 |
uint32_t use_vrs : 1; |
| 678 |
uint32_t use_subpass_post_pass : 1; |
| 679 |
uint32_t use_separate_post_pass : 1; |
| 680 |
uint32_t use_hdr_render_target : 1; |
| 681 |
uint32_t use_ldr_render_target : 1; |
| 682 |
}; |
| 683 |
}; |
| 684 |
}; |
| 685 |
|
| 686 |
GlobalPipelineData global_pipeline_data_compiled = {}; |
| 687 |
GlobalPipelineData global_pipeline_data_required = {}; |
| 688 |
|
| 689 |
typedef Pair<SceneShaderForwardMobile::ShaderData *, SceneShaderForwardMobile::ShaderData::PipelineKey> ShaderPipelinePair; |
| 690 |
|
| 691 |
void _update_global_pipeline_data_requirements_from_project(); |
| 692 |
void _update_global_pipeline_data_requirements_from_light_storage(); |
| 693 |
void _geometry_instance_add_surface_with_material(GeometryInstanceForwardMobile *ginstance, uint32_t p_surface, SceneShaderForwardMobile::MaterialData *p_material, uint32_t p_material_id, uint32_t p_shader_id, RID p_mesh); |
| 694 |
void _geometry_instance_add_surface_with_material_chain(GeometryInstanceForwardMobile *ginstance, uint32_t p_surface, SceneShaderForwardMobile::MaterialData *p_material, RID p_mat_src, RID p_mesh); |
| 695 |
void _geometry_instance_add_surface(GeometryInstanceForwardMobile *ginstance, uint32_t p_surface, RID p_material, RID p_mesh); |
| 696 |
void _geometry_instance_update(RenderGeometryInstance *p_geometry_instance); |
| 697 |
void _mesh_compile_pipeline_for_surface(SceneShaderForwardMobile::ShaderData *p_shader, void *p_mesh_surface, bool p_instanced_surface, RS::PipelineSource p_source, SceneShaderForwardMobile::ShaderData::PipelineKey &r_pipeline_key, Vector<ShaderPipelinePair> *r_pipeline_pairs = nullptr); |
| 698 |
void _mesh_compile_pipelines_for_surface(const SurfacePipelineData &p_surface, const GlobalPipelineData &p_global, RS::PipelineSource p_source, Vector<ShaderPipelinePair> *r_pipeline_pairs = nullptr); |
| 699 |
void _mesh_generate_all_pipelines_for_surface_cache(GeometryInstanceSurfaceDataCache *p_surface_cache, const GlobalPipelineData &p_global); |
| 700 |
void _update_dirty_geometry_instances(); |
| 701 |
void _update_dirty_geometry_pipelines(); |
| 702 |
|
| 703 |
|
| 704 |
struct GlobalSurfaceData { |
| 705 |
bool screen_texture_used = false; |
| 706 |
bool depth_texture_used = false; |
| 707 |
} global_surface_data; |
| 708 |
|
| 709 |
virtual RenderGeometryInstance *geometry_instance_create(RID p_base) override; |
| 710 |
virtual void geometry_instance_free(RenderGeometryInstance *p_geometry_instance) override; |
| 711 |
|
| 712 |
virtual uint32_t geometry_instance_get_pair_mask() override; |
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
virtual void mesh_generate_pipelines(RID p_mesh, bool p_background_compilation) override; |
| 717 |
virtual uint32_t get_pipeline_compilations(RS::PipelineSource p_source) override; |
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
virtual void enable_features(BitField<FeatureBits> p_feature_bits) override; |
| 722 |
virtual String get_name() const override; |
| 723 |
|
| 724 |
virtual bool free(RID p_rid) override; |
| 725 |
|
| 726 |
virtual void update() override; |
| 727 |
|
| 728 |
virtual void base_uniforms_changed() override; |
| 729 |
|
| 730 |
virtual bool is_dynamic_gi_supported() const override; |
| 731 |
virtual bool is_volumetric_supported() const override; |
| 732 |
virtual uint32_t get_max_elements() const override; |
| 733 |
|
| 734 |
RenderForwardMobile(); |
| 735 |
~RenderForwardMobile(); |
| 736 |
}; |
| 737 |
} |