2014-02-10 02:10:30 +01:00
/*************************************************************************/
2020-03-26 22:49:16 +01:00
/* visual_instance_3d.cpp */
2014-02-10 02:10:30 +01:00
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
2017-08-27 14:16:55 +02:00
/* https://godotengine.org */
2014-02-10 02:10:30 +01:00
/*************************************************************************/
2022-01-03 21:27:34 +01:00
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
2014-02-10 02:10:30 +01: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. */
/*************************************************************************/
2018-01-05 00:50:27 +01:00
2020-03-26 22:49:16 +01:00
# include "visual_instance_3d.h"
2014-02-10 02:10:30 +01:00
# include "scene/scene_string_names.h"
2022-03-10 08:17:38 +01:00
AABB VisualInstance3D : : get_aabb ( ) const {
AABB ret ;
if ( GDVIRTUAL_CALL ( _get_aabb , ret ) ) {
return ret ;
}
return AABB ( ) ;
}
2020-03-26 22:49:16 +01:00
AABB VisualInstance3D : : get_transformed_aabb ( ) const {
2017-03-05 16:44:50 +01:00
return get_global_transform ( ) . xform ( get_aabb ( ) ) ;
2014-02-10 02:10:30 +01:00
}
2020-03-26 22:49:16 +01:00
void VisualInstance3D : : _update_visibility ( ) {
2020-05-14 16:41:43 +02:00
if ( ! is_inside_tree ( ) ) {
2017-01-04 05:16:14 +01:00
return ;
2020-05-14 16:41:43 +02:00
}
2017-01-04 05:16:14 +01:00
2020-03-27 19:21:27 +01:00
RS : : get_singleton ( ) - > instance_set_visible ( get_instance ( ) , is_visible_in_tree ( ) ) ;
2017-01-04 05:16:14 +01:00
}
2020-03-26 22:49:16 +01:00
void VisualInstance3D : : _notification ( int p_what ) {
2017-03-05 16:44:50 +01:00
switch ( p_what ) {
2014-02-10 02:10:30 +01:00
case NOTIFICATION_ENTER_WORLD : {
2020-04-18 11:00:51 +02:00
ERR_FAIL_COND ( get_world_3d ( ) . is_null ( ) ) ;
RenderingServer : : get_singleton ( ) - > instance_set_scenario ( instance , get_world_3d ( ) - > get_scenario ( ) ) ;
2017-01-04 05:16:14 +01:00
_update_visibility ( ) ;
2014-02-10 02:10:30 +01:00
} break ;
2022-02-15 18:06:48 +01:00
2014-02-10 02:10:30 +01:00
case NOTIFICATION_TRANSFORM_CHANGED : {
2020-10-17 07:08:21 +02:00
Transform3D gt = get_global_transform ( ) ;
2020-03-27 19:21:27 +01:00
RenderingServer : : get_singleton ( ) - > instance_set_transform ( instance , gt ) ;
2014-02-10 02:10:30 +01:00
} break ;
2022-02-15 18:06:48 +01:00
2014-02-10 02:10:30 +01:00
case NOTIFICATION_EXIT_WORLD : {
2020-03-27 19:21:27 +01:00
RenderingServer : : get_singleton ( ) - > instance_set_scenario ( instance , RID ( ) ) ;
RenderingServer : : get_singleton ( ) - > instance_attach_skeleton ( instance , RID ( ) ) ;
2017-01-04 05:16:14 +01:00
} break ;
2022-02-15 18:06:48 +01:00
2017-01-04 05:16:14 +01:00
case NOTIFICATION_VISIBILITY_CHANGED : {
_update_visibility ( ) ;
2014-02-10 02:10:30 +01:00
} break ;
}
}
2020-03-26 22:49:16 +01:00
RID VisualInstance3D : : get_instance ( ) const {
2014-02-10 02:10:30 +01:00
return instance ;
}
2020-03-26 22:49:16 +01:00
RID VisualInstance3D : : _get_visual_instance_rid ( ) const {
2014-02-10 02:10:30 +01:00
return instance ;
}
2020-03-26 22:49:16 +01:00
void VisualInstance3D : : set_layer_mask ( uint32_t p_mask ) {
2017-03-05 16:44:50 +01:00
layers = p_mask ;
2020-03-27 19:21:27 +01:00
RenderingServer : : get_singleton ( ) - > instance_set_layer_mask ( instance , p_mask ) ;
2014-02-10 02:10:30 +01:00
}
2020-03-26 22:49:16 +01:00
uint32_t VisualInstance3D : : get_layer_mask ( ) const {
2014-02-10 02:10:30 +01:00
return layers ;
}
2021-08-12 01:01:38 +02:00
void VisualInstance3D : : set_layer_mask_value ( int p_layer_number , bool p_value ) {
ERR_FAIL_COND_MSG ( p_layer_number < 1 , " Render layer number must be between 1 and 20 inclusive. " ) ;
ERR_FAIL_COND_MSG ( p_layer_number > 20 , " Render layer number must be between 1 and 20 inclusive. " ) ;
uint32_t mask = get_layer_mask ( ) ;
if ( p_value ) {
mask | = 1 < < ( p_layer_number - 1 ) ;
2018-07-30 01:05:16 +02:00
} else {
2021-08-12 01:01:38 +02:00
mask & = ~ ( 1 < < ( p_layer_number - 1 ) ) ;
2018-07-30 01:05:16 +02:00
}
2021-08-12 01:01:38 +02:00
set_layer_mask ( mask ) ;
2018-07-30 01:05:16 +02:00
}
2021-08-12 01:01:38 +02:00
bool VisualInstance3D : : get_layer_mask_value ( int p_layer_number ) const {
ERR_FAIL_COND_V_MSG ( p_layer_number < 1 , false , " Render layer number must be between 1 and 20 inclusive. " ) ;
ERR_FAIL_COND_V_MSG ( p_layer_number > 20 , false , " Render layer number must be between 1 and 20 inclusive. " ) ;
return layers & ( 1 < < ( p_layer_number - 1 ) ) ;
2018-07-30 01:05:16 +02:00
}
2020-03-26 22:49:16 +01:00
void VisualInstance3D : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " _get_visual_instance_rid " ) , & VisualInstance3D : : _get_visual_instance_rid ) ;
ClassDB : : bind_method ( D_METHOD ( " set_base " , " base " ) , & VisualInstance3D : : set_base ) ;
ClassDB : : bind_method ( D_METHOD ( " get_base " ) , & VisualInstance3D : : get_base ) ;
ClassDB : : bind_method ( D_METHOD ( " get_instance " ) , & VisualInstance3D : : get_instance ) ;
ClassDB : : bind_method ( D_METHOD ( " set_layer_mask " , " mask " ) , & VisualInstance3D : : set_layer_mask ) ;
ClassDB : : bind_method ( D_METHOD ( " get_layer_mask " ) , & VisualInstance3D : : get_layer_mask ) ;
2021-08-12 01:01:38 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_layer_mask_value " , " layer_number " , " value " ) , & VisualInstance3D : : set_layer_mask_value ) ;
ClassDB : : bind_method ( D_METHOD ( " get_layer_mask_value " , " layer_number " ) , & VisualInstance3D : : get_layer_mask_value ) ;
2014-02-10 02:10:30 +01:00
2020-03-26 22:49:16 +01:00
ClassDB : : bind_method ( D_METHOD ( " get_transformed_aabb " ) , & VisualInstance3D : : get_transformed_aabb ) ;
2016-09-22 23:01:44 +02:00
2022-03-10 08:17:38 +01:00
GDVIRTUAL_BIND ( _get_aabb ) ;
2017-03-05 16:44:50 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " layers " , PROPERTY_HINT_LAYERS_3D_RENDER ) , " set_layer_mask " , " get_layer_mask " ) ;
2014-02-10 02:10:30 +01:00
}
2020-03-26 22:49:16 +01:00
void VisualInstance3D : : set_base ( const RID & p_base ) {
2020-03-27 19:21:27 +01:00
RenderingServer : : get_singleton ( ) - > instance_set_base ( instance , p_base ) ;
2019-04-23 00:27:30 +02:00
base = p_base ;
}
2020-03-26 22:49:16 +01:00
RID VisualInstance3D : : get_base ( ) const {
2019-04-23 00:27:30 +02:00
return base ;
2014-02-10 02:10:30 +01:00
}
2020-03-26 22:49:16 +01:00
VisualInstance3D : : VisualInstance3D ( ) {
2020-03-27 19:21:27 +01:00
instance = RenderingServer : : get_singleton ( ) - > instance_create ( ) ;
RenderingServer : : get_singleton ( ) - > instance_attach_object_instance_id ( instance , get_instance_id ( ) ) ;
2017-01-13 00:35:46 +01:00
set_notify_transform ( true ) ;
2014-02-10 02:10:30 +01:00
}
2020-03-26 22:49:16 +01:00
VisualInstance3D : : ~ VisualInstance3D ( ) {
2020-03-27 19:21:27 +01:00
RenderingServer : : get_singleton ( ) - > free ( instance ) ;
2014-02-10 02:10:30 +01:00
}
2020-03-26 22:49:16 +01:00
void GeometryInstance3D : : set_material_override ( const Ref < Material > & p_material ) {
2017-03-05 16:44:50 +01:00
material_override = p_material ;
2020-03-27 19:21:27 +01:00
RS : : get_singleton ( ) - > instance_geometry_set_material_override ( get_instance ( ) , p_material . is_valid ( ) ? p_material - > get_rid ( ) : RID ( ) ) ;
2014-02-10 02:10:30 +01:00
}
2020-03-26 22:49:16 +01:00
Ref < Material > GeometryInstance3D : : get_material_override ( ) const {
2014-02-10 02:10:30 +01:00
return material_override ;
}
2021-09-25 20:40:26 +02:00
void GeometryInstance3D : : set_material_overlay ( const Ref < Material > & p_material ) {
material_overlay = p_material ;
RS : : get_singleton ( ) - > instance_geometry_set_material_overlay ( get_instance ( ) , p_material . is_valid ( ) ? p_material - > get_rid ( ) : RID ( ) ) ;
}
Ref < Material > GeometryInstance3D : : get_material_overlay ( ) const {
return material_overlay ;
}
2021-07-20 20:17:34 +02:00
void GeometryInstance3D : : set_transparecy ( float p_transparency ) {
transparency = CLAMP ( p_transparency , 0.0f , 1.0f ) ;
RS : : get_singleton ( ) - > instance_geometry_set_transparency ( get_instance ( ) , transparency ) ;
}
float GeometryInstance3D : : get_transparency ( ) const {
return transparency ;
}
2021-05-09 18:23:20 +02:00
void GeometryInstance3D : : set_visibility_range_begin ( float p_dist ) {
visibility_range_begin = p_dist ;
2021-07-20 20:17:34 +02:00
RS : : get_singleton ( ) - > instance_geometry_set_visibility_range ( get_instance ( ) , visibility_range_begin , visibility_range_end , visibility_range_begin_margin , visibility_range_end_margin , ( RS : : VisibilityRangeFadeMode ) visibility_range_fade_mode ) ;
2021-07-28 19:33:14 +02:00
update_configuration_warnings ( ) ;
2014-02-10 02:10:30 +01:00
}
2021-05-09 18:23:20 +02:00
float GeometryInstance3D : : get_visibility_range_begin ( ) const {
return visibility_range_begin ;
2014-02-10 02:10:30 +01:00
}
2021-05-09 18:23:20 +02:00
void GeometryInstance3D : : set_visibility_range_end ( float p_dist ) {
visibility_range_end = p_dist ;
2021-07-20 20:17:34 +02:00
RS : : get_singleton ( ) - > instance_geometry_set_visibility_range ( get_instance ( ) , visibility_range_begin , visibility_range_end , visibility_range_begin_margin , visibility_range_end_margin , ( RS : : VisibilityRangeFadeMode ) visibility_range_fade_mode ) ;
2021-07-28 19:33:14 +02:00
update_configuration_warnings ( ) ;
2014-02-10 02:10:30 +01:00
}
2021-05-09 18:23:20 +02:00
float GeometryInstance3D : : get_visibility_range_end ( ) const {
return visibility_range_end ;
2014-02-10 02:10:30 +01:00
}
2021-05-09 18:23:20 +02:00
void GeometryInstance3D : : set_visibility_range_begin_margin ( float p_dist ) {
visibility_range_begin_margin = p_dist ;
2021-07-20 20:17:34 +02:00
RS : : get_singleton ( ) - > instance_geometry_set_visibility_range ( get_instance ( ) , visibility_range_begin , visibility_range_end , visibility_range_begin_margin , visibility_range_end_margin , ( RS : : VisibilityRangeFadeMode ) visibility_range_fade_mode ) ;
2021-11-26 21:46:32 +01:00
update_configuration_warnings ( ) ;
2016-10-03 21:33:42 +02:00
}
2014-06-11 15:41:03 +02:00
2021-05-09 18:23:20 +02:00
float GeometryInstance3D : : get_visibility_range_begin_margin ( ) const {
return visibility_range_begin_margin ;
2014-02-10 02:10:30 +01:00
}
2014-06-11 15:41:03 +02:00
2021-05-09 18:23:20 +02:00
void GeometryInstance3D : : set_visibility_range_end_margin ( float p_dist ) {
visibility_range_end_margin = p_dist ;
2021-07-20 20:17:34 +02:00
RS : : get_singleton ( ) - > instance_geometry_set_visibility_range ( get_instance ( ) , visibility_range_begin , visibility_range_end , visibility_range_begin_margin , visibility_range_end_margin , ( RS : : VisibilityRangeFadeMode ) visibility_range_fade_mode ) ;
2021-11-26 21:46:32 +01:00
update_configuration_warnings ( ) ;
2014-02-10 02:10:30 +01:00
}
2014-06-11 15:41:03 +02:00
2021-05-09 18:23:20 +02:00
float GeometryInstance3D : : get_visibility_range_end_margin ( ) const {
return visibility_range_end_margin ;
2016-10-03 21:33:42 +02:00
}
2014-06-11 15:41:03 +02:00
2021-07-20 20:17:34 +02:00
void GeometryInstance3D : : set_visibility_range_fade_mode ( VisibilityRangeFadeMode p_mode ) {
visibility_range_fade_mode = p_mode ;
RS : : get_singleton ( ) - > instance_geometry_set_visibility_range ( get_instance ( ) , visibility_range_begin , visibility_range_end , visibility_range_begin_margin , visibility_range_end_margin , ( RS : : VisibilityRangeFadeMode ) visibility_range_fade_mode ) ;
2021-11-26 21:46:32 +01:00
update_configuration_warnings ( ) ;
2021-07-20 20:17:34 +02:00
}
GeometryInstance3D : : VisibilityRangeFadeMode GeometryInstance3D : : get_visibility_range_fade_mode ( ) const {
return visibility_range_fade_mode ;
}
2020-04-17 04:52:00 +02:00
const StringName * GeometryInstance3D : : _instance_uniform_get_remap ( const StringName p_name ) const {
StringName * r = instance_uniform_property_remap . getptr ( p_name ) ;
if ( ! r ) {
String s = p_name ;
if ( s . begins_with ( " shader_params/ " ) ) {
StringName name = s . replace ( " shader_params/ " , " " ) ;
instance_uniform_property_remap [ p_name ] = name ;
return instance_uniform_property_remap . getptr ( p_name ) ;
}
return nullptr ;
}
return r ;
}
bool GeometryInstance3D : : _set ( const StringName & p_name , const Variant & p_value ) {
const StringName * r = _instance_uniform_get_remap ( p_name ) ;
if ( r ) {
set_shader_instance_uniform ( * r , p_value ) ;
return true ;
}
2020-05-01 14:34:23 +02:00
# ifndef DISABLE_DEPRECATED
if ( p_name = = SceneStringNames : : get_singleton ( ) - > use_in_baked_light & & bool ( p_value ) ) {
2021-11-26 17:47:37 +01:00
set_gi_mode ( GI_MODE_STATIC ) ;
2020-05-01 14:34:23 +02:00
return true ;
}
2020-04-17 04:52:00 +02:00
2020-05-01 14:34:23 +02:00
if ( p_name = = SceneStringNames : : get_singleton ( ) - > use_dynamic_gi & & bool ( p_value ) ) {
set_gi_mode ( GI_MODE_DYNAMIC ) ;
return true ;
}
# endif
2020-04-17 04:52:00 +02:00
return false ;
}
bool GeometryInstance3D : : _get ( const StringName & p_name , Variant & r_ret ) const {
const StringName * r = _instance_uniform_get_remap ( p_name ) ;
if ( r ) {
r_ret = get_shader_instance_uniform ( * r ) ;
return true ;
}
return false ;
}
2020-05-14 14:29:06 +02:00
2020-04-17 04:52:00 +02:00
void GeometryInstance3D : : _get_property_list ( List < PropertyInfo > * p_list ) const {
List < PropertyInfo > pinfo ;
RS : : get_singleton ( ) - > instance_geometry_get_shader_parameter_list ( get_instance ( ) , & pinfo ) ;
2021-07-16 05:45:57 +02:00
for ( PropertyInfo & pi : pinfo ) {
2020-04-17 04:52:00 +02:00
bool has_def_value = false ;
Variant def_value = RS : : get_singleton ( ) - > instance_geometry_get_shader_parameter_default_value ( get_instance ( ) , pi . name ) ;
if ( def_value . get_type ( ) ! = Variant : : NIL ) {
has_def_value = true ;
}
if ( instance_uniforms . has ( pi . name ) ) {
2021-07-01 03:24:34 +02:00
pi . usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE | ( has_def_value ? ( PROPERTY_USAGE_CHECKABLE | PROPERTY_USAGE_CHECKED ) : PROPERTY_USAGE_NONE ) ;
2020-04-17 04:52:00 +02:00
} else {
2021-07-01 03:24:34 +02:00
pi . usage = PROPERTY_USAGE_EDITOR | ( has_def_value ? PROPERTY_USAGE_CHECKABLE : PROPERTY_USAGE_NONE ) ; //do not save if not changed
2020-04-17 04:52:00 +02:00
}
pi . name = " shader_params/ " + pi . name ;
p_list - > push_back ( pi ) ;
}
}
2020-03-26 22:49:16 +01:00
void GeometryInstance3D : : set_cast_shadows_setting ( ShadowCastingSetting p_shadow_casting_setting ) {
2016-03-08 00:00:55 +01:00
shadow_casting_setting = p_shadow_casting_setting ;
2020-03-27 19:21:27 +01:00
RS : : get_singleton ( ) - > instance_geometry_set_cast_shadows_setting ( get_instance ( ) , ( RS : : ShadowCastingSetting ) p_shadow_casting_setting ) ;
2016-03-08 00:00:55 +01:00
}
2020-03-26 22:49:16 +01:00
GeometryInstance3D : : ShadowCastingSetting GeometryInstance3D : : get_cast_shadows_setting ( ) const {
2016-03-08 00:00:55 +01:00
return shadow_casting_setting ;
}
2020-03-26 22:49:16 +01:00
void GeometryInstance3D : : set_extra_cull_margin ( float p_margin ) {
2017-03-05 16:44:50 +01:00
ERR_FAIL_COND ( p_margin < 0 ) ;
extra_cull_margin = p_margin ;
2020-03-27 19:21:27 +01:00
RS : : get_singleton ( ) - > instance_set_extra_visibility_margin ( get_instance ( ) , extra_cull_margin ) ;
2015-03-02 04:54:10 +01:00
}
2020-03-26 22:49:16 +01:00
float GeometryInstance3D : : get_extra_cull_margin ( ) const {
2015-03-02 04:54:10 +01:00
return extra_cull_margin ;
}
2014-02-10 02:10:30 +01:00
2020-12-17 19:56:59 +01:00
void GeometryInstance3D : : set_lod_bias ( float p_bias ) {
ERR_FAIL_COND ( p_bias < 0.0 ) ;
lod_bias = p_bias ;
RS : : get_singleton ( ) - > instance_geometry_set_lod_bias ( get_instance ( ) , lod_bias ) ;
}
float GeometryInstance3D : : get_lod_bias ( ) const {
return lod_bias ;
}
2020-04-17 04:52:00 +02:00
void GeometryInstance3D : : set_shader_instance_uniform ( const StringName & p_uniform , const Variant & p_value ) {
if ( p_value . get_type ( ) = = Variant : : NIL ) {
Variant def_value = RS : : get_singleton ( ) - > instance_geometry_get_shader_parameter_default_value ( get_instance ( ) , p_uniform ) ;
RS : : get_singleton ( ) - > instance_geometry_set_shader_parameter ( get_instance ( ) , p_uniform , def_value ) ;
instance_uniforms . erase ( p_value ) ;
} else {
instance_uniforms [ p_uniform ] = p_value ;
2021-07-06 03:40:29 +02:00
if ( p_value . get_type ( ) = = Variant : : OBJECT ) {
RID tex_id = p_value ;
RS : : get_singleton ( ) - > instance_geometry_set_shader_parameter ( get_instance ( ) , p_uniform , tex_id ) ;
} else {
RS : : get_singleton ( ) - > instance_geometry_set_shader_parameter ( get_instance ( ) , p_uniform , p_value ) ;
}
2020-04-17 04:52:00 +02:00
}
}
Variant GeometryInstance3D : : get_shader_instance_uniform ( const StringName & p_uniform ) const {
return RS : : get_singleton ( ) - > instance_geometry_get_shader_parameter ( get_instance ( ) , p_uniform ) ;
}
2020-05-14 14:29:06 +02:00
2020-03-26 22:49:16 +01:00
void GeometryInstance3D : : set_custom_aabb ( AABB aabb ) {
2020-03-27 19:21:27 +01:00
RS : : get_singleton ( ) - > instance_set_custom_aabb ( get_instance ( ) , aabb ) ;
2019-01-31 17:54:00 +01:00
}
2020-05-01 14:34:23 +02:00
void GeometryInstance3D : : set_lightmap_scale ( LightmapScale p_scale ) {
ERR_FAIL_INDEX ( p_scale , LIGHTMAP_SCALE_MAX ) ;
lightmap_scale = p_scale ;
}
GeometryInstance3D : : LightmapScale GeometryInstance3D : : get_lightmap_scale ( ) const {
return lightmap_scale ;
}
void GeometryInstance3D : : set_gi_mode ( GIMode p_mode ) {
switch ( p_mode ) {
case GI_MODE_DISABLED : {
RS : : get_singleton ( ) - > instance_geometry_set_flag ( get_instance ( ) , RS : : INSTANCE_FLAG_USE_BAKED_LIGHT , false ) ;
RS : : get_singleton ( ) - > instance_geometry_set_flag ( get_instance ( ) , RS : : INSTANCE_FLAG_USE_DYNAMIC_GI , false ) ;
} break ;
2021-11-26 17:47:37 +01:00
case GI_MODE_STATIC : {
2020-05-01 14:34:23 +02:00
RS : : get_singleton ( ) - > instance_geometry_set_flag ( get_instance ( ) , RS : : INSTANCE_FLAG_USE_BAKED_LIGHT , true ) ;
RS : : get_singleton ( ) - > instance_geometry_set_flag ( get_instance ( ) , RS : : INSTANCE_FLAG_USE_DYNAMIC_GI , false ) ;
} break ;
case GI_MODE_DYNAMIC : {
RS : : get_singleton ( ) - > instance_geometry_set_flag ( get_instance ( ) , RS : : INSTANCE_FLAG_USE_BAKED_LIGHT , false ) ;
RS : : get_singleton ( ) - > instance_geometry_set_flag ( get_instance ( ) , RS : : INSTANCE_FLAG_USE_DYNAMIC_GI , true ) ;
} break ;
}
gi_mode = p_mode ;
}
GeometryInstance3D : : GIMode GeometryInstance3D : : get_gi_mode ( ) const {
return gi_mode ;
}
2021-04-20 18:40:24 +02:00
void GeometryInstance3D : : set_ignore_occlusion_culling ( bool p_enabled ) {
ignore_occlusion_culling = p_enabled ;
RS : : get_singleton ( ) - > instance_geometry_set_flag ( get_instance ( ) , RS : : INSTANCE_FLAG_IGNORE_OCCLUSION_CULLING , ignore_occlusion_culling ) ;
}
bool GeometryInstance3D : : is_ignoring_occlusion_culling ( ) {
return ignore_occlusion_culling ;
}
2021-07-28 19:33:14 +02:00
TypedArray < String > GeometryInstance3D : : get_configuration_warnings ( ) const {
TypedArray < String > warnings = Node : : get_configuration_warnings ( ) ;
if ( ! Math : : is_zero_approx ( visibility_range_end ) & & visibility_range_end < = visibility_range_begin ) {
2022-03-28 15:24:14 +02:00
warnings . push_back ( RTR ( " The GeometryInstance3D visibility range's End distance is set to a non-zero value, but is lower than the Begin distance. \n This means the GeometryInstance3D will never be visible. \n To resolve this, set the End distance to 0 or to a value greater than the Begin distance. " ) ) ;
2021-07-28 19:33:14 +02:00
}
2021-11-26 21:46:32 +01:00
if ( ( visibility_range_fade_mode = = VISIBILITY_RANGE_FADE_SELF | | visibility_range_fade_mode = = VISIBILITY_RANGE_FADE_DEPENDENCIES ) & & ! Math : : is_zero_approx ( visibility_range_begin ) & & Math : : is_zero_approx ( visibility_range_begin_margin ) ) {
2022-03-28 15:24:14 +02:00
warnings . push_back ( RTR ( " The GeometryInstance3D is configured to fade in smoothly over distance, but the fade transition distance is set to 0. \n To resolve this, increase Visibility Range Begin Margin above 0. " ) ) ;
2021-11-26 21:46:32 +01:00
}
if ( ( visibility_range_fade_mode = = VISIBILITY_RANGE_FADE_SELF | | visibility_range_fade_mode = = VISIBILITY_RANGE_FADE_DEPENDENCIES ) & & ! Math : : is_zero_approx ( visibility_range_end ) & & Math : : is_zero_approx ( visibility_range_end_margin ) ) {
2022-03-28 15:24:14 +02:00
warnings . push_back ( RTR ( " The GeometryInstance3D is configured to fade out smoothly over distance, but the fade transition distance is set to 0. \n To resolve this, increase Visibility Range End Margin above 0. " ) ) ;
2021-11-26 21:46:32 +01:00
}
2021-07-28 19:33:14 +02:00
return warnings ;
}
2020-03-26 22:49:16 +01:00
void GeometryInstance3D : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_material_override " , " material " ) , & GeometryInstance3D : : set_material_override ) ;
ClassDB : : bind_method ( D_METHOD ( " get_material_override " ) , & GeometryInstance3D : : get_material_override ) ;
2014-02-10 02:10:30 +01:00
2021-09-25 20:40:26 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_material_overlay " , " material " ) , & GeometryInstance3D : : set_material_overlay ) ;
ClassDB : : bind_method ( D_METHOD ( " get_material_overlay " ) , & GeometryInstance3D : : get_material_overlay ) ;
2020-03-26 22:49:16 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_cast_shadows_setting " , " shadow_casting_setting " ) , & GeometryInstance3D : : set_cast_shadows_setting ) ;
ClassDB : : bind_method ( D_METHOD ( " get_cast_shadows_setting " ) , & GeometryInstance3D : : get_cast_shadows_setting ) ;
2016-03-08 00:00:55 +01:00
2021-04-20 18:40:24 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_lod_bias " , " bias " ) , & GeometryInstance3D : : set_lod_bias ) ;
ClassDB : : bind_method ( D_METHOD ( " get_lod_bias " ) , & GeometryInstance3D : : get_lod_bias ) ;
2021-07-20 20:17:34 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_transparency " , " transparency " ) , & GeometryInstance3D : : set_transparecy ) ;
ClassDB : : bind_method ( D_METHOD ( " get_transparency " ) , & GeometryInstance3D : : get_transparency ) ;
2021-05-09 18:23:20 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_visibility_range_end_margin " , " distance " ) , & GeometryInstance3D : : set_visibility_range_end_margin ) ;
ClassDB : : bind_method ( D_METHOD ( " get_visibility_range_end_margin " ) , & GeometryInstance3D : : get_visibility_range_end_margin ) ;
2016-10-03 21:33:42 +02:00
2021-05-09 18:23:20 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_visibility_range_end " , " distance " ) , & GeometryInstance3D : : set_visibility_range_end ) ;
ClassDB : : bind_method ( D_METHOD ( " get_visibility_range_end " ) , & GeometryInstance3D : : get_visibility_range_end ) ;
2016-10-03 21:33:42 +02:00
2021-05-09 18:23:20 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_visibility_range_begin_margin " , " distance " ) , & GeometryInstance3D : : set_visibility_range_begin_margin ) ;
ClassDB : : bind_method ( D_METHOD ( " get_visibility_range_begin_margin " ) , & GeometryInstance3D : : get_visibility_range_begin_margin ) ;
2014-02-10 02:10:30 +01:00
2021-05-09 18:23:20 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_visibility_range_begin " , " distance " ) , & GeometryInstance3D : : set_visibility_range_begin ) ;
ClassDB : : bind_method ( D_METHOD ( " get_visibility_range_begin " ) , & GeometryInstance3D : : get_visibility_range_begin ) ;
2014-02-10 02:10:30 +01:00
2021-07-20 20:17:34 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_visibility_range_fade_mode " , " mode " ) , & GeometryInstance3D : : set_visibility_range_fade_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_visibility_range_fade_mode " ) , & GeometryInstance3D : : get_visibility_range_fade_mode ) ;
2021-04-20 18:40:24 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_shader_instance_uniform " , " uniform " , " value " ) , & GeometryInstance3D : : set_shader_instance_uniform ) ;
ClassDB : : bind_method ( D_METHOD ( " get_shader_instance_uniform " , " uniform " ) , & GeometryInstance3D : : get_shader_instance_uniform ) ;
2020-03-26 22:49:16 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_extra_cull_margin " , " margin " ) , & GeometryInstance3D : : set_extra_cull_margin ) ;
ClassDB : : bind_method ( D_METHOD ( " get_extra_cull_margin " ) , & GeometryInstance3D : : get_extra_cull_margin ) ;
2015-03-02 04:54:10 +01:00
2020-05-01 14:34:23 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_lightmap_scale " , " scale " ) , & GeometryInstance3D : : set_lightmap_scale ) ;
ClassDB : : bind_method ( D_METHOD ( " get_lightmap_scale " ) , & GeometryInstance3D : : get_lightmap_scale ) ;
ClassDB : : bind_method ( D_METHOD ( " set_gi_mode " , " mode " ) , & GeometryInstance3D : : set_gi_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_gi_mode " ) , & GeometryInstance3D : : get_gi_mode ) ;
2021-04-20 18:40:24 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_ignore_occlusion_culling " , " ignore_culling " ) , & GeometryInstance3D : : set_ignore_occlusion_culling ) ;
ClassDB : : bind_method ( D_METHOD ( " is_ignoring_occlusion_culling " ) , & GeometryInstance3D : : is_ignoring_occlusion_culling ) ;
2020-12-17 19:56:59 +01:00
2020-03-26 22:49:16 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_custom_aabb " , " aabb " ) , & GeometryInstance3D : : set_custom_aabb ) ;
2019-01-31 17:54:00 +01:00
2020-03-26 22:49:16 +01:00
ClassDB : : bind_method ( D_METHOD ( " get_aabb " ) , & GeometryInstance3D : : get_aabb ) ;
2016-09-22 23:01:44 +02:00
2017-03-05 16:44:50 +01:00
ADD_GROUP ( " Geometry " , " " ) ;
2021-07-04 17:49:36 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : OBJECT , " material_override " , PROPERTY_HINT_RESOURCE_TYPE , " BaseMaterial3D,ShaderMaterial " , PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DEFERRED_SET_RESOURCE ) , " set_material_override " , " get_material_override " ) ;
2021-09-25 20:40:26 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : OBJECT , " material_overlay " , PROPERTY_HINT_RESOURCE_TYPE , " BaseMaterial3D,ShaderMaterial " , PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DEFERRED_SET_RESOURCE ) , " set_material_overlay " , " get_material_overlay " ) ;
2021-07-20 20:17:34 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " transparency " , PROPERTY_HINT_RANGE , " 0.0,1.0,0.01 " ) , " set_transparency " , " get_transparency " ) ;
2017-02-12 01:11:37 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " cast_shadow " , PROPERTY_HINT_ENUM , " Off,On,Double-Sided,Shadows Only " ) , " set_cast_shadows_setting " , " get_cast_shadows_setting " ) ;
2021-12-03 01:09:19 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " extra_cull_margin " , PROPERTY_HINT_RANGE , " 0,16384,0.01,suffix:m " ) , " set_extra_cull_margin " , " get_extra_cull_margin " ) ;
2020-12-17 19:56:59 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " lod_bias " , PROPERTY_HINT_RANGE , " 0.001,128,0.001 " ) , " set_lod_bias " , " get_lod_bias " ) ;
2021-04-20 18:40:24 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " ignore_occlusion_culling " ) , " set_ignore_occlusion_culling " , " is_ignoring_occlusion_culling " ) ;
2022-02-18 22:19:33 +01:00
2020-05-01 14:34:23 +02:00
ADD_GROUP ( " Global Illumination " , " gi_ " ) ;
2021-11-26 17:47:37 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " gi_mode " , PROPERTY_HINT_ENUM , " Disabled,Static (VoxelGI/SDFGI/LightmapGI),Dynamic (VoxelGI only) " ) , " set_gi_mode " , " get_gi_mode " ) ;
2021-08-12 21:45:33 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " gi_lightmap_scale " , PROPERTY_HINT_ENUM , String : : utf8 ( " 1× ,2× ,4× ,8× " ) ) , " set_lightmap_scale " , " get_lightmap_scale " ) ;
2017-03-05 16:44:50 +01:00
2021-05-09 18:23:20 +02:00
ADD_GROUP ( " Visibility Range " , " visibility_range_ " ) ;
2022-02-18 22:19:33 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " visibility_range_begin " , PROPERTY_HINT_RANGE , " 0.0,4096.0,0.01,or_greater,suffix:m " ) , " set_visibility_range_begin " , " get_visibility_range_begin " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " visibility_range_begin_margin " , PROPERTY_HINT_RANGE , " 0.0,4096.0,0.01,or_greater,suffix:m " ) , " set_visibility_range_begin_margin " , " get_visibility_range_begin_margin " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " visibility_range_end " , PROPERTY_HINT_RANGE , " 0.0,4096.0,0.01,or_greater,suffix:m " ) , " set_visibility_range_end " , " get_visibility_range_end " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : FLOAT , " visibility_range_end_margin " , PROPERTY_HINT_RANGE , " 0.0,4096.0,0.01,or_greater,suffix:m " ) , " set_visibility_range_end_margin " , " get_visibility_range_end_margin " ) ;
2021-07-20 20:17:34 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " visibility_range_fade_mode " , PROPERTY_HINT_ENUM , " Disabled,Self,Dependencies " ) , " set_visibility_range_fade_mode " , " get_visibility_range_fade_mode " ) ;
2014-02-10 02:10:30 +01:00
2017-09-12 21:09:06 +02:00
BIND_ENUM_CONSTANT ( SHADOW_CASTING_SETTING_OFF ) ;
BIND_ENUM_CONSTANT ( SHADOW_CASTING_SETTING_ON ) ;
BIND_ENUM_CONSTANT ( SHADOW_CASTING_SETTING_DOUBLE_SIDED ) ;
BIND_ENUM_CONSTANT ( SHADOW_CASTING_SETTING_SHADOWS_ONLY ) ;
2014-02-10 02:10:30 +01:00
2020-05-01 14:34:23 +02:00
BIND_ENUM_CONSTANT ( GI_MODE_DISABLED ) ;
2021-11-26 17:47:37 +01:00
BIND_ENUM_CONSTANT ( GI_MODE_STATIC ) ;
2020-05-01 14:34:23 +02:00
BIND_ENUM_CONSTANT ( GI_MODE_DYNAMIC ) ;
BIND_ENUM_CONSTANT ( LIGHTMAP_SCALE_1X ) ;
BIND_ENUM_CONSTANT ( LIGHTMAP_SCALE_2X ) ;
BIND_ENUM_CONSTANT ( LIGHTMAP_SCALE_4X ) ;
BIND_ENUM_CONSTANT ( LIGHTMAP_SCALE_8X ) ;
BIND_ENUM_CONSTANT ( LIGHTMAP_SCALE_MAX ) ;
2021-07-20 20:17:34 +02:00
BIND_ENUM_CONSTANT ( VISIBILITY_RANGE_FADE_DISABLED ) ;
BIND_ENUM_CONSTANT ( VISIBILITY_RANGE_FADE_SELF ) ;
BIND_ENUM_CONSTANT ( VISIBILITY_RANGE_FADE_DEPENDENCIES ) ;
2014-02-10 02:10:30 +01:00
}
2020-03-26 22:49:16 +01:00
GeometryInstance3D : : GeometryInstance3D ( ) {
2014-02-10 02:10:30 +01:00
}
2022-05-26 08:12:20 +02:00
GeometryInstance3D : : ~ GeometryInstance3D ( ) {
if ( material_overlay . is_valid ( ) ) {
set_material_overlay ( Ref < Material > ( ) ) ;
}
if ( material_override . is_valid ( ) ) {
set_material_override ( Ref < Material > ( ) ) ;
}
}