2019-06-22 16:34:26 +00:00
/*************************************************************************/
2020-12-04 18:26:24 +00:00
/* renderer_storage_rd.h */
2019-06-22 16:34:26 +00:00
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
2022-01-03 20:27:34 +00:00
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
2019-06-22 16:34:26 +00:00
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
2020-12-04 18:26:24 +00:00
# ifndef RENDERING_SERVER_STORAGE_RD_H
# define RENDERING_SERVER_STORAGE_RD_H
2019-06-11 18:43:37 +00:00
2020-12-16 14:07:08 +00:00
# include "core/templates/list.h"
# include "core/templates/local_vector.h"
2020-11-07 22:33:38 +00:00
# include "core/templates/rid_owner.h"
2020-12-04 18:26:24 +00:00
# include "servers/rendering/renderer_compositor.h"
# include "servers/rendering/renderer_rd/effects_rd.h"
# include "servers/rendering/renderer_rd/shaders/particles.glsl.gen.h"
# include "servers/rendering/renderer_rd/shaders/particles_copy.glsl.gen.h"
2021-06-04 22:47:26 +00:00
# include "servers/rendering/renderer_rd/shaders/voxel_gi_sdf.glsl.gen.h"
2022-03-21 11:25:25 +00:00
# include "servers/rendering/renderer_rd/storage_rd/material_storage.h"
2020-12-04 18:26:24 +00:00
# include "servers/rendering/renderer_scene_render.h"
2020-03-27 18:21:27 +00:00
# include "servers/rendering/rendering_device.h"
2021-11-16 15:25:42 +00:00
# include "servers/rendering/shader_compiler.h"
2022-03-12 11:19:59 +00:00
2020-12-04 18:26:24 +00:00
class RendererStorageRD : public RendererStorage {
2019-06-11 18:43:37 +00:00
public :
2020-10-17 05:08:21 +00:00
static _FORCE_INLINE_ void store_transform ( const Transform3D & p_mtx , float * p_array ) {
2020-07-22 23:39:09 +00:00
p_array [ 0 ] = p_mtx . basis . elements [ 0 ] [ 0 ] ;
p_array [ 1 ] = p_mtx . basis . elements [ 1 ] [ 0 ] ;
p_array [ 2 ] = p_mtx . basis . elements [ 2 ] [ 0 ] ;
p_array [ 3 ] = 0 ;
p_array [ 4 ] = p_mtx . basis . elements [ 0 ] [ 1 ] ;
p_array [ 5 ] = p_mtx . basis . elements [ 1 ] [ 1 ] ;
p_array [ 6 ] = p_mtx . basis . elements [ 2 ] [ 1 ] ;
p_array [ 7 ] = 0 ;
p_array [ 8 ] = p_mtx . basis . elements [ 0 ] [ 2 ] ;
p_array [ 9 ] = p_mtx . basis . elements [ 1 ] [ 2 ] ;
p_array [ 10 ] = p_mtx . basis . elements [ 2 ] [ 2 ] ;
p_array [ 11 ] = 0 ;
p_array [ 12 ] = p_mtx . origin . x ;
p_array [ 13 ] = p_mtx . origin . y ;
p_array [ 14 ] = p_mtx . origin . z ;
p_array [ 15 ] = 1 ;
}
static _FORCE_INLINE_ void store_basis_3x4 ( const Basis & p_mtx , float * p_array ) {
p_array [ 0 ] = p_mtx . elements [ 0 ] [ 0 ] ;
p_array [ 1 ] = p_mtx . elements [ 1 ] [ 0 ] ;
p_array [ 2 ] = p_mtx . elements [ 2 ] [ 0 ] ;
p_array [ 3 ] = 0 ;
p_array [ 4 ] = p_mtx . elements [ 0 ] [ 1 ] ;
p_array [ 5 ] = p_mtx . elements [ 1 ] [ 1 ] ;
p_array [ 6 ] = p_mtx . elements [ 2 ] [ 1 ] ;
p_array [ 7 ] = 0 ;
p_array [ 8 ] = p_mtx . elements [ 0 ] [ 2 ] ;
p_array [ 9 ] = p_mtx . elements [ 1 ] [ 2 ] ;
p_array [ 10 ] = p_mtx . elements [ 2 ] [ 2 ] ;
p_array [ 11 ] = 0 ;
}
static _FORCE_INLINE_ void store_transform_3x3 ( const Basis & p_mtx , float * p_array ) {
p_array [ 0 ] = p_mtx . elements [ 0 ] [ 0 ] ;
p_array [ 1 ] = p_mtx . elements [ 1 ] [ 0 ] ;
p_array [ 2 ] = p_mtx . elements [ 2 ] [ 0 ] ;
p_array [ 3 ] = 0 ;
p_array [ 4 ] = p_mtx . elements [ 0 ] [ 1 ] ;
p_array [ 5 ] = p_mtx . elements [ 1 ] [ 1 ] ;
p_array [ 6 ] = p_mtx . elements [ 2 ] [ 1 ] ;
p_array [ 7 ] = 0 ;
p_array [ 8 ] = p_mtx . elements [ 0 ] [ 2 ] ;
p_array [ 9 ] = p_mtx . elements [ 1 ] [ 2 ] ;
p_array [ 10 ] = p_mtx . elements [ 2 ] [ 2 ] ;
p_array [ 11 ] = 0 ;
}
2020-10-17 05:08:21 +00:00
static _FORCE_INLINE_ void store_transform_transposed_3x4 ( const Transform3D & p_mtx , float * p_array ) {
2021-01-17 16:25:38 +00:00
p_array [ 0 ] = p_mtx . basis . elements [ 0 ] [ 0 ] ;
p_array [ 1 ] = p_mtx . basis . elements [ 0 ] [ 1 ] ;
p_array [ 2 ] = p_mtx . basis . elements [ 0 ] [ 2 ] ;
p_array [ 3 ] = p_mtx . origin . x ;
p_array [ 4 ] = p_mtx . basis . elements [ 1 ] [ 0 ] ;
p_array [ 5 ] = p_mtx . basis . elements [ 1 ] [ 1 ] ;
p_array [ 6 ] = p_mtx . basis . elements [ 1 ] [ 2 ] ;
p_array [ 7 ] = p_mtx . origin . y ;
p_array [ 8 ] = p_mtx . basis . elements [ 2 ] [ 0 ] ;
p_array [ 9 ] = p_mtx . basis . elements [ 2 ] [ 1 ] ;
p_array [ 10 ] = p_mtx . basis . elements [ 2 ] [ 2 ] ;
p_array [ 11 ] = p_mtx . origin . z ;
}
2020-07-22 23:39:09 +00:00
static _FORCE_INLINE_ void store_camera ( const CameraMatrix & p_mtx , float * p_array ) {
for ( int i = 0 ; i < 4 ; i + + ) {
for ( int j = 0 ; j < 4 ; j + + ) {
p_array [ i * 4 + j ] = p_mtx . matrix [ i ] [ j ] ;
}
}
}
static _FORCE_INLINE_ void store_soft_shadow_kernel ( const float * p_kernel , float * p_array ) {
for ( int i = 0 ; i < 128 ; i + + ) {
p_array [ i ] = p_kernel [ i ] ;
}
}
2019-07-21 14:31:30 +00:00
private :
2019-06-11 18:43:37 +00:00
/* TEXTURE API */
2019-06-16 02:45:24 +00:00
2020-03-27 18:21:27 +00:00
RID default_rd_samplers [ RS : : CANVAS_ITEM_TEXTURE_FILTER_MAX ] [ RS : : CANVAS_ITEM_TEXTURE_REPEAT_MAX ] ;
2021-11-23 21:16:03 +00:00
RID custom_rd_samplers [ RS : : CANVAS_ITEM_TEXTURE_FILTER_MAX ] [ RS : : CANVAS_ITEM_TEXTURE_REPEAT_MAX ] ;
2019-09-23 21:53:05 +00:00
2020-08-19 13:38:24 +00:00
/* PARTICLES */
struct ParticleData {
float xform [ 16 ] ;
float velocity [ 3 ] ;
uint32_t active ;
float color [ 4 ] ;
float custom [ 3 ] ;
float lifetime ;
} ;
struct ParticlesFrameParams {
2020-10-08 00:29:49 +00:00
enum {
MAX_ATTRACTORS = 32 ,
MAX_COLLIDERS = 32 ,
MAX_3D_TEXTURES = 7
} ;
enum AttractorType {
ATTRACTOR_TYPE_SPHERE ,
ATTRACTOR_TYPE_BOX ,
ATTRACTOR_TYPE_VECTOR_FIELD ,
} ;
struct Attractor {
float transform [ 16 ] ;
float extents [ 3 ] ; //exents or radius
uint32_t type ;
uint32_t texture_index ; //texture index for vector field
float strength ;
float attenuation ;
float directionality ;
} ;
enum CollisionType {
COLLISION_TYPE_SPHERE ,
COLLISION_TYPE_BOX ,
COLLISION_TYPE_SDF ,
2021-05-20 14:25:06 +00:00
COLLISION_TYPE_HEIGHT_FIELD ,
COLLISION_TYPE_2D_SDF ,
2020-10-08 00:29:49 +00:00
} ;
struct Collider {
float transform [ 16 ] ;
float extents [ 3 ] ; //exents or radius
uint32_t type ;
uint32_t texture_index ; //texture index for vector field
2021-08-12 14:07:47 +00:00
real_t scale ;
2020-10-08 00:29:49 +00:00
uint32_t pad [ 2 ] ;
} ;
2020-08-19 13:38:24 +00:00
uint32_t emitting ;
2021-08-17 10:22:04 +00:00
float system_phase ;
float prev_system_phase ;
2020-08-19 13:38:24 +00:00
uint32_t cycle ;
2021-08-12 14:07:47 +00:00
real_t explosiveness ;
real_t randomness ;
2021-08-17 10:22:04 +00:00
float time ;
float delta ;
2020-08-19 13:38:24 +00:00
2021-04-27 15:43:49 +00:00
uint32_t frame ;
uint32_t pad0 ;
uint32_t pad1 ;
uint32_t pad2 ;
2020-08-19 13:38:24 +00:00
uint32_t random_seed ;
2020-10-08 00:29:49 +00:00
uint32_t attractor_count ;
uint32_t collider_count ;
float particle_size ;
2020-08-19 13:38:24 +00:00
float emission_transform [ 16 ] ;
2020-10-08 00:29:49 +00:00
Attractor attractors [ MAX_ATTRACTORS ] ;
Collider colliders [ MAX_COLLIDERS ] ;
2020-08-19 13:38:24 +00:00
} ;
2020-09-06 12:18:10 +00:00
struct ParticleEmissionBufferData {
} ;
struct ParticleEmissionBuffer {
struct Data {
float xform [ 16 ] ;
float velocity [ 3 ] ;
uint32_t flags ;
float color [ 4 ] ;
float custom [ 4 ] ;
} ;
int32_t particle_count ;
int32_t particle_max ;
uint32_t pad1 ;
uint32_t pad2 ;
Data data [ 1 ] ; //its 2020 and empty arrays are still non standard in C++
} ;
2020-08-19 13:38:24 +00:00
struct Particles {
2021-05-10 16:12:44 +00:00
RS : : ParticlesMode mode = RS : : PARTICLES_MODE_3D ;
2021-04-05 11:36:41 +00:00
bool inactive = true ;
2021-02-02 02:16:37 +00:00
double inactive_time = 0.0 ;
2021-04-05 11:36:41 +00:00
bool emitting = false ;
bool one_shot = false ;
int amount = 0 ;
2021-02-02 02:16:37 +00:00
double lifetime = 1.0 ;
double pre_process_time = 0.0 ;
2021-08-12 14:07:47 +00:00
real_t explosiveness = 0.0 ;
real_t randomness = 0.0 ;
2021-04-05 11:36:41 +00:00
bool restart_request = false ;
AABB custom_aabb = AABB ( Vector3 ( - 4 , - 4 , - 4 ) , Vector3 ( 8 , 8 , 8 ) ) ;
bool use_local_coords = true ;
2021-05-20 14:25:06 +00:00
bool has_collision_cache = false ;
bool has_sdf_collision = false ;
Transform2D sdf_collision_transform ;
Rect2 sdf_collision_to_screen ;
RID sdf_collision_texture ;
2020-08-19 13:38:24 +00:00
RID process_material ;
2021-04-27 15:43:49 +00:00
uint32_t frame_counter = 0 ;
RS : : ParticlesTransformAlign transform_align = RS : : PARTICLES_TRANSFORM_ALIGN_DISABLED ;
2020-08-19 13:38:24 +00:00
2021-04-05 11:36:41 +00:00
RS : : ParticlesDrawOrder draw_order = RS : : PARTICLES_DRAW_ORDER_INDEX ;
2020-08-19 13:38:24 +00:00
Vector < RID > draw_passes ;
2020-10-17 05:08:21 +00:00
Vector < Transform3D > trail_bind_poses ;
2021-04-27 15:43:49 +00:00
bool trail_bind_poses_dirty = false ;
RID trail_bind_pose_buffer ;
RID trail_bind_pose_uniform_set ;
2020-08-19 13:38:24 +00:00
RID particle_buffer ;
RID particle_instance_buffer ;
RID frame_params_buffer ;
2022-02-14 12:27:10 +00:00
uint32_t userdata_count = 0 ;
2020-08-19 13:38:24 +00:00
RID particles_material_uniform_set ;
RID particles_copy_uniform_set ;
RID particles_transforms_buffer_uniform_set ;
2020-10-08 00:29:49 +00:00
RID collision_textures_uniform_set ;
RID collision_3d_textures [ ParticlesFrameParams : : MAX_3D_TEXTURES ] ;
uint32_t collision_3d_textures_used = 0 ;
RID collision_heightmap_texture ;
2020-08-19 13:38:24 +00:00
RID particles_sort_buffer ;
RID particles_sort_uniform_set ;
bool dirty = false ;
Particles * update_list = nullptr ;
2020-09-06 12:18:10 +00:00
RID sub_emitter ;
2021-08-12 14:07:47 +00:00
double phase = 0.0 ;
double prev_phase = 0.0 ;
2021-04-05 11:36:41 +00:00
uint64_t prev_ticks = 0 ;
uint32_t random_seed = 0 ;
2020-08-19 13:38:24 +00:00
2021-04-05 11:36:41 +00:00
uint32_t cycle_number = 0 ;
2020-08-19 13:38:24 +00:00
2021-02-02 02:16:37 +00:00
double speed_scale = 1.0 ;
2020-08-19 13:38:24 +00:00
2021-04-27 15:43:49 +00:00
int fixed_fps = 30 ;
bool interpolate = true ;
2021-04-05 11:36:41 +00:00
bool fractional_delta = false ;
2021-02-02 02:16:37 +00:00
double frame_remainder = 0 ;
2021-08-12 14:07:47 +00:00
real_t collision_base_size = 0.01 ;
2020-08-19 13:38:24 +00:00
2021-04-05 11:36:41 +00:00
bool clear = true ;
2020-08-19 13:38:24 +00:00
2020-09-06 12:18:10 +00:00
bool force_sub_emit = false ;
2020-10-17 05:08:21 +00:00
Transform3D emission_transform ;
2020-08-19 13:38:24 +00:00
2020-09-06 12:18:10 +00:00
Vector < uint8_t > emission_buffer_data ;
ParticleEmissionBuffer * emission_buffer = nullptr ;
RID emission_storage_buffer ;
2020-12-31 12:42:56 +00:00
Set < RID > collisions ;
2020-10-08 00:29:49 +00:00
2021-01-04 12:33:25 +00:00
Dependency dependency ;
2020-08-19 13:38:24 +00:00
2021-08-12 14:07:47 +00:00
double trail_length = 1.0 ;
2021-04-27 15:43:49 +00:00
bool trails_enabled = false ;
LocalVector < ParticlesFrameParams > frame_history ;
LocalVector < ParticlesFrameParams > trail_params ;
Particles ( ) {
}
2020-08-19 13:38:24 +00:00
} ;
2021-02-02 02:16:37 +00:00
void _particles_process ( Particles * p_particles , double p_delta ) ;
2020-09-06 12:18:10 +00:00
void _particles_allocate_emission_buffer ( Particles * particles ) ;
void _particles_free_data ( Particles * particles ) ;
2021-04-27 15:43:49 +00:00
void _particles_update_buffers ( Particles * particles ) ;
2020-08-19 13:38:24 +00:00
struct ParticlesShader {
struct PushConstant {
2021-08-17 10:22:04 +00:00
float lifetime ;
2020-08-19 13:38:24 +00:00
uint32_t clear ;
uint32_t total_particles ;
uint32_t trail_size ;
2020-09-06 12:18:10 +00:00
2020-08-19 13:38:24 +00:00
uint32_t use_fractional_delta ;
2020-09-06 12:18:10 +00:00
uint32_t sub_emitter_mode ;
uint32_t can_emit ;
2021-04-27 15:43:49 +00:00
uint32_t trail_pass ;
2020-08-19 13:38:24 +00:00
} ;
ParticlesShaderRD shader ;
2021-11-16 15:25:42 +00:00
ShaderCompiler compiler ;
2020-08-19 13:38:24 +00:00
RID default_shader ;
RID default_material ;
RID default_shader_rd ;
RID base_uniform_set ;
struct CopyPushConstant {
float sort_direction [ 3 ] ;
uint32_t total_particles ;
2021-04-27 15:43:49 +00:00
uint32_t trail_size ;
uint32_t trail_total ;
float frame_delta ;
float frame_remainder ;
float align_up [ 3 ] ;
uint32_t align_mode ;
2021-05-20 14:25:06 +00:00
uint32_t order_by_lifetime ;
uint32_t lifetime_split ;
uint32_t lifetime_reverse ;
2022-02-14 12:27:10 +00:00
uint32_t copy_mode_2d ;
2022-02-02 03:49:54 +00:00
float inv_emission_transform [ 16 ] ;
2020-08-19 13:38:24 +00:00
} ;
2022-02-14 12:27:10 +00:00
enum {
MAX_USERDATAS = 6
} ;
2020-08-19 13:38:24 +00:00
enum {
COPY_MODE_FILL_INSTANCES ,
COPY_MODE_FILL_SORT_BUFFER ,
COPY_MODE_FILL_INSTANCES_WITH_SORT_BUFFER ,
COPY_MODE_MAX ,
} ;
ParticlesCopyShaderRD copy_shader ;
RID copy_shader_version ;
2022-02-14 12:27:10 +00:00
RID copy_pipelines [ COPY_MODE_MAX * ( MAX_USERDATAS + 1 ) ] ;
2020-08-19 13:38:24 +00:00
2021-04-27 15:43:49 +00:00
LocalVector < float > pose_update_buffer ;
2020-08-19 13:38:24 +00:00
} particles_shader ;
Particles * particle_update_list = nullptr ;
2022-03-21 11:25:25 +00:00
struct ParticlesShaderData : public RendererRD : : ShaderData {
2020-08-19 13:38:24 +00:00
bool valid ;
RID version ;
2021-05-20 14:25:06 +00:00
bool uses_collision = false ;
2020-08-19 13:38:24 +00:00
2020-12-04 18:26:24 +00:00
//PipelineCacheRD pipelines[SKY_VERSION_MAX];
2020-08-19 13:38:24 +00:00
Map < StringName , ShaderLanguage : : ShaderNode : : Uniform > uniforms ;
2021-11-16 15:25:42 +00:00
Vector < ShaderCompiler : : GeneratedCode : : Texture > texture_uniforms ;
2020-08-19 13:38:24 +00:00
Vector < uint32_t > ubo_offsets ;
uint32_t ubo_size ;
String path ;
String code ;
2021-10-17 11:38:26 +00:00
Map < StringName , Map < int , RID > > default_texture_params ;
2020-08-19 13:38:24 +00:00
RID pipeline ;
2022-02-14 12:27:10 +00:00
bool uses_time = false ;
bool userdatas_used [ ParticlesShader : : MAX_USERDATAS ] = { } ;
uint32_t userdata_count = 0 ;
2020-08-19 13:38:24 +00:00
virtual void set_code ( const String & p_Code ) ;
2021-10-17 11:38:26 +00:00
virtual void set_default_texture_param ( const StringName & p_name , RID p_texture , int p_index ) ;
2020-08-19 13:38:24 +00:00
virtual void get_param_list ( List < PropertyInfo > * p_param_list ) const ;
2022-03-21 11:25:25 +00:00
virtual void get_instance_param_list ( List < RendererMaterialStorage : : InstanceShaderParam > * p_param_list ) const ;
2020-08-19 13:38:24 +00:00
virtual bool is_param_texture ( const StringName & p_param ) const ;
virtual bool is_animated ( ) const ;
virtual bool casts_shadows ( ) const ;
virtual Variant get_default_parameter ( const StringName & p_parameter ) const ;
2021-01-05 23:01:50 +00:00
virtual RS : : ShaderNativeSourceCode get_native_source_code ( ) const ;
2020-08-19 13:38:24 +00:00
ParticlesShaderData ( ) ;
virtual ~ ParticlesShaderData ( ) ;
} ;
2022-03-21 11:25:25 +00:00
RendererRD : : ShaderData * _create_particles_shader_func ( ) ;
static RendererRD : : ShaderData * _create_particles_shader_funcs ( ) {
2020-08-19 13:38:24 +00:00
return base_singleton - > _create_particles_shader_func ( ) ;
}
2022-03-21 11:25:25 +00:00
struct ParticlesMaterialData : public RendererRD : : MaterialData {
2021-07-06 21:56:28 +00:00
ParticlesShaderData * shader_data = nullptr ;
2020-08-19 13:38:24 +00:00
RID uniform_set ;
virtual void set_render_priority ( int p_priority ) { }
virtual void set_next_pass ( RID p_pass ) { }
2021-07-06 21:56:28 +00:00
virtual bool update_parameters ( const Map < StringName , Variant > & p_parameters , bool p_uniform_dirty , bool p_textures_dirty ) ;
2020-08-19 13:38:24 +00:00
virtual ~ ParticlesMaterialData ( ) ;
} ;
2022-03-21 11:25:25 +00:00
RendererRD : : MaterialData * _create_particles_material_func ( ParticlesShaderData * p_shader ) ;
static RendererRD : : MaterialData * _create_particles_material_funcs ( RendererRD : : ShaderData * p_shader ) {
2020-08-19 13:38:24 +00:00
return base_singleton - > _create_particles_material_func ( static_cast < ParticlesShaderData * > ( p_shader ) ) ;
}
void update_particles ( ) ;
2021-02-09 16:19:03 +00:00
mutable RID_Owner < Particles , true > particles_owner ;
2020-08-19 13:38:24 +00:00
2020-10-08 00:29:49 +00:00
/* Particles Collision */
struct ParticlesCollision {
RS : : ParticlesCollisionType type = RS : : PARTICLES_COLLISION_TYPE_SPHERE_ATTRACT ;
uint32_t cull_mask = 0xFFFFFFFF ;
float radius = 1.0 ;
Vector3 extents = Vector3 ( 1 , 1 , 1 ) ;
float attractor_strength = 1.0 ;
float attractor_attenuation = 1.0 ;
float attractor_directionality = 0.0 ;
RID field_texture ;
RID heightfield_texture ;
RID heightfield_fb ;
Size2i heightfield_fb_size ;
RS : : ParticlesCollisionHeightfieldResolution heightfield_resolution = RS : : PARTICLES_COLLISION_HEIGHTFIELD_RESOLUTION_1024 ;
2021-01-04 12:33:25 +00:00
Dependency dependency ;
2020-10-08 00:29:49 +00:00
} ;
2021-02-09 16:19:03 +00:00
mutable RID_Owner < ParticlesCollision , true > particles_collision_owner ;
2020-10-08 00:29:49 +00:00
2020-12-31 12:42:56 +00:00
struct ParticlesCollisionInstance {
RID collision ;
2020-10-17 05:08:21 +00:00
Transform3D transform ;
2020-12-31 12:42:56 +00:00
bool active = false ;
} ;
mutable RID_Owner < ParticlesCollisionInstance > particles_collision_instance_owner ;
2021-10-03 11:28:55 +00:00
/* FOG VOLUMES */
struct FogVolume {
RID material ;
Vector3 extents = Vector3 ( 1 , 1 , 1 ) ;
RS : : FogVolumeShape shape = RS : : FOG_VOLUME_SHAPE_BOX ;
Dependency dependency ;
} ;
mutable RID_Owner < FogVolume , true > fog_volume_owner ;
2021-06-16 18:43:02 +00:00
/* visibility_notifier */
struct VisibilityNotifier {
AABB aabb ;
Callable enter_callback ;
Callable exit_callback ;
Dependency dependency ;
} ;
mutable RID_Owner < VisibilityNotifier > visibility_notifier_owner ;
2019-09-07 01:51:27 +00:00
/* LIGHT */
struct Light {
2020-03-27 18:21:27 +00:00
RS : : LightType type ;
float param [ RS : : LIGHT_PARAM_MAX ] ;
2019-09-07 01:51:27 +00:00
Color color = Color ( 1 , 1 , 1 , 1 ) ;
RID projector ;
bool shadow = false ;
bool negative = false ;
bool reverse_cull = false ;
2020-06-25 13:33:28 +00:00
RS : : LightBakeMode bake_mode = RS : : LIGHT_BAKE_DYNAMIC ;
uint32_t max_sdfgi_cascade = 2 ;
2019-09-07 01:51:27 +00:00
uint32_t cull_mask = 0xFFFFFFFF ;
2022-02-24 21:55:14 +00:00
bool distance_fade = false ;
real_t distance_fade_begin = 40.0 ;
real_t distance_fade_shadow = 50.0 ;
real_t distance_fade_length = 10.0 ;
2020-03-27 18:21:27 +00:00
RS : : LightOmniShadowMode omni_shadow_mode = RS : : LIGHT_OMNI_SHADOW_DUAL_PARABOLOID ;
RS : : LightDirectionalShadowMode directional_shadow_mode = RS : : LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL ;
2019-09-07 01:51:27 +00:00
bool directional_blend_splits = false ;
2021-10-19 22:40:46 +00:00
RS : : LightDirectionalSkyMode directional_sky_mode = RS : : LIGHT_DIRECTIONAL_SKY_MODE_LIGHT_AND_SKY ;
2019-09-07 01:51:27 +00:00
uint64_t version = 0 ;
2021-01-04 12:33:25 +00:00
Dependency dependency ;
2019-09-07 01:51:27 +00:00
} ;
2021-02-09 16:19:03 +00:00
mutable RID_Owner < Light , true > light_owner ;
2019-09-07 01:51:27 +00:00
/* REFLECTION PROBE */
struct ReflectionProbe {
2020-03-27 18:21:27 +00:00
RS : : ReflectionProbeUpdateMode update_mode = RS : : REFLECTION_PROBE_UPDATE_ONCE ;
2019-09-07 01:51:27 +00:00
int resolution = 256 ;
float intensity = 1.0 ;
2020-06-25 13:33:28 +00:00
RS : : ReflectionProbeAmbientMode ambient_mode = RS : : REFLECTION_PROBE_AMBIENT_ENVIRONMENT ;
Color ambient_color ;
float ambient_color_energy = 1.0 ;
2019-09-07 01:51:27 +00:00
float max_distance = 0 ;
Vector3 extents = Vector3 ( 1 , 1 , 1 ) ;
Vector3 origin_offset ;
bool interior = false ;
bool box_projection = false ;
bool enable_shadows = false ;
uint32_t cull_mask = ( 1 < < 20 ) - 1 ;
2021-12-28 23:10:41 +00:00
float mesh_lod_threshold = 0.01 ;
2019-09-07 01:51:27 +00:00
2021-01-04 12:33:25 +00:00
Dependency dependency ;
2019-09-07 01:51:27 +00:00
} ;
2021-02-09 16:19:03 +00:00
mutable RID_Owner < ReflectionProbe , true > reflection_probe_owner ;
2019-09-07 01:51:27 +00:00
2021-06-04 22:47:26 +00:00
/* VOXEL GI */
2019-10-03 20:39:08 +00:00
2021-06-04 22:47:26 +00:00
struct VoxelGI {
2019-10-03 20:39:08 +00:00
RID octree_buffer ;
RID data_buffer ;
2019-10-11 02:14:56 +00:00
RID sdf_texture ;
2019-10-03 20:39:08 +00:00
uint32_t octree_buffer_size = 0 ;
uint32_t data_buffer_size = 0 ;
2020-02-17 21:06:54 +00:00
Vector < int > level_counts ;
2019-10-03 20:39:08 +00:00
int cell_count = 0 ;
2020-10-17 05:08:21 +00:00
Transform3D to_cell_xform ;
2019-10-03 20:39:08 +00:00
AABB bounds ;
Vector3i octree_size ;
2021-11-25 23:50:17 +00:00
float dynamic_range = 2.0 ;
2019-10-03 20:39:08 +00:00
float energy = 1.0 ;
float bias = 1.4 ;
float normal_bias = 0.0 ;
float propagation = 0.7 ;
bool interior = false ;
bool use_two_bounces = false ;
float anisotropy_strength = 0.5 ;
uint32_t version = 1 ;
uint32_t data_version = 1 ;
2021-01-04 12:33:25 +00:00
Dependency dependency ;
2019-10-03 20:39:08 +00:00
} ;
2021-06-04 22:47:26 +00:00
mutable RID_Owner < VoxelGI , true > voxel_gi_owner ;
2019-10-03 20:39:08 +00:00
2020-05-01 12:34:23 +00:00
/* REFLECTION PROBE */
struct Lightmap {
RID light_texture ;
bool uses_spherical_harmonics = false ;
bool interior = false ;
AABB bounds = AABB ( Vector3 ( ) , Vector3 ( 1 , 1 , 1 ) ) ;
int32_t array_index = - 1 ; //unassigned
PackedVector3Array points ;
PackedColorArray point_sh ;
PackedInt32Array tetrahedra ;
PackedInt32Array bsp_tree ;
struct BSP {
static const int32_t EMPTY_LEAF = INT32_MIN ;
float plane [ 4 ] ;
int32_t over = EMPTY_LEAF , under = EMPTY_LEAF ;
} ;
2021-01-04 12:33:25 +00:00
Dependency dependency ;
2020-05-01 12:34:23 +00:00
} ;
bool using_lightmap_array ; //high end uses this
/* for high end */
Vector < RID > lightmap_textures ;
uint64_t lightmap_array_version = 0 ;
2021-02-09 16:19:03 +00:00
mutable RID_Owner < Lightmap , true > lightmap_owner ;
2020-05-01 12:34:23 +00:00
float lightmap_probe_capture_update_speed = 4 ;
2019-07-27 13:23:24 +00:00
/* EFFECTS */
2021-10-12 07:30:55 +00:00
EffectsRD * effects = nullptr ;
2019-06-16 02:45:24 +00:00
public :
//internal usage
2020-03-27 18:21:27 +00:00
_FORCE_INLINE_ RID sampler_rd_get_default ( RS : : CanvasItemTextureFilter p_filter , RS : : CanvasItemTextureRepeat p_repeat ) {
2019-07-21 14:31:30 +00:00
return default_rd_samplers [ p_filter ] [ p_repeat ] ;
}
2021-11-23 21:16:03 +00:00
_FORCE_INLINE_ RID sampler_rd_get_custom ( RS : : CanvasItemTextureFilter p_filter , RS : : CanvasItemTextureRepeat p_repeat ) {
return custom_rd_samplers [ p_filter ] [ p_repeat ] ;
}
void sampler_rd_configure_custom ( float mipmap_bias ) ;
void sampler_rd_set_default ( float p_mipmap_bias ) ;
2019-07-21 14:31:30 +00:00
2019-06-11 18:43:37 +00:00
/* Light API */
2021-02-09 16:19:03 +00:00
void _light_initialize ( RID p_rid , RS : : LightType p_type ) ;
RID directional_light_allocate ( ) ;
void directional_light_initialize ( RID p_light ) ;
2019-06-11 18:43:37 +00:00
2021-02-09 16:19:03 +00:00
RID omni_light_allocate ( ) ;
void omni_light_initialize ( RID p_light ) ;
RID spot_light_allocate ( ) ;
void spot_light_initialize ( RID p_light ) ;
2019-06-11 18:43:37 +00:00
2019-09-07 01:51:27 +00:00
void light_set_color ( RID p_light , const Color & p_color ) ;
2020-03-27 18:21:27 +00:00
void light_set_param ( RID p_light , RS : : LightParam p_param , float p_value ) ;
2019-09-07 01:51:27 +00:00
void light_set_shadow ( RID p_light , bool p_enabled ) ;
void light_set_projector ( RID p_light , RID p_texture ) ;
void light_set_negative ( RID p_light , bool p_enable ) ;
void light_set_cull_mask ( RID p_light , uint32_t p_mask ) ;
2022-02-24 21:55:14 +00:00
void light_set_distance_fade ( RID p_light , bool p_enabled , float p_begin , float p_shadow , float p_length ) ;
2019-09-07 01:51:27 +00:00
void light_set_reverse_cull_face_mode ( RID p_light , bool p_enabled ) ;
2020-06-25 13:33:28 +00:00
void light_set_bake_mode ( RID p_light , RS : : LightBakeMode p_bake_mode ) ;
void light_set_max_sdfgi_cascade ( RID p_light , uint32_t p_cascade ) ;
2019-09-07 01:51:27 +00:00
2020-03-27 18:21:27 +00:00
void light_omni_set_shadow_mode ( RID p_light , RS : : LightOmniShadowMode p_mode ) ;
2019-09-07 01:51:27 +00:00
2020-03-27 18:21:27 +00:00
void light_directional_set_shadow_mode ( RID p_light , RS : : LightDirectionalShadowMode p_mode ) ;
2019-09-07 01:51:27 +00:00
void light_directional_set_blend_splits ( RID p_light , bool p_enable ) ;
bool light_directional_get_blend_splits ( RID p_light ) const ;
2021-10-19 22:40:46 +00:00
void light_directional_set_sky_mode ( RID p_light , RS : : LightDirectionalSkyMode p_mode ) ;
RS : : LightDirectionalSkyMode light_directional_get_sky_mode ( RID p_light ) const ;
2019-09-07 01:51:27 +00:00
2020-03-27 18:21:27 +00:00
RS : : LightDirectionalShadowMode light_directional_get_shadow_mode ( RID p_light ) ;
RS : : LightOmniShadowMode light_omni_get_shadow_mode ( RID p_light ) ;
2019-09-07 01:51:27 +00:00
2020-03-27 18:21:27 +00:00
_FORCE_INLINE_ RS : : LightType light_get_type ( RID p_light ) const {
2021-09-29 17:08:41 +00:00
const Light * light = light_owner . get_or_null ( p_light ) ;
2020-03-27 18:21:27 +00:00
ERR_FAIL_COND_V ( ! light , RS : : LIGHT_DIRECTIONAL ) ;
2019-09-07 01:51:27 +00:00
return light - > type ;
}
AABB light_get_aabb ( RID p_light ) const ;
2020-03-27 18:21:27 +00:00
_FORCE_INLINE_ float light_get_param ( RID p_light , RS : : LightParam p_param ) {
2021-09-29 17:08:41 +00:00
const Light * light = light_owner . get_or_null ( p_light ) ;
2019-09-07 01:51:27 +00:00
ERR_FAIL_COND_V ( ! light , 0 ) ;
return light - > param [ p_param ] ;
}
2020-04-14 20:05:45 +00:00
_FORCE_INLINE_ RID light_get_projector ( RID p_light ) {
2021-09-29 17:08:41 +00:00
const Light * light = light_owner . get_or_null ( p_light ) ;
2020-04-14 20:05:45 +00:00
ERR_FAIL_COND_V ( ! light , RID ( ) ) ;
return light - > projector ;
}
2019-09-07 01:51:27 +00:00
_FORCE_INLINE_ Color light_get_color ( RID p_light ) {
2021-09-29 17:08:41 +00:00
const Light * light = light_owner . get_or_null ( p_light ) ;
2019-09-07 01:51:27 +00:00
ERR_FAIL_COND_V ( ! light , Color ( ) ) ;
return light - > color ;
}
_FORCE_INLINE_ uint32_t light_get_cull_mask ( RID p_light ) {
2021-09-29 17:08:41 +00:00
const Light * light = light_owner . get_or_null ( p_light ) ;
2019-09-07 01:51:27 +00:00
ERR_FAIL_COND_V ( ! light , 0 ) ;
return light - > cull_mask ;
}
2022-02-24 21:55:14 +00:00
_FORCE_INLINE_ bool light_is_distance_fade_enabled ( RID p_light ) {
const Light * light = light_owner . get_or_null ( p_light ) ;
return light - > distance_fade ;
}
_FORCE_INLINE_ float light_get_distance_fade_begin ( RID p_light ) {
const Light * light = light_owner . get_or_null ( p_light ) ;
return light - > distance_fade_begin ;
}
_FORCE_INLINE_ float light_get_distance_fade_shadow ( RID p_light ) {
const Light * light = light_owner . get_or_null ( p_light ) ;
return light - > distance_fade_shadow ;
}
_FORCE_INLINE_ float light_get_distance_fade_length ( RID p_light ) {
const Light * light = light_owner . get_or_null ( p_light ) ;
return light - > distance_fade_length ;
}
2019-09-07 01:51:27 +00:00
_FORCE_INLINE_ bool light_has_shadow ( RID p_light ) const {
2021-09-29 17:08:41 +00:00
const Light * light = light_owner . get_or_null ( p_light ) ;
2020-03-27 18:21:27 +00:00
ERR_FAIL_COND_V ( ! light , RS : : LIGHT_DIRECTIONAL ) ;
2019-09-07 01:51:27 +00:00
return light - > shadow ;
}
2021-07-12 23:32:05 +00:00
_FORCE_INLINE_ bool light_has_projector ( RID p_light ) const {
2021-09-29 17:08:41 +00:00
const Light * light = light_owner . get_or_null ( p_light ) ;
2021-07-12 23:32:05 +00:00
ERR_FAIL_COND_V ( ! light , RS : : LIGHT_DIRECTIONAL ) ;
2022-03-12 11:19:59 +00:00
return light_owner . owns ( light - > projector ) ;
2021-07-12 23:32:05 +00:00
}
2019-09-07 01:51:27 +00:00
_FORCE_INLINE_ bool light_is_negative ( RID p_light ) const {
2021-09-29 17:08:41 +00:00
const Light * light = light_owner . get_or_null ( p_light ) ;
2020-03-27 18:21:27 +00:00
ERR_FAIL_COND_V ( ! light , RS : : LIGHT_DIRECTIONAL ) ;
2019-09-07 01:51:27 +00:00
return light - > negative ;
}
2020-04-08 01:51:52 +00:00
_FORCE_INLINE_ float light_get_transmittance_bias ( RID p_light ) const {
2021-09-29 17:08:41 +00:00
const Light * light = light_owner . get_or_null ( p_light ) ;
2020-04-08 01:51:52 +00:00
ERR_FAIL_COND_V ( ! light , 0.0 ) ;
return light - > param [ RS : : LIGHT_PARAM_TRANSMITTANCE_BIAS ] ;
}
2020-08-13 01:21:01 +00:00
_FORCE_INLINE_ float light_get_shadow_volumetric_fog_fade ( RID p_light ) const {
2021-09-29 17:08:41 +00:00
const Light * light = light_owner . get_or_null ( p_light ) ;
2020-08-13 01:21:01 +00:00
ERR_FAIL_COND_V ( ! light , 0.0 ) ;
return light - > param [ RS : : LIGHT_PARAM_SHADOW_VOLUMETRIC_FOG_FADE ] ;
}
2020-06-25 13:33:28 +00:00
RS : : LightBakeMode light_get_bake_mode ( RID p_light ) ;
uint32_t light_get_max_sdfgi_cascade ( RID p_light ) ;
2019-09-07 01:51:27 +00:00
uint64_t light_get_version ( RID p_light ) const ;
2019-06-11 18:43:37 +00:00
/* PROBE API */
2021-02-09 16:19:03 +00:00
RID reflection_probe_allocate ( ) ;
void reflection_probe_initialize ( RID p_reflection_probe ) ;
2019-09-07 01:51:27 +00:00
2020-03-27 18:21:27 +00:00
void reflection_probe_set_update_mode ( RID p_probe , RS : : ReflectionProbeUpdateMode p_mode ) ;
2019-09-07 01:51:27 +00:00
void reflection_probe_set_intensity ( RID p_probe , float p_intensity ) ;
2020-06-25 13:33:28 +00:00
void reflection_probe_set_ambient_mode ( RID p_probe , RS : : ReflectionProbeAmbientMode p_mode ) ;
void reflection_probe_set_ambient_color ( RID p_probe , const Color & p_color ) ;
void reflection_probe_set_ambient_energy ( RID p_probe , float p_energy ) ;
2019-09-07 01:51:27 +00:00
void reflection_probe_set_max_distance ( RID p_probe , float p_distance ) ;
void reflection_probe_set_extents ( RID p_probe , const Vector3 & p_extents ) ;
void reflection_probe_set_origin_offset ( RID p_probe , const Vector3 & p_offset ) ;
void reflection_probe_set_as_interior ( RID p_probe , bool p_enable ) ;
void reflection_probe_set_enable_box_projection ( RID p_probe , bool p_enable ) ;
void reflection_probe_set_enable_shadows ( RID p_probe , bool p_enable ) ;
void reflection_probe_set_cull_mask ( RID p_probe , uint32_t p_layers ) ;
void reflection_probe_set_resolution ( RID p_probe , int p_resolution ) ;
2021-12-28 23:10:41 +00:00
void reflection_probe_set_mesh_lod_threshold ( RID p_probe , float p_ratio ) ;
2019-09-07 01:51:27 +00:00
AABB reflection_probe_get_aabb ( RID p_probe ) const ;
2020-03-27 18:21:27 +00:00
RS : : ReflectionProbeUpdateMode reflection_probe_get_update_mode ( RID p_probe ) const ;
2019-09-07 01:51:27 +00:00
uint32_t reflection_probe_get_cull_mask ( RID p_probe ) const ;
Vector3 reflection_probe_get_extents ( RID p_probe ) const ;
Vector3 reflection_probe_get_origin_offset ( RID p_probe ) const ;
float reflection_probe_get_origin_max_distance ( RID p_probe ) const ;
2021-12-28 23:10:41 +00:00
float reflection_probe_get_mesh_lod_threshold ( RID p_probe ) const ;
2020-12-17 18:56:59 +00:00
2019-09-07 01:51:27 +00:00
int reflection_probe_get_resolution ( RID p_probe ) const ;
bool reflection_probe_renders_shadows ( RID p_probe ) const ;
float reflection_probe_get_intensity ( RID p_probe ) const ;
bool reflection_probe_is_interior ( RID p_probe ) const ;
bool reflection_probe_is_box_projection ( RID p_probe ) const ;
2020-06-25 13:33:28 +00:00
RS : : ReflectionProbeAmbientMode reflection_probe_get_ambient_mode ( RID p_probe ) const ;
Color reflection_probe_get_ambient_color ( RID p_probe ) const ;
float reflection_probe_get_ambient_color_energy ( RID p_probe ) const ;
2019-06-11 18:43:37 +00:00
2021-01-04 12:33:25 +00:00
void base_update_dependency ( RID p_base , DependencyTracker * p_instance ) ;
2019-06-11 18:43:37 +00:00
2021-06-04 22:47:26 +00:00
/* VOXEL GI API */
2019-06-11 18:43:37 +00:00
2021-06-04 22:47:26 +00:00
RID voxel_gi_allocate ( ) ;
void voxel_gi_initialize ( RID p_voxel_gi ) ;
2019-06-11 18:43:37 +00:00
2021-06-04 22:47:26 +00:00
void voxel_gi_allocate_data ( RID p_voxel_gi , const Transform3D & p_to_cell_xform , const AABB & p_aabb , const Vector3i & p_octree_size , const Vector < uint8_t > & p_octree_cells , const Vector < uint8_t > & p_data_cells , const Vector < uint8_t > & p_distance_field , const Vector < int > & p_level_counts ) ;
2019-06-11 18:43:37 +00:00
2021-06-04 22:47:26 +00:00
AABB voxel_gi_get_bounds ( RID p_voxel_gi ) const ;
Vector3i voxel_gi_get_octree_size ( RID p_voxel_gi ) const ;
Vector < uint8_t > voxel_gi_get_octree_cells ( RID p_voxel_gi ) const ;
Vector < uint8_t > voxel_gi_get_data_cells ( RID p_voxel_gi ) const ;
Vector < uint8_t > voxel_gi_get_distance_field ( RID p_voxel_gi ) const ;
2019-10-13 00:24:03 +00:00
2021-06-04 22:47:26 +00:00
Vector < int > voxel_gi_get_level_counts ( RID p_voxel_gi ) const ;
Transform3D voxel_gi_get_to_cell_xform ( RID p_voxel_gi ) const ;
2019-06-11 18:43:37 +00:00
2021-06-04 22:47:26 +00:00
void voxel_gi_set_dynamic_range ( RID p_voxel_gi , float p_range ) ;
float voxel_gi_get_dynamic_range ( RID p_voxel_gi ) const ;
2019-06-11 18:43:37 +00:00
2021-06-04 22:47:26 +00:00
void voxel_gi_set_propagation ( RID p_voxel_gi , float p_range ) ;
float voxel_gi_get_propagation ( RID p_voxel_gi ) const ;
2019-06-11 18:43:37 +00:00
2021-06-04 22:47:26 +00:00
void voxel_gi_set_energy ( RID p_voxel_gi , float p_energy ) ;
float voxel_gi_get_energy ( RID p_voxel_gi ) const ;
2019-06-11 18:43:37 +00:00
2021-06-04 22:47:26 +00:00
void voxel_gi_set_bias ( RID p_voxel_gi , float p_bias ) ;
float voxel_gi_get_bias ( RID p_voxel_gi ) const ;
2019-06-11 18:43:37 +00:00
2021-06-04 22:47:26 +00:00
void voxel_gi_set_normal_bias ( RID p_voxel_gi , float p_range ) ;
float voxel_gi_get_normal_bias ( RID p_voxel_gi ) const ;
2019-06-11 18:43:37 +00:00
2021-06-04 22:47:26 +00:00
void voxel_gi_set_interior ( RID p_voxel_gi , bool p_enable ) ;
bool voxel_gi_is_interior ( RID p_voxel_gi ) const ;
2019-06-11 18:43:37 +00:00
2021-06-04 22:47:26 +00:00
void voxel_gi_set_use_two_bounces ( RID p_voxel_gi , bool p_enable ) ;
bool voxel_gi_is_using_two_bounces ( RID p_voxel_gi ) const ;
2019-06-11 18:43:37 +00:00
2021-06-04 22:47:26 +00:00
void voxel_gi_set_anisotropy_strength ( RID p_voxel_gi , float p_strength ) ;
float voxel_gi_get_anisotropy_strength ( RID p_voxel_gi ) const ;
2019-06-11 18:43:37 +00:00
2021-06-04 22:47:26 +00:00
uint32_t voxel_gi_get_version ( RID p_probe ) ;
uint32_t voxel_gi_get_data_version ( RID p_probe ) ;
2019-06-11 18:43:37 +00:00
2021-06-04 22:47:26 +00:00
RID voxel_gi_get_octree_buffer ( RID p_voxel_gi ) const ;
RID voxel_gi_get_data_buffer ( RID p_voxel_gi ) const ;
2019-06-11 18:43:37 +00:00
2021-06-04 22:47:26 +00:00
RID voxel_gi_get_sdf_texture ( RID p_voxel_gi ) ;
2019-10-11 02:14:56 +00:00
2019-06-11 18:43:37 +00:00
/* LIGHTMAP CAPTURE */
2021-02-09 16:19:03 +00:00
RID lightmap_allocate ( ) ;
void lightmap_initialize ( RID p_lightmap ) ;
2020-05-01 12:34:23 +00:00
virtual void lightmap_set_textures ( RID p_lightmap , RID p_light , bool p_uses_spherical_haromics ) ;
virtual void lightmap_set_probe_bounds ( RID p_lightmap , const AABB & p_bounds ) ;
virtual void lightmap_set_probe_interior ( RID p_lightmap , bool p_interior ) ;
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 ) ;
virtual PackedVector3Array lightmap_get_probe_capture_points ( RID p_lightmap ) const ;
virtual PackedColorArray lightmap_get_probe_capture_sh ( RID p_lightmap ) const ;
virtual PackedInt32Array lightmap_get_probe_capture_tetrahedra ( RID p_lightmap ) const ;
virtual PackedInt32Array lightmap_get_probe_capture_bsp_tree ( RID p_lightmap ) const ;
virtual AABB lightmap_get_aabb ( RID p_lightmap ) const ;
virtual bool lightmap_is_interior ( RID p_lightmap ) const ;
virtual void lightmap_tap_sh_light ( RID p_lightmap , const Vector3 & p_point , Color * r_sh ) ;
virtual void lightmap_set_probe_capture_update_speed ( float p_speed ) ;
_FORCE_INLINE_ float lightmap_get_probe_capture_update_speed ( ) const {
return lightmap_probe_capture_update_speed ;
}
2020-12-31 12:42:56 +00:00
_FORCE_INLINE_ RID lightmap_get_texture ( RID p_lightmap ) const {
2021-09-29 17:08:41 +00:00
const Lightmap * lm = lightmap_owner . get_or_null ( p_lightmap ) ;
2020-12-31 12:42:56 +00:00
ERR_FAIL_COND_V ( ! lm , RID ( ) ) ;
return lm - > light_texture ;
}
2020-05-01 12:34:23 +00:00
_FORCE_INLINE_ int32_t lightmap_get_array_index ( RID p_lightmap ) const {
ERR_FAIL_COND_V ( ! using_lightmap_array , - 1 ) ; //only for arrays
2021-09-29 17:08:41 +00:00
const Lightmap * lm = lightmap_owner . get_or_null ( p_lightmap ) ;
2020-05-01 12:34:23 +00:00
return lm - > array_index ;
}
_FORCE_INLINE_ bool lightmap_uses_spherical_harmonics ( RID p_lightmap ) const {
ERR_FAIL_COND_V ( ! using_lightmap_array , false ) ; //only for arrays
2021-09-29 17:08:41 +00:00
const Lightmap * lm = lightmap_owner . get_or_null ( p_lightmap ) ;
2020-05-01 12:34:23 +00:00
return lm - > uses_spherical_harmonics ;
2019-06-11 18:43:37 +00:00
}
2020-05-01 12:34:23 +00:00
_FORCE_INLINE_ uint64_t lightmap_array_get_version ( ) const {
ERR_FAIL_COND_V ( ! using_lightmap_array , 0 ) ; //only for arrays
return lightmap_array_version ;
2019-06-11 18:43:37 +00:00
}
2020-05-01 12:34:23 +00:00
_FORCE_INLINE_ int lightmap_array_get_size ( ) const {
ERR_FAIL_COND_V ( ! using_lightmap_array , 0 ) ; //only for arrays
return lightmap_textures . size ( ) ;
}
_FORCE_INLINE_ const Vector < RID > & lightmap_array_get_textures ( ) const {
ERR_FAIL_COND_V ( ! using_lightmap_array , lightmap_textures ) ; //only for arrays
return lightmap_textures ;
2019-06-11 18:43:37 +00:00
}
/* PARTICLES */
2021-02-09 16:19:03 +00:00
RID particles_allocate ( ) ;
void particles_initialize ( RID p_particles_collision ) ;
2020-08-19 13:38:24 +00:00
2021-05-10 16:12:44 +00:00
void particles_set_mode ( RID p_particles , RS : : ParticlesMode p_mode ) ;
2020-08-19 13:38:24 +00:00
void particles_set_emitting ( RID p_particles , bool p_emitting ) ;
void particles_set_amount ( RID p_particles , int p_amount ) ;
2021-02-02 02:16:37 +00:00
void particles_set_lifetime ( RID p_particles , double p_lifetime ) ;
2020-08-19 13:38:24 +00:00
void particles_set_one_shot ( RID p_particles , bool p_one_shot ) ;
2021-02-02 02:16:37 +00:00
void particles_set_pre_process_time ( RID p_particles , double p_time ) ;
2021-08-12 14:07:47 +00:00
void particles_set_explosiveness_ratio ( RID p_particles , real_t p_ratio ) ;
void particles_set_randomness_ratio ( RID p_particles , real_t p_ratio ) ;
2020-08-19 13:38:24 +00:00
void particles_set_custom_aabb ( RID p_particles , const AABB & p_aabb ) ;
2021-02-02 02:16:37 +00:00
void particles_set_speed_scale ( RID p_particles , double p_scale ) ;
2020-08-19 13:38:24 +00:00
void particles_set_use_local_coordinates ( RID p_particles , bool p_enable ) ;
void particles_set_process_material ( RID p_particles , RID p_material ) ;
2022-02-14 12:27:10 +00:00
RID particles_get_process_material ( RID p_particles ) const ;
2020-08-19 13:38:24 +00:00
void particles_set_fixed_fps ( RID p_particles , int p_fps ) ;
2021-04-27 15:43:49 +00:00
void particles_set_interpolate ( RID p_particles , bool p_enable ) ;
2020-08-19 13:38:24 +00:00
void particles_set_fractional_delta ( RID p_particles , bool p_enable ) ;
2021-08-12 14:07:47 +00:00
void particles_set_collision_base_size ( RID p_particles , real_t p_size ) ;
2021-04-27 15:43:49 +00:00
void particles_set_transform_align ( RID p_particles , RS : : ParticlesTransformAlign p_transform_align ) ;
2021-08-12 14:07:47 +00:00
void particles_set_trails ( RID p_particles , bool p_enable , double p_length ) ;
2020-10-17 05:08:21 +00:00
void particles_set_trail_bind_poses ( RID p_particles , const Vector < Transform3D > & p_bind_poses ) ;
2021-04-27 15:43:49 +00:00
2020-08-19 13:38:24 +00:00
void particles_restart ( RID p_particles ) ;
2020-10-17 05:08:21 +00:00
void particles_emit ( RID p_particles , const Transform3D & p_transform , const Vector3 & p_velocity , const Color & p_color , const Color & p_custom , uint32_t p_emit_flags ) ;
2021-04-27 15:43:49 +00:00
2020-09-06 12:18:10 +00:00
void particles_set_subemitter ( RID p_particles , RID p_subemitter_particles ) ;
2019-06-11 18:43:37 +00:00
2020-08-19 13:38:24 +00:00
void particles_set_draw_order ( RID p_particles , RS : : ParticlesDrawOrder p_order ) ;
2019-06-11 18:43:37 +00:00
2020-08-19 13:38:24 +00:00
void particles_set_draw_passes ( RID p_particles , int p_count ) ;
void particles_set_draw_pass_mesh ( RID p_particles , int p_pass , RID p_mesh ) ;
2019-06-11 18:43:37 +00:00
2020-08-19 13:38:24 +00:00
void particles_request_process ( RID p_particles ) ;
AABB particles_get_current_aabb ( RID p_particles ) ;
AABB particles_get_aabb ( RID p_particles ) const ;
2019-06-11 18:43:37 +00:00
2020-10-17 05:08:21 +00:00
void particles_set_emission_transform ( RID p_particles , const Transform3D & p_transform ) ;
2019-06-11 18:43:37 +00:00
2020-08-19 13:38:24 +00:00
bool particles_get_emitting ( RID p_particles ) ;
int particles_get_draw_passes ( RID p_particles ) const ;
RID particles_get_draw_pass_mesh ( RID p_particles , int p_pass ) const ;
2021-04-27 15:43:49 +00:00
void particles_set_view_axis ( RID p_particles , const Vector3 & p_axis , const Vector3 & p_up_axis ) ;
2020-08-19 13:38:24 +00:00
virtual bool particles_is_inactive ( RID p_particles ) const ;
2021-05-10 16:12:44 +00:00
_FORCE_INLINE_ RS : : ParticlesMode particles_get_mode ( RID p_particles ) {
2021-09-29 17:08:41 +00:00
Particles * particles = particles_owner . get_or_null ( p_particles ) ;
2021-05-10 16:12:44 +00:00
ERR_FAIL_COND_V ( ! particles , RS : : PARTICLES_MODE_2D ) ;
return particles - > mode ;
}
2021-04-27 15:43:49 +00:00
_FORCE_INLINE_ uint32_t particles_get_amount ( RID p_particles , uint32_t & r_trail_divisor ) {
2021-09-29 17:08:41 +00:00
Particles * particles = particles_owner . get_or_null ( p_particles ) ;
2020-08-19 13:38:24 +00:00
ERR_FAIL_COND_V ( ! particles , 0 ) ;
2021-04-27 15:43:49 +00:00
if ( particles - > trails_enabled & & particles - > trail_bind_poses . size ( ) > 1 ) {
r_trail_divisor = particles - > trail_bind_poses . size ( ) ;
} else {
r_trail_divisor = 1 ;
}
return particles - > amount * r_trail_divisor ;
2020-08-19 13:38:24 +00:00
}
2019-06-11 18:43:37 +00:00
2021-05-20 14:25:06 +00:00
_FORCE_INLINE_ bool particles_has_collision ( RID p_particles ) {
2021-09-29 17:08:41 +00:00
Particles * particles = particles_owner . get_or_null ( p_particles ) ;
2021-05-20 14:25:06 +00:00
ERR_FAIL_COND_V ( ! particles , 0 ) ;
return particles - > has_collision_cache ;
}
2020-08-19 13:38:24 +00:00
_FORCE_INLINE_ uint32_t particles_is_using_local_coords ( RID p_particles ) {
2021-09-29 17:08:41 +00:00
Particles * particles = particles_owner . get_or_null ( p_particles ) ;
2020-08-19 13:38:24 +00:00
ERR_FAIL_COND_V ( ! particles , false ) ;
2019-06-11 18:43:37 +00:00
2020-08-19 13:38:24 +00:00
return particles - > use_local_coords ;
}
_FORCE_INLINE_ RID particles_get_instance_buffer_uniform_set ( RID p_particles , RID p_shader , uint32_t p_set ) {
2021-09-29 17:08:41 +00:00
Particles * particles = particles_owner . get_or_null ( p_particles ) ;
2020-08-19 13:38:24 +00:00
ERR_FAIL_COND_V ( ! particles , RID ( ) ) ;
if ( particles - > particles_transforms_buffer_uniform_set . is_null ( ) ) {
2021-04-27 15:43:49 +00:00
_particles_update_buffers ( particles ) ;
2020-08-19 13:38:24 +00:00
Vector < RD : : Uniform > uniforms ;
{
RD : : Uniform u ;
2020-10-17 01:19:21 +00:00
u . uniform_type = RD : : UNIFORM_TYPE_STORAGE_BUFFER ;
2020-08-19 13:38:24 +00:00
u . binding = 0 ;
2022-03-06 11:57:09 +00:00
u . append_id ( particles - > particle_instance_buffer ) ;
2020-08-19 13:38:24 +00:00
uniforms . push_back ( u ) ;
}
particles - > particles_transforms_buffer_uniform_set = RD : : get_singleton ( ) - > uniform_set_create ( uniforms , p_shader , p_set ) ;
}
return particles - > particles_transforms_buffer_uniform_set ;
}
2019-06-11 18:43:37 +00:00
2020-12-31 12:42:56 +00:00
virtual void particles_add_collision ( RID p_particles , RID p_particles_collision_instance ) ;
virtual void particles_remove_collision ( RID p_particles , RID p_particles_collision_instance ) ;
2021-05-20 14:25:06 +00:00
virtual void particles_set_canvas_sdf_collision ( RID p_particles , bool p_enable , const Transform2D & p_xform , const Rect2 & p_to_screen , RID p_texture ) ;
2020-10-08 00:29:49 +00:00
/* PARTICLES COLLISION */
2021-02-09 16:19:03 +00:00
RID particles_collision_allocate ( ) ;
void particles_collision_initialize ( RID p_particles_collision ) ;
2020-10-08 00:29:49 +00:00
virtual void particles_collision_set_collision_type ( RID p_particles_collision , RS : : ParticlesCollisionType p_type ) ;
virtual void particles_collision_set_cull_mask ( RID p_particles_collision , uint32_t p_cull_mask ) ;
2021-08-12 14:07:47 +00:00
virtual void particles_collision_set_sphere_radius ( RID p_particles_collision , real_t p_radius ) ; //for spheres
2020-10-08 00:29:49 +00:00
virtual void particles_collision_set_box_extents ( RID p_particles_collision , const Vector3 & p_extents ) ; //for non-spheres
2021-08-12 14:07:47 +00:00
virtual void particles_collision_set_attractor_strength ( RID p_particles_collision , real_t p_strength ) ;
virtual void particles_collision_set_attractor_directionality ( RID p_particles_collision , real_t p_directionality ) ;
virtual void particles_collision_set_attractor_attenuation ( RID p_particles_collision , real_t p_curve ) ;
2020-10-08 00:29:49 +00:00
virtual void particles_collision_set_field_texture ( RID p_particles_collision , RID p_texture ) ; //for SDF and vector field, heightfield is dynamic
virtual void particles_collision_height_field_update ( RID p_particles_collision ) ; //for SDF and vector field
virtual void particles_collision_set_height_field_resolution ( RID p_particles_collision , RS : : ParticlesCollisionHeightfieldResolution p_resolution ) ; //for SDF and vector field
virtual AABB particles_collision_get_aabb ( RID p_particles_collision ) const ;
virtual Vector3 particles_collision_get_extents ( RID p_particles_collision ) const ;
virtual bool particles_collision_is_heightfield ( RID p_particles_collision ) const ;
RID particles_collision_get_heightfield_framebuffer ( RID p_particles_collision ) const ;
2021-10-03 11:28:55 +00:00
/* FOG VOLUMES */
virtual RID fog_volume_allocate ( ) ;
virtual void fog_volume_initialize ( RID p_rid ) ;
virtual void fog_volume_set_shape ( RID p_fog_volume , RS : : FogVolumeShape p_shape ) ;
virtual void fog_volume_set_extents ( RID p_fog_volume , const Vector3 & p_extents ) ;
virtual void fog_volume_set_material ( RID p_fog_volume , RID p_material ) ;
virtual RS : : FogVolumeShape fog_volume_get_shape ( RID p_fog_volume ) const ;
virtual RID fog_volume_get_material ( RID p_fog_volume ) const ;
virtual AABB fog_volume_get_aabb ( RID p_fog_volume ) const ;
virtual Vector3 fog_volume_get_extents ( RID p_fog_volume ) const ;
/* VISIBILITY NOTIFIER */
2021-06-16 18:43:02 +00:00
virtual RID visibility_notifier_allocate ( ) ;
virtual void visibility_notifier_initialize ( RID p_notifier ) ;
virtual void visibility_notifier_set_aabb ( RID p_notifier , const AABB & p_aabb ) ;
virtual void visibility_notifier_set_callbacks ( RID p_notifier , const Callable & p_enter_callbable , const Callable & p_exit_callable ) ;
virtual AABB visibility_notifier_get_aabb ( RID p_notifier ) const ;
virtual void visibility_notifier_call ( RID p_notifier , bool p_enter , bool p_deferred ) ;
2020-12-31 12:42:56 +00:00
//used from 2D and 3D
virtual RID particles_collision_instance_create ( RID p_collision ) ;
2020-10-17 05:08:21 +00:00
virtual void particles_collision_instance_set_transform ( RID p_collision_instance , const Transform3D & p_transform ) ;
2020-12-31 12:42:56 +00:00
virtual void particles_collision_instance_set_active ( RID p_collision_instance , bool p_active ) ;
2020-03-27 18:21:27 +00:00
RS : : InstanceType get_base_type ( RID p_rid ) const ;
2019-06-11 18:43:37 +00:00
2019-06-16 02:45:24 +00:00
bool free ( RID p_rid ) ;
2019-06-11 18:43:37 +00:00
2019-09-14 03:37:42 +00:00
bool has_os_feature ( const String & p_feature ) const ;
2019-06-11 18:43:37 +00:00
2019-07-21 14:31:30 +00:00
void update_dirty_resources ( ) ;
2019-06-11 18:43:37 +00:00
void set_debug_generate_wireframes ( bool p_generate ) { }
2021-07-02 23:14:19 +00:00
//keep cached since it can be called form any thread
uint64_t texture_mem_cache = 0 ;
uint64_t buffer_mem_cache = 0 ;
uint64_t total_mem_cache = 0 ;
virtual void update_memory_info ( ) ;
virtual uint64_t get_rendering_info ( RS : : RenderingInfo p_info ) ;
2019-06-11 18:43:37 +00:00
2021-07-02 23:14:19 +00:00
String get_video_adapter_name ( ) const ;
String get_video_adapter_vendor ( ) const ;
2021-12-10 16:01:51 +00:00
RenderingDevice : : DeviceType get_video_adapter_type ( ) const ;
2019-06-11 18:43:37 +00:00
2019-09-20 20:58:06 +00:00
virtual void capture_timestamps_begin ( ) ;
virtual void capture_timestamp ( const String & p_name ) ;
virtual uint32_t get_captured_timestamps_count ( ) const ;
virtual uint64_t get_captured_timestamps_frame ( ) const ;
virtual uint64_t get_captured_timestamp_gpu_time ( uint32_t p_index ) const ;
virtual uint64_t get_captured_timestamp_cpu_time ( uint32_t p_index ) const ;
virtual String get_captured_timestamp_name ( uint32_t p_index ) const ;
2020-12-04 18:26:24 +00:00
static RendererStorageRD * base_singleton ;
2019-06-11 18:43:37 +00:00
2021-07-20 11:40:16 +00:00
void init_effects ( bool p_prefer_raster_effects ) ;
2020-12-04 18:26:24 +00:00
EffectsRD * get_effects ( ) ;
2019-07-27 13:23:24 +00:00
2020-12-04 18:26:24 +00:00
RendererStorageRD ( ) ;
~ RendererStorageRD ( ) ;
2019-06-11 18:43:37 +00:00
} ;
# endif // RASTERIZER_STORAGE_RD_H