2014-02-10 02:10:30 +01:00
/*************************************************************************/
/* material.cpp */
/*************************************************************************/
/* 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-13 09:45:09 +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
2014-02-10 02:10:30 +01:00
# include "material.h"
2017-08-26 17:46:49 +02:00
2020-01-02 17:19:14 +01:00
# include "core/engine.h"
2020-10-04 00:29:00 +02:00
# include "core/project_settings.h"
2021-08-16 18:46:55 +02:00
# include "core/version.h"
2020-01-02 17:19:14 +01:00
2018-12-18 02:53:54 +01:00
# ifdef TOOLS_ENABLED
# include "editor/editor_settings.h"
# endif
2014-02-10 02:10:30 +01:00
# include "scene/scene_string_names.h"
2017-07-08 17:34:05 +02:00
void Material : : set_next_pass ( const Ref < Material > & p_pass ) {
2021-05-04 16:00:45 +02:00
for ( Ref < Material > pass_child = p_pass ; pass_child ! = nullptr ; pass_child = pass_child - > get_next_pass ( ) ) {
2019-08-08 22:11:48 +02:00
ERR_FAIL_COND_MSG ( pass_child = = this , " Can't set as next_pass one of its parents to prevent crashes due to recursive loop. " ) ;
2019-05-03 13:39:46 +02:00
}
2018-08-19 18:40:34 +02:00
2021-05-05 12:44:11 +02:00
if ( next_pass = = p_pass ) {
2017-07-08 17:34:05 +02:00
return ;
2021-05-05 12:44:11 +02:00
}
2017-07-08 17:34:05 +02:00
next_pass = p_pass ;
RID next_pass_rid ;
2021-05-05 12:44:11 +02:00
if ( next_pass . is_valid ( ) ) {
2017-07-08 17:34:05 +02:00
next_pass_rid = next_pass - > get_rid ( ) ;
2021-05-05 12:44:11 +02:00
}
2017-07-08 17:34:05 +02:00
VS : : get_singleton ( ) - > material_set_next_pass ( material , next_pass_rid ) ;
}
Ref < Material > Material : : get_next_pass ( ) const {
return next_pass ;
}
2017-09-01 17:56:52 +02:00
void Material : : set_render_priority ( int p_priority ) {
ERR_FAIL_COND ( p_priority < RENDER_PRIORITY_MIN ) ;
ERR_FAIL_COND ( p_priority > RENDER_PRIORITY_MAX ) ;
render_priority = p_priority ;
VS : : get_singleton ( ) - > material_set_render_priority ( material , p_priority ) ;
}
int Material : : get_render_priority ( ) const {
return render_priority ;
}
2014-02-10 02:10:30 +01:00
RID Material : : get_rid ( ) const {
return material ;
}
2017-09-06 01:40:50 +02:00
void Material : : _validate_property ( PropertyInfo & property ) const {
2017-09-11 13:12:05 +02:00
if ( ! _can_do_next_pass ( ) & & property . name = = " next_pass " ) {
property . usage = 0 ;
2017-09-06 01:40:50 +02:00
}
}
2014-02-10 02:10:30 +01:00
2017-07-08 17:34:05 +02:00
void Material : : _bind_methods ( ) {
2017-08-09 13:19:41 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_next_pass " , " next_pass " ) , & Material : : set_next_pass ) ;
ClassDB : : bind_method ( D_METHOD ( " get_next_pass " ) , & Material : : get_next_pass ) ;
2017-07-08 17:34:05 +02:00
2017-09-01 17:56:52 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_render_priority " , " priority " ) , & Material : : set_render_priority ) ;
ClassDB : : bind_method ( D_METHOD ( " get_render_priority " ) , & Material : : get_render_priority ) ;
2017-09-11 13:12:05 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " render_priority " , PROPERTY_HINT_RANGE , itos ( RENDER_PRIORITY_MIN ) + " , " + itos ( RENDER_PRIORITY_MAX ) + " ,1 " ) , " set_render_priority " , " get_render_priority " ) ;
2017-07-08 17:34:05 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : OBJECT , " next_pass " , PROPERTY_HINT_RESOURCE_TYPE , " Material " ) , " set_next_pass " , " get_next_pass " ) ;
2017-09-01 17:56:52 +02:00
BIND_CONSTANT ( RENDER_PRIORITY_MAX ) ;
BIND_CONSTANT ( RENDER_PRIORITY_MIN ) ;
2017-07-08 17:34:05 +02:00
}
2016-10-03 21:33:42 +02:00
Material : : Material ( ) {
2021-11-09 13:00:07 +01:00
material = RID_PRIME ( VisualServer : : get_singleton ( ) - > material_create ( ) ) ;
2017-09-01 17:56:52 +02:00
render_priority = 0 ;
2014-02-10 02:10:30 +01:00
}
Material : : ~ Material ( ) {
VisualServer : : get_singleton ( ) - > free ( material ) ;
}
2017-04-07 04:36:37 +02:00
///////////////////////////////////
bool ShaderMaterial : : _set ( const StringName & p_name , const Variant & p_value ) {
2018-01-11 23:35:12 +01:00
if ( shader . is_valid ( ) ) {
StringName pr = shader - > remap_param ( p_name ) ;
if ( ! pr ) {
String n = p_name ;
if ( n . find ( " param/ " ) = = 0 ) { //backwards compatibility
pr = n . substr ( 6 , n . length ( ) ) ;
2017-04-07 04:36:37 +02:00
}
2019-02-23 21:52:49 +01:00
if ( n . find ( " shader_param/ " ) = = 0 ) { //backwards compatibility
pr = n . replace_first ( " shader_param/ " , " " ) ;
}
2017-04-07 04:36:37 +02:00
}
2018-01-11 23:35:12 +01:00
if ( pr ) {
VisualServer : : get_singleton ( ) - > material_set_param ( _get_material ( ) , pr , p_value ) ;
return true ;
}
2017-04-07 04:36:37 +02:00
}
return false ;
}
bool ShaderMaterial : : _get ( const StringName & p_name , Variant & r_ret ) const {
2018-01-11 23:35:12 +01:00
if ( shader . is_valid ( ) ) {
StringName pr = shader - > remap_param ( p_name ) ;
2019-02-23 21:52:49 +01:00
if ( ! pr ) {
String n = p_name ;
if ( n . find ( " param/ " ) = = 0 ) { //backwards compatibility
pr = n . substr ( 6 , n . length ( ) ) ;
}
if ( n . find ( " shader_param/ " ) = = 0 ) { //backwards compatibility
pr = n . replace_first ( " shader_param/ " , " " ) ;
}
}
2018-01-11 23:35:12 +01:00
if ( pr ) {
r_ret = VisualServer : : get_singleton ( ) - > material_get_param ( _get_material ( ) , pr ) ;
return true ;
2017-04-07 04:36:37 +02:00
}
}
return false ;
}
void ShaderMaterial : : _get_property_list ( List < PropertyInfo > * p_list ) const {
if ( ! shader . is_null ( ) ) {
shader - > get_param_list ( p_list ) ;
}
}
2018-09-05 00:54:35 +02:00
bool ShaderMaterial : : property_can_revert ( const String & p_name ) {
if ( shader . is_valid ( ) ) {
StringName pr = shader - > remap_param ( p_name ) ;
if ( pr ) {
Variant default_value = VisualServer : : get_singleton ( ) - > material_get_param_default ( _get_material ( ) , pr ) ;
Variant current_value ;
_get ( p_name , current_value ) ;
return default_value . get_type ( ) ! = Variant : : NIL & & default_value ! = current_value ;
}
}
return false ;
}
Variant ShaderMaterial : : property_get_revert ( const String & p_name ) {
Variant r_ret ;
if ( shader . is_valid ( ) ) {
StringName pr = shader - > remap_param ( p_name ) ;
if ( pr ) {
r_ret = VisualServer : : get_singleton ( ) - > material_get_param_default ( _get_material ( ) , pr ) ;
}
}
return r_ret ;
}
2017-04-07 04:36:37 +02:00
void ShaderMaterial : : set_shader ( const Ref < Shader > & p_shader ) {
2020-01-02 17:19:14 +01:00
// Only connect/disconnect the signal when running in the editor.
// This can be a slow operation, and `_change_notify()` (which is called by `_shader_changed()`)
// does nothing in non-editor builds anyway. See GH-34741 for details.
if ( shader . is_valid ( ) & & Engine : : get_singleton ( ) - > is_editor_hint ( ) ) {
2018-07-14 23:15:42 +02:00
shader - > disconnect ( " changed " , this , " _shader_changed " ) ;
}
2017-04-07 04:36:37 +02:00
shader = p_shader ;
RID rid ;
2018-07-14 23:15:42 +02:00
if ( shader . is_valid ( ) ) {
2017-04-07 04:36:37 +02:00
rid = shader - > get_rid ( ) ;
2020-01-02 17:19:14 +01:00
if ( Engine : : get_singleton ( ) - > is_editor_hint ( ) ) {
shader - > connect ( " changed " , this , " _shader_changed " ) ;
}
2018-07-14 23:15:42 +02:00
}
2017-04-07 04:36:37 +02:00
VS : : get_singleton ( ) - > material_set_shader ( _get_material ( ) , rid ) ;
_change_notify ( ) ; //properties for shader exposed
emit_changed ( ) ;
}
Ref < Shader > ShaderMaterial : : get_shader ( ) const {
return shader ;
}
void ShaderMaterial : : set_shader_param ( const StringName & p_param , const Variant & p_value ) {
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , p_param , p_value ) ;
}
Variant ShaderMaterial : : get_shader_param ( const StringName & p_param ) const {
return VS : : get_singleton ( ) - > material_get_param ( _get_material ( ) , p_param ) ;
}
2018-07-14 23:15:42 +02:00
void ShaderMaterial : : _shader_changed ( ) {
_change_notify ( ) ; //update all properties
}
2017-04-07 04:36:37 +02:00
void ShaderMaterial : : _bind_methods ( ) {
2017-08-09 13:19:41 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_shader " , " shader " ) , & ShaderMaterial : : set_shader ) ;
ClassDB : : bind_method ( D_METHOD ( " get_shader " ) , & ShaderMaterial : : get_shader ) ;
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_shader_param " , " param " , " value " ) , & ShaderMaterial : : set_shader_param ) ;
2017-08-09 13:19:41 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_shader_param " , " param " ) , & ShaderMaterial : : get_shader_param ) ;
2018-07-14 23:15:42 +02:00
ClassDB : : bind_method ( D_METHOD ( " _shader_changed " ) , & ShaderMaterial : : _shader_changed ) ;
2018-09-05 00:54:35 +02:00
ClassDB : : bind_method ( D_METHOD ( " property_can_revert " , " name " ) , & ShaderMaterial : : property_can_revert ) ;
ClassDB : : bind_method ( D_METHOD ( " property_get_revert " , " name " ) , & ShaderMaterial : : property_get_revert ) ;
2018-01-11 23:35:12 +01:00
2018-01-12 16:37:00 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : OBJECT , " shader " , PROPERTY_HINT_RESOURCE_TYPE , " Shader " ) , " set_shader " , " get_shader " ) ;
2017-04-07 04:36:37 +02:00
}
void ShaderMaterial : : get_argument_options ( const StringName & p_function , int p_idx , List < String > * r_options ) const {
2018-12-18 02:53:54 +01:00
# ifdef TOOLS_ENABLED
2022-04-27 09:26:46 +02:00
const String quote_style = EDITOR_GET ( " text_editor/completion/use_single_quotes " ) ? " ' " : " \" " ;
2018-12-18 02:53:54 +01:00
# else
const String quote_style = " \" " ;
# endif
2017-04-07 04:36:37 +02:00
String f = p_function . operator String ( ) ;
if ( ( f = = " get_shader_param " | | f = = " set_shader_param " ) & & p_idx = = 0 ) {
if ( shader . is_valid ( ) ) {
List < PropertyInfo > pl ;
shader - > get_param_list ( & pl ) ;
for ( List < PropertyInfo > : : Element * E = pl . front ( ) ; E ; E = E - > next ( ) ) {
2018-12-18 02:53:54 +01:00
r_options - > push_back ( quote_style + E - > get ( ) . name . replace_first ( " shader_param/ " , " " ) + quote_style ) ;
2017-04-07 04:36:37 +02:00
}
}
}
Resource : : get_argument_options ( p_function , p_idx , r_options ) ;
}
2017-09-06 01:40:50 +02:00
bool ShaderMaterial : : _can_do_next_pass ( ) const {
2017-09-11 13:12:05 +02:00
return shader . is_valid ( ) & & shader - > get_mode ( ) = = Shader : : MODE_SPATIAL ;
2017-09-06 01:40:50 +02:00
}
2017-12-06 23:43:22 +01:00
Shader : : Mode ShaderMaterial : : get_shader_mode ( ) const {
2021-05-05 12:44:11 +02:00
if ( shader . is_valid ( ) ) {
2017-12-06 23:43:22 +01:00
return shader - > get_mode ( ) ;
2021-05-05 12:44:11 +02:00
} else {
2017-12-06 23:43:22 +01:00
return Shader : : MODE_SPATIAL ;
2021-05-05 12:44:11 +02:00
}
2017-12-06 23:43:22 +01:00
}
2017-04-07 04:36:37 +02:00
ShaderMaterial : : ShaderMaterial ( ) {
}
ShaderMaterial : : ~ ShaderMaterial ( ) {
}
2016-10-27 16:50:26 +02:00
/////////////////////////////////
2021-01-27 10:43:02 +01:00
Mutex SpatialMaterial : : material_mutex ;
2021-05-04 16:00:45 +02:00
SelfList < SpatialMaterial > : : List * SpatialMaterial : : dirty_materials = nullptr ;
2017-04-07 04:36:37 +02:00
Map < SpatialMaterial : : MaterialKey , SpatialMaterial : : ShaderData > SpatialMaterial : : shader_map ;
2021-05-04 16:00:45 +02:00
SpatialMaterial : : ShaderNames * SpatialMaterial : : shader_names = nullptr ;
2016-10-27 16:50:26 +02:00
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : init_shaders ( ) {
2018-11-21 16:48:05 +01:00
dirty_materials = memnew ( SelfList < SpatialMaterial > : : List ) ;
2017-03-05 16:44:50 +01:00
shader_names = memnew ( ShaderNames ) ;
shader_names - > albedo = " albedo " ;
shader_names - > specular = " specular " ;
shader_names - > roughness = " roughness " ;
2017-06-01 01:16:38 +02:00
shader_names - > metallic = " metallic " ;
2017-03-05 16:44:50 +01:00
shader_names - > emission = " emission " ;
shader_names - > emission_energy = " emission_energy " ;
shader_names - > normal_scale = " normal_scale " ;
shader_names - > rim = " rim " ;
shader_names - > rim_tint = " rim_tint " ;
shader_names - > clearcoat = " clearcoat " ;
shader_names - > clearcoat_gloss = " clearcoat_gloss " ;
shader_names - > anisotropy = " anisotropy_ratio " ;
2017-06-04 23:08:06 +02:00
shader_names - > depth_scale = " depth_scale " ;
2017-03-05 16:44:50 +01:00
shader_names - > subsurface_scattering_strength = " subsurface_scattering_strength " ;
2017-09-03 15:29:56 +02:00
shader_names - > transmission = " transmission " ;
2017-03-05 16:44:50 +01:00
shader_names - > refraction = " refraction " ;
shader_names - > point_size = " point_size " ;
shader_names - > uv1_scale = " uv1_scale " ;
shader_names - > uv1_offset = " uv1_offset " ;
shader_names - > uv2_scale = " uv2_scale " ;
shader_names - > uv2_offset = " uv2_offset " ;
2017-07-08 13:06:13 +02:00
shader_names - > uv1_blend_sharpness = " uv1_blend_sharpness " ;
shader_names - > uv2_blend_sharpness = " uv2_blend_sharpness " ;
2017-03-05 16:44:50 +01:00
2017-08-17 15:49:17 +02:00
shader_names - > particles_anim_h_frames = " particles_anim_h_frames " ;
shader_names - > particles_anim_v_frames = " particles_anim_v_frames " ;
2017-04-07 04:36:37 +02:00
shader_names - > particles_anim_loop = " particles_anim_loop " ;
2017-06-04 23:08:06 +02:00
shader_names - > depth_min_layers = " depth_min_layers " ;
shader_names - > depth_max_layers = " depth_max_layers " ;
2018-11-14 14:15:15 +01:00
shader_names - > depth_flip = " depth_flip " ;
2017-04-07 04:36:37 +02:00
2017-07-08 17:34:05 +02:00
shader_names - > grow = " grow " ;
2017-09-24 04:10:34 +02:00
shader_names - > ao_light_affect = " ao_light_affect " ;
2017-09-21 20:20:00 +02:00
shader_names - > proximity_fade_distance = " proximity_fade_distance " ;
shader_names - > distance_fade_min = " distance_fade_min " ;
shader_names - > distance_fade_max = " distance_fade_max " ;
2017-08-02 20:34:55 +02:00
shader_names - > metallic_texture_channel = " metallic_texture_channel " ;
shader_names - > roughness_texture_channel = " roughness_texture_channel " ;
shader_names - > ao_texture_channel = " ao_texture_channel " ;
shader_names - > clearcoat_texture_channel = " clearcoat_texture_channel " ;
shader_names - > rim_texture_channel = " rim_texture_channel " ;
shader_names - > depth_texture_channel = " depth_texture_channel " ;
shader_names - > refraction_texture_channel = " refraction_texture_channel " ;
2017-08-08 22:23:44 +02:00
shader_names - > alpha_scissor_threshold = " alpha_scissor_threshold " ;
2017-08-02 20:34:55 +02:00
2017-03-05 16:44:50 +01:00
shader_names - > texture_names [ TEXTURE_ALBEDO ] = " texture_albedo " ;
2017-06-01 01:16:38 +02:00
shader_names - > texture_names [ TEXTURE_METALLIC ] = " texture_metallic " ;
shader_names - > texture_names [ TEXTURE_ROUGHNESS ] = " texture_roughness " ;
2017-03-05 16:44:50 +01:00
shader_names - > texture_names [ TEXTURE_EMISSION ] = " texture_emission " ;
shader_names - > texture_names [ TEXTURE_NORMAL ] = " texture_normal " ;
shader_names - > texture_names [ TEXTURE_RIM ] = " texture_rim " ;
shader_names - > texture_names [ TEXTURE_CLEARCOAT ] = " texture_clearcoat " ;
shader_names - > texture_names [ TEXTURE_FLOWMAP ] = " texture_flowmap " ;
shader_names - > texture_names [ TEXTURE_AMBIENT_OCCLUSION ] = " texture_ambient_occlusion " ;
2017-06-04 23:08:06 +02:00
shader_names - > texture_names [ TEXTURE_DEPTH ] = " texture_depth " ;
2017-03-05 16:44:50 +01:00
shader_names - > texture_names [ TEXTURE_SUBSURFACE_SCATTERING ] = " texture_subsurface_scattering " ;
2017-09-03 15:29:56 +02:00
shader_names - > texture_names [ TEXTURE_TRANSMISSION ] = " texture_transmission " ;
2017-03-05 16:44:50 +01:00
shader_names - > texture_names [ TEXTURE_REFRACTION ] = " texture_refraction " ;
shader_names - > texture_names [ TEXTURE_DETAIL_MASK ] = " texture_detail_mask " ;
shader_names - > texture_names [ TEXTURE_DETAIL_ALBEDO ] = " texture_detail_albedo " ;
shader_names - > texture_names [ TEXTURE_DETAIL_NORMAL ] = " texture_detail_normal " ;
}
2022-05-21 19:12:12 +02:00
HashMap < uint64_t , Ref < SpatialMaterial > > SpatialMaterial : : materials_for_2d ;
2017-08-08 22:23:44 +02:00
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : finish_shaders ( ) {
2022-05-21 19:12:12 +02:00
materials_for_2d . clear ( ) ;
2017-08-08 22:23:44 +02:00
2018-11-21 16:48:05 +01:00
memdelete ( dirty_materials ) ;
2021-05-04 16:00:45 +02:00
dirty_materials = nullptr ;
2018-11-21 16:48:05 +01:00
2017-03-05 16:44:50 +01:00
memdelete ( shader_names ) ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : _update_shader ( ) {
2018-11-21 16:48:05 +01:00
dirty_materials - > remove ( & element ) ;
2016-10-27 16:50:26 +02:00
MaterialKey mk = _compute_key ( ) ;
2021-05-05 12:44:11 +02:00
if ( mk . key = = current_key . key ) {
2016-10-27 16:50:26 +02:00
return ; //no update required in the end
2021-05-05 12:44:11 +02:00
}
2016-10-27 16:50:26 +02:00
if ( shader_map . has ( current_key ) ) {
shader_map [ current_key ] . users - - ;
2017-03-05 16:44:50 +01:00
if ( shader_map [ current_key ] . users = = 0 ) {
2016-10-27 16:50:26 +02:00
//deallocate shader, as it's no longer in use
VS : : get_singleton ( ) - > free ( shader_map [ current_key ] . shader ) ;
shader_map . erase ( current_key ) ;
}
}
2017-03-05 16:44:50 +01:00
current_key = mk ;
2016-10-27 16:50:26 +02:00
if ( shader_map . has ( mk ) ) {
2017-03-05 16:44:50 +01:00
VS : : get_singleton ( ) - > material_set_shader ( _get_material ( ) , shader_map [ mk ] . shader ) ;
2016-10-27 16:50:26 +02:00
shader_map [ mk ] . users + + ;
return ;
}
//must create a shader!
2021-08-16 18:46:55 +02:00
// Add a comment to describe the shader origin (useful when converting to ShaderMaterial).
String code = " // NOTE: Shader automatically converted from " VERSION_NAME " " VERSION_FULL_CONFIG " 's SpatialMaterial. \n \n " ;
code + = " shader_type spatial; \n render_mode " ;
2017-03-05 16:44:50 +01:00
switch ( blend_mode ) {
2021-05-04 14:35:44 +02:00
case BLEND_MODE_MIX :
code + = " blend_mix " ;
break ;
case BLEND_MODE_ADD :
code + = " blend_add " ;
break ;
case BLEND_MODE_SUB :
code + = " blend_sub " ;
break ;
case BLEND_MODE_MUL :
code + = " blend_mul " ;
break ;
2016-10-27 16:50:26 +02:00
}
2017-06-06 03:33:01 +02:00
DepthDrawMode ddm = depth_draw_mode ;
if ( features [ FEATURE_REFRACTION ] ) {
ddm = DEPTH_DRAW_ALWAYS ;
}
switch ( ddm ) {
2021-05-04 14:35:44 +02:00
case DEPTH_DRAW_OPAQUE_ONLY :
code + = " ,depth_draw_opaque " ;
break ;
case DEPTH_DRAW_ALWAYS :
code + = " ,depth_draw_always " ;
break ;
case DEPTH_DRAW_DISABLED :
code + = " ,depth_draw_never " ;
break ;
case DEPTH_DRAW_ALPHA_OPAQUE_PREPASS :
code + = " ,depth_draw_alpha_prepass " ;
break ;
2016-10-27 16:50:26 +02:00
}
2017-03-05 16:44:50 +01:00
switch ( cull_mode ) {
2021-05-04 14:35:44 +02:00
case CULL_BACK :
code + = " ,cull_back " ;
break ;
case CULL_FRONT :
code + = " ,cull_front " ;
break ;
case CULL_DISABLED :
code + = " ,cull_disabled " ;
break ;
2016-10-27 16:50:26 +02:00
}
2017-06-01 23:55:24 +02:00
switch ( diffuse_mode ) {
2021-05-04 14:35:44 +02:00
case DIFFUSE_BURLEY :
code + = " ,diffuse_burley " ;
break ;
case DIFFUSE_LAMBERT :
code + = " ,diffuse_lambert " ;
break ;
case DIFFUSE_LAMBERT_WRAP :
code + = " ,diffuse_lambert_wrap " ;
break ;
case DIFFUSE_OREN_NAYAR :
code + = " ,diffuse_oren_nayar " ;
break ;
case DIFFUSE_TOON :
code + = " ,diffuse_toon " ;
break ;
2017-07-08 17:34:05 +02:00
}
switch ( specular_mode ) {
2021-05-04 14:35:44 +02:00
case SPECULAR_SCHLICK_GGX :
code + = " ,specular_schlick_ggx " ;
break ;
case SPECULAR_BLINN :
code + = " ,specular_blinn " ;
break ;
case SPECULAR_PHONG :
code + = " ,specular_phong " ;
break ;
case SPECULAR_TOON :
code + = " ,specular_toon " ;
break ;
case SPECULAR_DISABLED :
code + = " ,specular_disabled " ;
break ;
2017-06-01 23:55:24 +02:00
}
2016-10-27 16:50:26 +02:00
if ( flags [ FLAG_UNSHADED ] ) {
2017-03-05 16:44:50 +01:00
code + = " ,unshaded " ;
2016-10-27 16:50:26 +02:00
}
2017-09-01 17:56:52 +02:00
if ( flags [ FLAG_DISABLE_DEPTH_TEST ] ) {
code + = " ,depth_test_disable " ;
2016-10-27 16:50:26 +02:00
}
2020-10-04 00:29:00 +02:00
if ( flags [ FLAG_USE_VERTEX_LIGHTING ] | | force_vertex_shading ) {
2017-07-22 19:07:38 +02:00
code + = " ,vertex_lighting " ;
}
2017-09-02 14:56:12 +02:00
if ( flags [ FLAG_TRIPLANAR_USE_WORLD ] & & ( flags [ FLAG_UV1_USE_TRIPLANAR ] | | flags [ FLAG_UV2_USE_TRIPLANAR ] ) ) {
2017-07-08 13:06:13 +02:00
code + = " ,world_vertex_coords " ;
}
2018-03-29 18:46:42 +02:00
if ( flags [ FLAG_DONT_RECEIVE_SHADOWS ] ) {
code + = " ,shadows_disabled " ;
}
2018-07-17 21:30:43 +02:00
if ( flags [ FLAG_DISABLE_AMBIENT_LIGHT ] ) {
code + = " ,ambient_light_disabled " ;
}
2018-06-21 00:12:12 +02:00
if ( flags [ FLAG_ENSURE_CORRECT_NORMALS ] ) {
code + = " ,ensure_correct_normals " ;
}
2019-05-20 16:37:13 +02:00
if ( flags [ FLAG_USE_SHADOW_TO_OPACITY ] ) {
code + = " ,shadow_to_opacity " ;
}
2017-03-05 16:44:50 +01:00
code + = " ; \n " ;
2016-10-27 16:50:26 +02:00
2017-03-05 16:44:50 +01:00
code + = " uniform vec4 albedo : hint_color; \n " ;
2019-11-03 01:42:36 +01:00
code + = " uniform sampler2D texture_albedo : hint_albedo; \n " ;
2017-06-01 01:16:38 +02:00
code + = " uniform float specular; \n " ;
code + = " uniform float metallic; \n " ;
2017-07-08 17:34:05 +02:00
if ( grow_enabled ) {
code + = " uniform float grow; \n " ;
}
2017-01-02 04:01:55 +01:00
2017-09-21 20:20:00 +02:00
if ( proximity_fade_enabled ) {
code + = " uniform float proximity_fade_distance; \n " ;
}
2018-08-22 15:23:28 +02:00
if ( distance_fade ! = DISTANCE_FADE_DISABLED ) {
2017-09-21 20:20:00 +02:00
code + = " uniform float distance_fade_min; \n " ;
code + = " uniform float distance_fade_max; \n " ;
}
2017-08-08 22:23:44 +02:00
if ( flags [ FLAG_USE_ALPHA_SCISSOR ] ) {
code + = " uniform float alpha_scissor_threshold; \n " ;
}
2017-03-05 16:44:50 +01:00
code + = " uniform float roughness : hint_range(0,1); \n " ;
code + = " uniform float point_size : hint_range(0,128); \n " ;
2019-10-27 00:28:54 +02:00
2021-05-04 16:00:45 +02:00
if ( textures [ TEXTURE_METALLIC ] ! = nullptr ) {
2019-10-27 00:28:54 +02:00
code + = " uniform sampler2D texture_metallic : hint_white; \n " ;
code + = " uniform vec4 metallic_texture_channel; \n " ;
}
2021-05-04 16:00:45 +02:00
if ( textures [ TEXTURE_ROUGHNESS ] ! = nullptr ) {
2019-10-27 00:28:54 +02:00
code + = " uniform sampler2D texture_roughness : hint_white; \n " ;
code + = " uniform vec4 roughness_texture_channel; \n " ;
}
2017-04-07 04:36:37 +02:00
if ( billboard_mode = = BILLBOARD_PARTICLES ) {
code + = " uniform int particles_anim_h_frames; \n " ;
code + = " uniform int particles_anim_v_frames; \n " ;
code + = " uniform bool particles_anim_loop; \n " ;
}
2016-11-21 02:49:53 +01:00
if ( features [ FEATURE_EMISSION ] ) {
2017-03-05 16:44:50 +01:00
code + = " uniform sampler2D texture_emission : hint_black_albedo; \n " ;
code + = " uniform vec4 emission : hint_color; \n " ;
code + = " uniform float emission_energy; \n " ;
2016-11-21 02:49:53 +01:00
}
2017-06-06 03:33:01 +02:00
if ( features [ FEATURE_REFRACTION ] ) {
code + = " uniform sampler2D texture_refraction; \n " ;
code + = " uniform float refraction : hint_range(-16,16); \n " ;
2017-08-02 20:34:55 +02:00
code + = " uniform vec4 refraction_texture_channel; \n " ;
2017-06-06 03:33:01 +02:00
}
2016-11-21 02:49:53 +01:00
if ( features [ FEATURE_NORMAL_MAPPING ] ) {
2017-03-05 16:44:50 +01:00
code + = " uniform sampler2D texture_normal : hint_normal; \n " ;
code + = " uniform float normal_scale : hint_range(-16,16); \n " ;
2016-11-21 02:49:53 +01:00
}
if ( features [ FEATURE_RIM ] ) {
2017-03-05 16:44:50 +01:00
code + = " uniform float rim : hint_range(0,1); \n " ;
code + = " uniform float rim_tint : hint_range(0,1); \n " ;
code + = " uniform sampler2D texture_rim : hint_white; \n " ;
2016-11-21 02:49:53 +01:00
}
if ( features [ FEATURE_CLEARCOAT ] ) {
2017-03-05 16:44:50 +01:00
code + = " uniform float clearcoat : hint_range(0,1); \n " ;
code + = " uniform float clearcoat_gloss : hint_range(0,1); \n " ;
code + = " uniform sampler2D texture_clearcoat : hint_white; \n " ;
2016-11-21 02:49:53 +01:00
}
if ( features [ FEATURE_ANISOTROPY ] ) {
2017-03-05 16:44:50 +01:00
code + = " uniform float anisotropy_ratio : hint_range(0,256); \n " ;
code + = " uniform sampler2D texture_flowmap : hint_aniso; \n " ;
2016-11-21 02:49:53 +01:00
}
if ( features [ FEATURE_AMBIENT_OCCLUSION ] ) {
2017-03-05 16:44:50 +01:00
code + = " uniform sampler2D texture_ambient_occlusion : hint_white; \n " ;
2017-08-02 20:34:55 +02:00
code + = " uniform vec4 ao_texture_channel; \n " ;
2017-09-24 04:10:34 +02:00
code + = " uniform float ao_light_affect; \n " ;
2016-11-21 02:49:53 +01:00
}
if ( features [ FEATURE_DETAIL ] ) {
2017-03-05 16:44:50 +01:00
code + = " uniform sampler2D texture_detail_albedo : hint_albedo; \n " ;
code + = " uniform sampler2D texture_detail_normal : hint_normal; \n " ;
code + = " uniform sampler2D texture_detail_mask : hint_white; \n " ;
2016-11-21 02:49:53 +01:00
}
2016-12-03 02:23:16 +01:00
if ( features [ FEATURE_SUBSURACE_SCATTERING ] ) {
2017-03-05 16:44:50 +01:00
code + = " uniform float subsurface_scattering_strength : hint_range(0,1); \n " ;
code + = " uniform sampler2D texture_subsurface_scattering : hint_white; \n " ;
2016-12-03 02:23:16 +01:00
}
2017-09-03 15:29:56 +02:00
if ( features [ FEATURE_TRANSMISSION ] ) {
code + = " uniform vec4 transmission : hint_color; \n " ;
code + = " uniform sampler2D texture_transmission : hint_black; \n " ;
}
2017-06-04 23:08:06 +02:00
if ( features [ FEATURE_DEPTH_MAPPING ] ) {
code + = " uniform sampler2D texture_depth : hint_black; \n " ;
code + = " uniform float depth_scale; \n " ;
code + = " uniform int depth_min_layers; \n " ;
code + = " uniform int depth_max_layers; \n " ;
2018-11-14 14:15:15 +01:00
code + = " uniform vec2 depth_flip; \n " ;
2017-06-04 23:08:06 +02:00
}
2017-07-08 13:06:13 +02:00
if ( flags [ FLAG_UV1_USE_TRIPLANAR ] ) {
2017-09-02 14:56:12 +02:00
code + = " varying vec3 uv1_triplanar_pos; \n " ;
2017-07-08 13:06:13 +02:00
}
if ( flags [ FLAG_UV2_USE_TRIPLANAR ] ) {
2017-09-02 14:56:12 +02:00
code + = " varying vec3 uv2_triplanar_pos; \n " ;
2017-07-08 13:06:13 +02:00
}
if ( flags [ FLAG_UV1_USE_TRIPLANAR ] ) {
code + = " uniform float uv1_blend_sharpness; \n " ;
code + = " varying vec3 uv1_power_normal; \n " ;
}
if ( flags [ FLAG_UV2_USE_TRIPLANAR ] ) {
code + = " uniform float uv2_blend_sharpness; \n " ;
code + = " varying vec3 uv2_power_normal; \n " ;
}
code + = " uniform vec3 uv1_scale; \n " ;
code + = " uniform vec3 uv1_offset; \n " ;
code + = " uniform vec3 uv2_scale; \n " ;
code + = " uniform vec3 uv2_offset; \n " ;
2017-06-04 23:08:06 +02:00
2017-03-05 16:44:50 +01:00
code + = " \n \n " ;
2016-12-03 02:23:16 +01:00
2017-03-05 16:44:50 +01:00
code + = " void vertex() { \n " ;
2016-10-30 01:48:09 +02:00
if ( flags [ FLAG_SRGB_VERTEX_COLOR ] ) {
2018-09-23 17:12:30 +02:00
code + = " \t if (!OUTPUT_IS_SRGB) { \n " ;
2021-01-29 16:12:50 +01:00
code + = " \t \t COLOR.rgb = mix(pow((COLOR.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), COLOR.rgb * (1.0 / 12.92), lessThan(COLOR.rgb, vec3(0.04045))); \n " ;
2018-09-23 17:12:30 +02:00
code + = " \t } \n " ;
2016-10-30 01:48:09 +02:00
}
if ( flags [ FLAG_USE_POINT_SIZE ] ) {
2017-03-05 16:44:50 +01:00
code + = " \t POINT_SIZE=point_size; \n " ;
2016-10-30 01:48:09 +02:00
}
2017-07-08 13:06:13 +02:00
2020-10-04 00:29:00 +02:00
if ( flags [ FLAG_USE_VERTEX_LIGHTING ] | | force_vertex_shading ) {
2017-07-22 19:07:38 +02:00
code + = " \t ROUGHNESS=roughness; \n " ;
}
2017-07-08 13:06:13 +02:00
if ( ! flags [ FLAG_UV1_USE_TRIPLANAR ] ) {
code + = " \t UV=UV*uv1_scale.xy+uv1_offset.xy; \n " ;
}
2017-04-07 04:36:37 +02:00
switch ( billboard_mode ) {
case BILLBOARD_DISABLED : {
} break ;
case BILLBOARD_ENABLED : {
code + = " \t MODELVIEW_MATRIX = INV_CAMERA_MATRIX * mat4(CAMERA_MATRIX[0],CAMERA_MATRIX[1],CAMERA_MATRIX[2],WORLD_MATRIX[3]); \n " ;
2018-04-22 12:11:05 +02:00
if ( flags [ FLAG_BILLBOARD_KEEP_SCALE ] ) {
2019-02-24 23:55:37 +01:00
code + = " \t MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(length(WORLD_MATRIX[0].xyz), 0.0, 0.0, 0.0),vec4(0.0, length(WORLD_MATRIX[1].xyz), 0.0, 0.0),vec4(0.0, 0.0, length(WORLD_MATRIX[2].xyz), 0.0),vec4(0.0, 0.0, 0.0, 1.0)); \n " ;
2018-04-22 12:11:05 +02:00
}
2017-04-07 04:36:37 +02:00
} break ;
case BILLBOARD_FIXED_Y : {
2021-08-27 13:30:29 +02:00
code + = " \t MODELVIEW_MATRIX = INV_CAMERA_MATRIX * mat4(vec4(normalize(cross(vec3(0.0, 1.0, 0.0), CAMERA_MATRIX[2].xyz)),0.0),vec4(0.0, 1.0, 0.0, 0.0),vec4(normalize(cross(CAMERA_MATRIX[0].xyz, vec3(0.0, 1.0, 0.0))),0.0),WORLD_MATRIX[3]); \n " ;
2018-04-22 12:11:05 +02:00
if ( flags [ FLAG_BILLBOARD_KEEP_SCALE ] ) {
2021-08-27 13:30:29 +02:00
code + = " \t MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(length(WORLD_MATRIX[0].xyz), 0.0, 0.0, 0.0),vec4(0.0, length(WORLD_MATRIX[1].xyz), 0.0, 0.0),vec4(0.0, 0.0, length(WORLD_MATRIX[2].xyz), 0.0),vec4(0.0, 0.0, 0.0, 1.0)); \n " ;
2018-04-22 12:11:05 +02:00
}
2017-04-07 04:36:37 +02:00
} break ;
case BILLBOARD_PARTICLES : {
//make billboard
code + = " \t mat4 mat_world = mat4(normalize(CAMERA_MATRIX[0])*length(WORLD_MATRIX[0]),normalize(CAMERA_MATRIX[1])*length(WORLD_MATRIX[0]),normalize(CAMERA_MATRIX[2])*length(WORLD_MATRIX[2]),WORLD_MATRIX[3]); \n " ;
//rotate by rotation
2019-02-24 23:55:37 +01:00
code + = " \t mat_world = mat_world * mat4( vec4(cos(INSTANCE_CUSTOM.x),-sin(INSTANCE_CUSTOM.x), 0.0, 0.0), vec4(sin(INSTANCE_CUSTOM.x), cos(INSTANCE_CUSTOM.x), 0.0, 0.0),vec4(0.0, 0.0, 1.0, 0.0),vec4(0.0, 0.0, 0.0, 1.0)); \n " ;
2017-04-07 04:36:37 +02:00
//set modelview
code + = " \t MODELVIEW_MATRIX = INV_CAMERA_MATRIX * mat_world; \n " ;
//handle animation
2019-02-10 01:13:42 +01:00
code + = " \t float h_frames = float(particles_anim_h_frames); \n " ;
code + = " \t float v_frames = float(particles_anim_v_frames); \n " ;
2018-09-29 18:49:34 +02:00
code + = " \t float particle_total_frames = float(particles_anim_h_frames * particles_anim_v_frames); \n " ;
code + = " \t float particle_frame = floor(INSTANCE_CUSTOM.z * float(particle_total_frames)); \n " ;
2019-02-10 01:13:42 +01:00
code + = " \t if (!particles_anim_loop) { \n " ;
code + = " \t \t particle_frame = clamp(particle_frame, 0.0, particle_total_frames - 1.0); \n " ;
code + = " \t } else { \n " ;
code + = " \t \t particle_frame = mod(particle_frame, particle_total_frames); \n " ;
code + = " \t } " ;
code + = " \t UV /= vec2(h_frames, v_frames); \n " ;
2021-09-29 20:03:07 +02:00
code + = " \t UV += vec2(mod(particle_frame, h_frames) / h_frames, floor((particle_frame + 0.5) / h_frames) / v_frames); \n " ;
2017-04-07 04:36:37 +02:00
} break ;
}
if ( flags [ FLAG_FIXED_SIZE ] ) {
code + = " \t if (PROJECTION_MATRIX[3][3] != 0.0) { \n " ;
//orthogonal matrix, try to do about the same
//with viewport size
code + = " \t \t float h = abs(1.0 / (2.0 * PROJECTION_MATRIX[1][1])); \n " ;
code + = " \t \t float sc = (h * 2.0); //consistent with Y-fov \n " ;
code + = " \t \t MODELVIEW_MATRIX[0]*=sc; \n " ;
code + = " \t \t MODELVIEW_MATRIX[1]*=sc; \n " ;
code + = " \t \t MODELVIEW_MATRIX[2]*=sc; \n " ;
code + = " \t } else { \n " ;
//just scale by depth
code + = " \t \t float sc = -(MODELVIEW_MATRIX)[3].z; \n " ;
code + = " \t \t MODELVIEW_MATRIX[0]*=sc; \n " ;
code + = " \t \t MODELVIEW_MATRIX[1]*=sc; \n " ;
code + = " \t \t MODELVIEW_MATRIX[2]*=sc; \n " ;
code + = " \t } \n " ;
}
2017-07-08 13:06:13 +02:00
if ( detail_uv = = DETAIL_UV_2 & & ! flags [ FLAG_UV2_USE_TRIPLANAR ] ) {
2017-08-31 14:43:33 +02:00
code + = " \t UV2=UV2*uv2_scale.xy+uv2_offset.xy; \n " ;
2016-11-21 02:49:53 +01:00
}
2017-07-08 13:06:13 +02:00
if ( flags [ FLAG_UV1_USE_TRIPLANAR ] | | flags [ FLAG_UV2_USE_TRIPLANAR ] ) {
//generate tangent and binormal in world space
code + = " \t TANGENT = vec3(0.0,0.0,-1.0) * abs(NORMAL.x); \n " ;
code + = " \t TANGENT+= vec3(1.0,0.0,0.0) * abs(NORMAL.y); \n " ;
code + = " \t TANGENT+= vec3(1.0,0.0,0.0) * abs(NORMAL.z); \n " ;
code + = " \t TANGENT = normalize(TANGENT); \n " ;
2021-06-27 16:32:03 +02:00
code + = " \t BINORMAL = vec3(0.0,1.0,0.0) * abs(NORMAL.x); \n " ;
code + = " \t BINORMAL+= vec3(0.0,0.0,-1.0) * abs(NORMAL.y); \n " ;
code + = " \t BINORMAL+= vec3(0.0,1.0,0.0) * abs(NORMAL.z); \n " ;
2017-07-08 13:06:13 +02:00
code + = " \t BINORMAL = normalize(BINORMAL); \n " ;
}
if ( flags [ FLAG_UV1_USE_TRIPLANAR ] ) {
code + = " \t uv1_power_normal=pow(abs(NORMAL),vec3(uv1_blend_sharpness)); \n " ;
code + = " \t uv1_power_normal/=dot(uv1_power_normal,vec3(1.0)); \n " ;
2017-09-02 14:56:12 +02:00
code + = " \t uv1_triplanar_pos = VERTEX * uv1_scale + uv1_offset; \n " ;
code + = " \t uv1_triplanar_pos *= vec3(1.0,-1.0, 1.0); \n " ;
2017-07-08 13:06:13 +02:00
}
if ( flags [ FLAG_UV2_USE_TRIPLANAR ] ) {
code + = " \t uv2_power_normal=pow(abs(NORMAL), vec3(uv2_blend_sharpness)); \n " ;
code + = " \t uv2_power_normal/=dot(uv2_power_normal,vec3(1.0)); \n " ;
2017-09-02 14:56:12 +02:00
code + = " \t uv2_triplanar_pos = VERTEX * uv2_scale + uv2_offset; \n " ;
code + = " \t uv2_triplanar_pos *= vec3(1.0,-1.0, 1.0); \n " ;
2017-07-08 13:06:13 +02:00
}
2016-10-30 01:48:09 +02:00
2017-07-08 17:34:05 +02:00
if ( grow_enabled ) {
code + = " \t VERTEX+=NORMAL*grow; \n " ;
}
2017-03-05 16:44:50 +01:00
code + = " } \n " ;
code + = " \n \n " ;
2017-07-08 13:06:13 +02:00
if ( flags [ FLAG_UV1_USE_TRIPLANAR ] | | flags [ FLAG_UV2_USE_TRIPLANAR ] ) {
2017-09-02 14:56:12 +02:00
code + = " vec4 triplanar_texture(sampler2D p_sampler,vec3 p_weights,vec3 p_triplanar_pos) { \n " ;
2017-07-08 13:06:13 +02:00
code + = " \t vec4 samp=vec4(0.0); \n " ;
2017-09-02 14:56:12 +02:00
code + = " \t samp+= texture(p_sampler,p_triplanar_pos.xy) * p_weights.z; \n " ;
code + = " \t samp+= texture(p_sampler,p_triplanar_pos.xz) * p_weights.y; \n " ;
code + = " \t samp+= texture(p_sampler,p_triplanar_pos.zy * vec2(-1.0,1.0)) * p_weights.x; \n " ;
2017-07-08 13:06:13 +02:00
code + = " \t return samp; \n " ;
code + = " } \n " ;
}
code + = " \n \n " ;
2017-03-05 16:44:50 +01:00
code + = " void fragment() { \n " ;
2016-10-30 01:48:09 +02:00
2017-07-08 13:06:13 +02:00
if ( ! flags [ FLAG_UV1_USE_TRIPLANAR ] ) {
code + = " \t vec2 base_uv = UV; \n " ;
}
2017-12-14 12:59:46 +01:00
if ( ( features [ FEATURE_DETAIL ] & & detail_uv = = DETAIL_UV_2 ) | | ( features [ FEATURE_AMBIENT_OCCLUSION ] & & flags [ FLAG_AO_ON_UV2 ] ) | | ( features [ FEATURE_EMISSION ] & & flags [ FLAG_EMISSION_ON_UV2 ] ) ) {
2017-06-04 23:08:06 +02:00
code + = " \t vec2 base_uv2 = UV2; \n " ;
}
2021-06-27 16:40:59 +02:00
if ( features [ FEATURE_DEPTH_MAPPING ] & & flags [ FLAG_UV1_USE_TRIPLANAR ] ) {
// Display both resource name and albedo texture name.
// Materials are often built-in to scenes, so displaying the resource name alone may not be meaningful.
// On the other hand, albedo textures are almost always external to the scene.
if ( textures [ TEXTURE_ALBEDO ] . is_valid ( ) ) {
WARN_PRINT ( vformat ( " %s (albedo %s): Depth mapping is not supported on triplanar materials. Ignoring depth mapping in favor of triplanar mapping. " , get_path ( ) , textures [ TEXTURE_ALBEDO ] - > get_path ( ) ) ) ;
} else if ( ! get_path ( ) . empty ( ) ) {
WARN_PRINT ( vformat ( " %s: Depth mapping is not supported on triplanar materials. Ignoring depth mapping in favor of triplanar mapping. " , get_path ( ) ) ) ;
} else {
// Resource wasn't saved yet.
WARN_PRINT ( " Depth mapping is not supported on triplanar materials. Ignoring depth mapping in favor of triplanar mapping. " ) ;
}
}
2019-02-26 01:46:24 +01:00
if ( ! VisualServer : : get_singleton ( ) - > is_low_end ( ) & & features [ FEATURE_DEPTH_MAPPING ] & & ! flags [ FLAG_UV1_USE_TRIPLANAR ] ) { //depthmap not supported with triplanar
2017-06-04 23:08:06 +02:00
code + = " \t { \n " ;
2018-12-08 03:43:46 +01:00
code + = " \t \t vec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT*depth_flip.x,-BINORMAL*depth_flip.y,NORMAL)); \n " ; // binormal is negative due to mikktspace, flip 'unflips' it ;-)
2017-06-04 23:08:06 +02:00
if ( deep_parallax ) {
code + = " \t \t float num_layers = mix(float(depth_max_layers),float(depth_min_layers), abs(dot(vec3(0.0, 0.0, 1.0), view_dir))); \n " ;
code + = " \t \t float layer_depth = 1.0 / num_layers; \n " ;
code + = " \t \t float current_layer_depth = 0.0; \n " ;
code + = " \t \t vec2 P = view_dir.xy * depth_scale; \n " ;
code + = " \t \t vec2 delta = P / num_layers; \n " ;
2021-06-07 10:17:32 +02:00
code + = " \t \t vec2 ofs = base_uv; \n " ;
code + = " \t \t float depth = textureLod(texture_depth, ofs, 0.0).r; \n " ;
2017-06-04 23:08:06 +02:00
code + = " \t \t float current_depth = 0.0; \n " ;
code + = " \t \t while(current_depth < depth) { \n " ;
code + = " \t \t \t ofs -= delta; \n " ;
2021-06-07 10:17:32 +02:00
code + = " \t \t \t depth = textureLod(texture_depth, ofs, 0.0).r; \n " ;
2017-06-04 23:08:06 +02:00
code + = " \t \t \t current_depth += layer_depth; \n " ;
code + = " \t \t } \n " ;
code + = " \t \t vec2 prev_ofs = ofs + delta; \n " ;
code + = " \t \t float after_depth = depth - current_depth; \n " ;
2017-11-27 21:47:02 +01:00
code + = " \t \t float before_depth = textureLod(texture_depth, prev_ofs, 0.0).r - current_depth + layer_depth; \n " ;
2017-06-04 23:08:06 +02:00
code + = " \t \t float weight = after_depth / (after_depth - before_depth); \n " ;
code + = " \t \t ofs = mix(ofs,prev_ofs,weight); \n " ;
} else {
code + = " \t \t float depth = texture(texture_depth, base_uv).r; \n " ;
2021-08-09 15:11:36 +02:00
// Use offset limiting to improve the appearance of non-deep parallax.
// This reduces the impression of depth, but avoids visible warping in the distance.
code + = " \t \t vec2 ofs = base_uv - view_dir.xy * depth * depth_scale; \n " ;
2017-06-04 23:08:06 +02:00
}
code + = " \t \t base_uv=ofs; \n " ;
if ( features [ FEATURE_DETAIL ] & & detail_uv = = DETAIL_UV_2 ) {
code + = " \t \t base_uv2-=ofs; \n " ;
}
code + = " \t } \n " ;
}
2019-11-03 01:42:36 +01:00
if ( flags [ FLAG_USE_POINT_SIZE ] ) {
code + = " \t vec4 albedo_tex = texture(texture_albedo,POINT_COORD); \n " ;
} else {
if ( flags [ FLAG_UV1_USE_TRIPLANAR ] ) {
code + = " \t vec4 albedo_tex = triplanar_texture(texture_albedo,uv1_power_normal,uv1_triplanar_pos); \n " ;
2017-07-08 13:06:13 +02:00
} else {
2019-11-03 01:42:36 +01:00
code + = " \t vec4 albedo_tex = texture(texture_albedo,base_uv); \n " ;
2017-07-08 13:06:13 +02:00
}
2019-11-03 01:42:36 +01:00
}
2016-10-27 16:50:26 +02:00
2022-05-21 19:12:12 +02:00
if ( flags [ FLAG_ALBEDO_TEXTURE_SDF ] ) {
code + = " \t const float smoothing = 0.125; \n " ;
code + = " \t float dist = albedo_tex.a; \n " ;
code + = " \t albedo_tex.a = smoothstep(0.5 - smoothing, 0.5 + smoothing, dist); \n " ;
code + = " \t albedo_tex.rgb = vec3(1.0); \n " ;
} else if ( flags [ FLAG_ALBEDO_TEXTURE_FORCE_SRGB ] ) {
2019-11-03 01:42:36 +01:00
code + = " \t albedo_tex.rgb = mix(pow((albedo_tex.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)),vec3(2.4)),albedo_tex.rgb.rgb * (1.0 / 12.92),lessThan(albedo_tex.rgb,vec3(0.04045))); \n " ;
2017-12-04 19:55:20 +01:00
}
2016-10-27 16:50:26 +02:00
if ( flags [ FLAG_ALBEDO_FROM_VERTEX_COLOR ] ) {
2017-03-05 16:44:50 +01:00
code + = " \t albedo_tex *= COLOR; \n " ;
2016-10-27 16:50:26 +02:00
}
2017-03-05 16:44:50 +01:00
code + = " \t ALBEDO = albedo.rgb * albedo_tex.rgb; \n " ;
2019-10-27 00:28:54 +02:00
2021-05-04 16:00:45 +02:00
if ( textures [ TEXTURE_METALLIC ] ! = nullptr ) {
2019-10-27 00:28:54 +02:00
if ( flags [ FLAG_UV1_USE_TRIPLANAR ] ) {
code + = " \t float metallic_tex = dot(triplanar_texture(texture_metallic,uv1_power_normal,uv1_triplanar_pos),metallic_texture_channel); \n " ;
} else {
code + = " \t float metallic_tex = dot(texture(texture_metallic,base_uv),metallic_texture_channel); \n " ;
}
code + = " \t METALLIC = metallic_tex * metallic; \n " ;
2017-07-08 13:06:13 +02:00
} else {
2019-10-27 00:28:54 +02:00
code + = " \t METALLIC = metallic; \n " ;
2017-07-08 13:06:13 +02:00
}
2019-10-27 00:28:54 +02:00
2021-05-04 16:00:45 +02:00
if ( textures [ TEXTURE_ROUGHNESS ] ! = nullptr ) {
2019-10-27 00:28:54 +02:00
if ( flags [ FLAG_UV1_USE_TRIPLANAR ] ) {
code + = " \t float roughness_tex = dot(triplanar_texture(texture_roughness,uv1_power_normal,uv1_triplanar_pos),roughness_texture_channel); \n " ;
} else {
code + = " \t float roughness_tex = dot(texture(texture_roughness,base_uv),roughness_texture_channel); \n " ;
}
code + = " \t ROUGHNESS = roughness_tex * roughness; \n " ;
2017-07-08 13:06:13 +02:00
} else {
2019-10-27 00:28:54 +02:00
code + = " \t ROUGHNESS = roughness; \n " ;
2017-07-08 13:06:13 +02:00
}
2019-10-27 00:28:54 +02:00
2017-06-06 03:33:01 +02:00
code + = " \t SPECULAR = specular; \n " ;
if ( features [ FEATURE_NORMAL_MAPPING ] ) {
2017-07-08 13:06:13 +02:00
if ( flags [ FLAG_UV1_USE_TRIPLANAR ] ) {
2017-09-02 14:56:12 +02:00
code + = " \t NORMALMAP = triplanar_texture(texture_normal,uv1_power_normal,uv1_triplanar_pos).rgb; \n " ;
2017-07-08 13:06:13 +02:00
} else {
code + = " \t NORMALMAP = texture(texture_normal,base_uv).rgb; \n " ;
}
2017-06-06 03:33:01 +02:00
code + = " \t NORMALMAP_DEPTH = normal_scale; \n " ;
2016-10-27 16:50:26 +02:00
}
2016-11-21 02:49:53 +01:00
if ( features [ FEATURE_EMISSION ] ) {
2017-12-14 12:59:46 +01:00
if ( flags [ FLAG_EMISSION_ON_UV2 ] ) {
if ( flags [ FLAG_UV2_USE_TRIPLANAR ] ) {
code + = " \t vec3 emission_tex = triplanar_texture(texture_emission,uv2_power_normal,uv2_triplanar_pos).rgb; \n " ;
} else {
code + = " \t vec3 emission_tex = texture(texture_emission,base_uv2).rgb; \n " ;
}
2017-07-08 13:06:13 +02:00
} else {
2017-12-14 12:59:46 +01:00
if ( flags [ FLAG_UV1_USE_TRIPLANAR ] ) {
code + = " \t vec3 emission_tex = triplanar_texture(texture_emission,uv1_power_normal,uv1_triplanar_pos).rgb; \n " ;
} else {
code + = " \t vec3 emission_tex = texture(texture_emission,base_uv).rgb; \n " ;
}
2017-07-08 13:06:13 +02:00
}
2017-12-14 12:59:46 +01:00
2017-11-15 16:39:24 +01:00
if ( emission_op = = EMISSION_OP_ADD ) {
code + = " \t EMISSION = (emission.rgb+emission_tex)*emission_energy; \n " ;
} else {
code + = " \t EMISSION = (emission.rgb*emission_tex)*emission_energy; \n " ;
}
2016-11-21 02:49:53 +01:00
}
2018-02-15 15:21:09 +01:00
if ( features [ FEATURE_REFRACTION ] ) {
2017-06-06 03:33:01 +02:00
if ( features [ FEATURE_NORMAL_MAPPING ] ) {
2021-05-05 16:25:32 +02:00
code + = " \t vec3 unpacked_normal = NORMALMAP; \n " ;
code + = " \t unpacked_normal.xy = unpacked_normal.xy * 2.0 - 1.0; \n " ;
code + = " \t unpacked_normal.z = sqrt(max(0.0, 1.0 - dot(unpacked_normal.xy, unpacked_normal.xy))); \n " ;
code + = " \t vec3 ref_normal = normalize( mix(NORMAL,TANGENT * unpacked_normal.x + BINORMAL * unpacked_normal.y + NORMAL * unpacked_normal.z,NORMALMAP_DEPTH) ); \n " ;
2017-06-06 03:33:01 +02:00
} else {
code + = " \t vec3 ref_normal = NORMAL; \n " ;
}
2018-02-15 15:21:09 +01:00
if ( flags [ FLAG_UV1_USE_TRIPLANAR ] ) {
code + = " \t vec2 ref_ofs = SCREEN_UV - ref_normal.xy * dot(triplanar_texture(texture_refraction,uv1_power_normal,uv1_triplanar_pos),refraction_texture_channel) * refraction; \n " ;
} else {
code + = " \t vec2 ref_ofs = SCREEN_UV - ref_normal.xy * dot(texture(texture_refraction,base_uv),refraction_texture_channel) * refraction; \n " ;
}
2017-06-06 03:33:01 +02:00
code + = " \t float ref_amount = 1.0 - albedo.a * albedo_tex.a; \n " ;
code + = " \t EMISSION += textureLod(SCREEN_TEXTURE,ref_ofs,ROUGHNESS * 8.0).rgb * ref_amount; \n " ;
code + = " \t ALBEDO *= 1.0 - ref_amount; \n " ;
code + = " \t ALPHA = 1.0; \n " ;
2019-05-20 16:37:13 +02:00
} else if ( features [ FEATURE_TRANSPARENT ] | | flags [ FLAG_USE_ALPHA_SCISSOR ] | | flags [ FLAG_USE_SHADOW_TO_OPACITY ] | | ( distance_fade = = DISTANCE_FADE_PIXEL_ALPHA ) | | proximity_fade_enabled ) {
2017-06-06 03:33:01 +02:00
code + = " \t ALPHA = albedo.a * albedo_tex.a; \n " ;
2016-11-21 02:49:53 +01:00
}
2019-02-22 15:32:37 +01:00
if ( proximity_fade_enabled ) {
2017-09-21 20:20:00 +02:00
code + = " \t float depth_tex = textureLod(DEPTH_TEXTURE,SCREEN_UV,0.0).r; \n " ;
code + = " \t vec4 world_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV*2.0-1.0,depth_tex*2.0-1.0,1.0); \n " ;
code + = " \t world_pos.xyz/=world_pos.w; \n " ;
code + = " \t ALPHA*=clamp(1.0-smoothstep(world_pos.z+proximity_fade_distance,world_pos.z,VERTEX.z),0.0,1.0); \n " ;
}
2018-08-22 15:23:28 +02:00
if ( distance_fade ! = DISTANCE_FADE_DISABLED ) {
2022-12-12 15:16:34 +01:00
// Use the slightly more expensive circular fade (distance to the object) instead of linear
// (Z distance), so that the fade is always the same regardless of the camera angle.
2018-09-30 00:17:34 +02:00
if ( ( distance_fade = = DISTANCE_FADE_OBJECT_DITHER | | distance_fade = = DISTANCE_FADE_PIXEL_DITHER ) ) {
if ( ! VisualServer : : get_singleton ( ) - > is_low_end ( ) ) {
code + = " \t { \n " ;
2021-07-09 00:01:47 +02:00
2018-09-30 00:17:34 +02:00
if ( distance_fade = = DISTANCE_FADE_OBJECT_DITHER ) {
2022-12-12 15:16:34 +01:00
code + = " \t \t float fade_distance = length((INV_CAMERA_MATRIX * WORLD_MATRIX[3])); \n " ;
2018-09-30 00:17:34 +02:00
} else {
2022-12-12 15:16:34 +01:00
code + = " \t \t float fade_distance = length(VERTEX); \n " ;
2018-09-30 00:17:34 +02:00
}
2021-07-09 00:01:47 +02:00
// Use interleaved gradient noise, which is fast but still looks good.
code + = " \t \t const vec3 magic = vec3(0.06711056f, 0.00583715f, 52.9829189f); " ;
code + = " \t \t float fade = clamp(smoothstep(distance_fade_min, distance_fade_max, fade_distance), 0.0, 1.0); \n " ;
// Use a hard cap to prevent a few stray pixels from remaining when past the fade-out distance.
code + = " \t \t if (fade < 0.001 || fade < fract(magic.z * fract(dot(FRAGCOORD.xy, magic.xy)))) { \n " ;
code + = " \t \t \t discard; \n " ;
code + = " \t \t } \n " ;
2018-09-30 00:17:34 +02:00
code + = " \t } \n \n " ;
2018-08-22 15:23:28 +02:00
}
} else {
2022-12-12 15:16:34 +01:00
code + = " \t ALPHA *= clamp(smoothstep(distance_fade_min, distance_fade_max, length(VERTEX)), 0.0, 1.0); \n " ;
2018-08-22 15:23:28 +02:00
}
2017-09-21 20:20:00 +02:00
}
2016-11-21 02:49:53 +01:00
if ( features [ FEATURE_RIM ] ) {
2017-07-08 13:06:13 +02:00
if ( flags [ FLAG_UV1_USE_TRIPLANAR ] ) {
2017-09-02 14:56:12 +02:00
code + = " \t vec2 rim_tex = triplanar_texture(texture_rim,uv1_power_normal,uv1_triplanar_pos).xy; \n " ;
2017-07-08 13:06:13 +02:00
} else {
code + = " \t vec2 rim_tex = texture(texture_rim,base_uv).xy; \n " ;
}
2017-03-05 16:44:50 +01:00
code + = " \t RIM = rim*rim_tex.x; " ;
code + = " \t RIM_TINT = rim_tint*rim_tex.y; \n " ;
2016-11-21 02:49:53 +01:00
}
if ( features [ FEATURE_CLEARCOAT ] ) {
2017-07-08 13:06:13 +02:00
if ( flags [ FLAG_UV1_USE_TRIPLANAR ] ) {
2017-09-02 14:56:12 +02:00
code + = " \t vec2 clearcoat_tex = triplanar_texture(texture_clearcoat,uv1_power_normal,uv1_triplanar_pos).xy; \n " ;
2017-07-08 13:06:13 +02:00
} else {
code + = " \t vec2 clearcoat_tex = texture(texture_clearcoat,base_uv).xy; \n " ;
}
2017-03-05 16:44:50 +01:00
code + = " \t CLEARCOAT = clearcoat*clearcoat_tex.x; " ;
code + = " \t CLEARCOAT_GLOSS = clearcoat_gloss*clearcoat_tex.y; \n " ;
2016-11-21 02:49:53 +01:00
}
if ( features [ FEATURE_ANISOTROPY ] ) {
2017-07-08 13:06:13 +02:00
if ( flags [ FLAG_UV1_USE_TRIPLANAR ] ) {
2017-09-02 14:56:12 +02:00
code + = " \t vec3 anisotropy_tex = triplanar_texture(texture_flowmap,uv1_power_normal,uv1_triplanar_pos).rga; \n " ;
2017-07-08 13:06:13 +02:00
} else {
code + = " \t vec3 anisotropy_tex = texture(texture_flowmap,base_uv).rga; \n " ;
}
2017-07-08 17:34:05 +02:00
code + = " \t ANISOTROPY = anisotropy_ratio*anisotropy_tex.b; \n " ;
2017-03-05 16:44:50 +01:00
code + = " \t ANISOTROPY_FLOW = anisotropy_tex.rg*2.0-1.0; \n " ;
2016-11-21 02:49:53 +01:00
}
if ( features [ FEATURE_AMBIENT_OCCLUSION ] ) {
2017-07-08 13:06:13 +02:00
if ( flags [ FLAG_AO_ON_UV2 ] ) {
if ( flags [ FLAG_UV2_USE_TRIPLANAR ] ) {
2017-09-02 14:56:12 +02:00
code + = " \t AO = dot(triplanar_texture(texture_ambient_occlusion,uv2_power_normal,uv2_triplanar_pos),ao_texture_channel); \n " ;
2017-07-08 13:06:13 +02:00
} else {
2017-08-02 20:34:55 +02:00
code + = " \t AO = dot(texture(texture_ambient_occlusion,base_uv2),ao_texture_channel); \n " ;
2017-07-08 13:06:13 +02:00
}
} else {
if ( flags [ FLAG_UV1_USE_TRIPLANAR ] ) {
2017-09-02 14:56:12 +02:00
code + = " \t AO = dot(triplanar_texture(texture_ambient_occlusion,uv1_power_normal,uv1_triplanar_pos),ao_texture_channel); \n " ;
2017-07-08 13:06:13 +02:00
} else {
2017-08-02 20:34:55 +02:00
code + = " \t AO = dot(texture(texture_ambient_occlusion,base_uv),ao_texture_channel); \n " ;
2017-07-08 13:06:13 +02:00
}
}
2017-09-24 04:10:34 +02:00
code + = " \t AO_LIGHT_AFFECT = ao_light_affect; \n " ;
2016-11-21 02:49:53 +01:00
}
2016-12-03 02:23:16 +01:00
if ( features [ FEATURE_SUBSURACE_SCATTERING ] ) {
2017-07-08 13:06:13 +02:00
if ( flags [ FLAG_UV1_USE_TRIPLANAR ] ) {
2017-09-02 14:56:12 +02:00
code + = " \t float sss_tex = triplanar_texture(texture_subsurface_scattering,uv1_power_normal,uv1_triplanar_pos).r; \n " ;
2017-07-08 13:06:13 +02:00
} else {
code + = " \t float sss_tex = texture(texture_subsurface_scattering,base_uv).r; \n " ;
}
2017-03-05 16:44:50 +01:00
code + = " \t SSS_STRENGTH=subsurface_scattering_strength*sss_tex; \n " ;
2016-12-03 02:23:16 +01:00
}
2017-09-03 15:29:56 +02:00
if ( features [ FEATURE_TRANSMISSION ] ) {
if ( flags [ FLAG_UV1_USE_TRIPLANAR ] ) {
code + = " \t vec3 transmission_tex = triplanar_texture(texture_transmission,uv1_power_normal,uv1_triplanar_pos).rgb; \n " ;
} else {
code + = " \t vec3 transmission_tex = texture(texture_transmission,base_uv).rgb; \n " ;
}
code + = " \t TRANSMISSION = (transmission.rgb+transmission_tex); \n " ;
}
2016-11-21 02:49:53 +01:00
if ( features [ FEATURE_DETAIL ] ) {
2017-07-08 13:06:13 +02:00
bool triplanar = ( flags [ FLAG_UV1_USE_TRIPLANAR ] & & detail_uv = = DETAIL_UV_1 ) | | ( flags [ FLAG_UV2_USE_TRIPLANAR ] & & detail_uv = = DETAIL_UV_2 ) ;
if ( triplanar ) {
String tp_uv = detail_uv = = DETAIL_UV_1 ? " uv1 " : " uv2 " ;
2017-09-02 14:56:12 +02:00
code + = " \t vec4 detail_tex = triplanar_texture(texture_detail_albedo, " + tp_uv + " _power_normal, " + tp_uv + " _triplanar_pos); \n " ;
code + = " \t vec4 detail_norm_tex = triplanar_texture(texture_detail_normal, " + tp_uv + " _power_normal, " + tp_uv + " _triplanar_pos); \n " ;
2017-07-08 13:06:13 +02:00
} else {
String det_uv = detail_uv = = DETAIL_UV_1 ? " base_uv " : " base_uv2 " ;
code + = " \t vec4 detail_tex = texture(texture_detail_albedo, " + det_uv + " ); \n " ;
code + = " \t vec4 detail_norm_tex = texture(texture_detail_normal, " + det_uv + " ); \n " ;
}
if ( flags [ FLAG_UV1_USE_TRIPLANAR ] ) {
2018-08-26 19:58:52 +02:00
code + = " \t vec4 detail_mask_tex = triplanar_texture(texture_detail_mask,uv1_power_normal,uv1_triplanar_pos); \n " ;
2017-07-08 13:06:13 +02:00
} else {
code + = " \t vec4 detail_mask_tex = texture(texture_detail_mask,base_uv); \n " ;
}
2016-11-21 02:49:53 +01:00
2017-03-05 16:44:50 +01:00
switch ( detail_blend_mode ) {
2016-11-21 02:49:53 +01:00
case BLEND_MODE_MIX : {
2017-03-05 16:44:50 +01:00
code + = " \t vec3 detail = mix(ALBEDO.rgb,detail_tex.rgb,detail_tex.a); \n " ;
2016-11-21 02:49:53 +01:00
} break ;
case BLEND_MODE_ADD : {
2017-03-05 16:44:50 +01:00
code + = " \t vec3 detail = mix(ALBEDO.rgb,ALBEDO.rgb+detail_tex.rgb,detail_tex.a); \n " ;
2016-11-21 02:49:53 +01:00
} break ;
case BLEND_MODE_SUB : {
2017-03-05 16:44:50 +01:00
code + = " \t vec3 detail = mix(ALBEDO.rgb,ALBEDO.rgb-detail_tex.rgb,detail_tex.a); \n " ;
2016-11-21 02:49:53 +01:00
} break ;
case BLEND_MODE_MUL : {
2017-03-05 16:44:50 +01:00
code + = " \t vec3 detail = mix(ALBEDO.rgb,ALBEDO.rgb*detail_tex.rgb,detail_tex.a); \n " ;
2016-11-21 02:49:53 +01:00
} break ;
}
2017-03-05 16:44:50 +01:00
code + = " \t vec3 detail_norm = mix(NORMALMAP,detail_norm_tex.rgb,detail_tex.a); \n " ;
code + = " \t NORMALMAP = mix(NORMALMAP,detail_norm,detail_mask_tex.r); \n " ;
code + = " \t ALBEDO.rgb = mix(ALBEDO.rgb,detail,detail_mask_tex.r); \n " ;
2017-09-23 13:27:34 +02:00
}
2017-08-08 22:23:44 +02:00
2017-09-23 13:27:34 +02:00
if ( flags [ FLAG_USE_ALPHA_SCISSOR ] ) {
code + = " \t ALPHA_SCISSOR=alpha_scissor_threshold; \n " ;
2016-11-21 02:49:53 +01:00
}
2017-03-05 16:44:50 +01:00
code + = " } \n " ;
2016-10-27 16:50:26 +02:00
2021-09-26 21:31:17 +02:00
String fallback_mode_str ;
switch ( async_mode ) {
case ASYNC_MODE_VISIBLE : {
fallback_mode_str = " async_visible " ;
} break ;
case ASYNC_MODE_HIDDEN : {
fallback_mode_str = " async_hidden " ;
} break ;
}
code = code . replace_first ( " render_mode " , " render_mode " + fallback_mode_str + " , " ) ;
2016-10-27 16:50:26 +02:00
ShaderData shader_data ;
2017-04-07 04:36:37 +02:00
shader_data . shader = VS : : get_singleton ( ) - > shader_create ( ) ;
2017-03-05 16:44:50 +01:00
shader_data . users = 1 ;
2016-10-27 16:50:26 +02:00
2017-03-05 16:44:50 +01:00
VS : : get_singleton ( ) - > shader_set_code ( shader_data . shader , code ) ;
2016-10-27 16:50:26 +02:00
2017-03-05 16:44:50 +01:00
shader_map [ mk ] = shader_data ;
2016-10-27 16:50:26 +02:00
2017-03-05 16:44:50 +01:00
VS : : get_singleton ( ) - > material_set_shader ( _get_material ( ) , shader_data . shader ) ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : flush_changes ( ) {
2021-01-27 10:43:02 +01:00
material_mutex . lock ( ) ;
2014-02-10 02:10:30 +01:00
2018-11-21 16:48:05 +01:00
while ( dirty_materials - > first ( ) ) {
dirty_materials - > first ( ) - > self ( ) - > _update_shader ( ) ;
2016-10-27 16:50:26 +02:00
}
2021-01-27 10:43:02 +01:00
material_mutex . unlock ( ) ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : _queue_shader_change ( ) {
2021-01-27 10:43:02 +01:00
material_mutex . lock ( ) ;
2016-10-27 16:50:26 +02:00
2021-09-06 14:32:59 +02:00
if ( is_initialized & & ! element . in_list ( ) ) {
2018-11-21 16:48:05 +01:00
dirty_materials - > add ( & element ) ;
2016-10-27 16:50:26 +02:00
}
2021-01-27 10:43:02 +01:00
material_mutex . unlock ( ) ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
bool SpatialMaterial : : _is_shader_dirty ( ) const {
2017-03-05 16:44:50 +01:00
bool dirty = false ;
2016-10-27 16:50:26 +02:00
2021-01-27 10:43:02 +01:00
material_mutex . lock ( ) ;
2016-10-27 16:50:26 +02:00
2017-03-05 16:44:50 +01:00
dirty = element . in_list ( ) ;
2016-10-27 16:50:26 +02:00
2021-01-27 10:43:02 +01:00
material_mutex . unlock ( ) ;
2016-10-27 16:50:26 +02:00
return dirty ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_albedo ( const Color & p_albedo ) {
2017-03-05 16:44:50 +01:00
albedo = p_albedo ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > albedo , p_albedo ) ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
Color SpatialMaterial : : get_albedo ( ) const {
2016-10-27 16:50:26 +02:00
return albedo ;
2014-02-10 02:10:30 +01:00
}
2017-06-01 01:16:38 +02:00
void SpatialMaterial : : set_specular ( float p_specular ) {
2017-03-05 16:44:50 +01:00
specular = p_specular ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > specular , p_specular ) ;
2016-10-27 16:50:26 +02:00
}
2017-06-01 01:16:38 +02:00
float SpatialMaterial : : get_specular ( ) const {
2016-10-27 16:50:26 +02:00
return specular ;
}
2014-02-10 02:10:30 +01:00
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_roughness ( float p_roughness ) {
2017-03-05 16:44:50 +01:00
roughness = p_roughness ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > roughness , p_roughness ) ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
float SpatialMaterial : : get_roughness ( ) const {
2016-10-27 16:50:26 +02:00
return roughness ;
}
2014-02-10 02:10:30 +01:00
2017-06-01 01:16:38 +02:00
void SpatialMaterial : : set_metallic ( float p_metallic ) {
metallic = p_metallic ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > metallic , p_metallic ) ;
2017-01-02 04:01:55 +01:00
}
2014-02-10 02:10:30 +01:00
2017-06-01 01:16:38 +02:00
float SpatialMaterial : : get_metallic ( ) const {
return metallic ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_emission ( const Color & p_emission ) {
2017-03-05 16:44:50 +01:00
emission = p_emission ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > emission , p_emission ) ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
Color SpatialMaterial : : get_emission ( ) const {
2016-10-27 16:50:26 +02:00
return emission ;
}
2014-02-10 02:10:30 +01:00
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_emission_energy ( float p_emission_energy ) {
2017-03-05 16:44:50 +01:00
emission_energy = p_emission_energy ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > emission_energy , p_emission_energy ) ;
2016-11-21 02:49:53 +01:00
}
2017-04-07 04:36:37 +02:00
float SpatialMaterial : : get_emission_energy ( ) const {
2016-11-21 02:49:53 +01:00
return emission_energy ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_normal_scale ( float p_normal_scale ) {
2017-03-05 16:44:50 +01:00
normal_scale = p_normal_scale ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > normal_scale , p_normal_scale ) ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
float SpatialMaterial : : get_normal_scale ( ) const {
2016-10-27 16:50:26 +02:00
return normal_scale ;
}
2014-02-10 02:10:30 +01:00
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_rim ( float p_rim ) {
2017-03-05 16:44:50 +01:00
rim = p_rim ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > rim , p_rim ) ;
2016-10-27 16:50:26 +02:00
}
2017-04-07 04:36:37 +02:00
float SpatialMaterial : : get_rim ( ) const {
2016-11-21 02:49:53 +01:00
return rim ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_rim_tint ( float p_rim_tint ) {
2017-03-05 16:44:50 +01:00
rim_tint = p_rim_tint ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > rim_tint , p_rim_tint ) ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
float SpatialMaterial : : get_rim_tint ( ) const {
2016-11-21 02:49:53 +01:00
return rim_tint ;
2016-10-27 16:50:26 +02:00
}
2014-02-10 02:10:30 +01:00
2017-09-24 04:10:34 +02:00
void SpatialMaterial : : set_ao_light_affect ( float p_ao_light_affect ) {
ao_light_affect = p_ao_light_affect ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > ao_light_affect , p_ao_light_affect ) ;
}
float SpatialMaterial : : get_ao_light_affect ( ) const {
return ao_light_affect ;
}
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_clearcoat ( float p_clearcoat ) {
2017-03-05 16:44:50 +01:00
clearcoat = p_clearcoat ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > clearcoat , p_clearcoat ) ;
2016-10-27 16:50:26 +02:00
}
2014-02-10 02:10:30 +01:00
2017-04-07 04:36:37 +02:00
float SpatialMaterial : : get_clearcoat ( ) const {
2016-10-27 16:50:26 +02:00
return clearcoat ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_clearcoat_gloss ( float p_clearcoat_gloss ) {
2017-03-05 16:44:50 +01:00
clearcoat_gloss = p_clearcoat_gloss ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > clearcoat_gloss , p_clearcoat_gloss ) ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
float SpatialMaterial : : get_clearcoat_gloss ( ) const {
2016-10-27 16:50:26 +02:00
return clearcoat_gloss ;
2014-06-28 04:21:45 +02:00
}
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_anisotropy ( float p_anisotropy ) {
2017-03-05 16:44:50 +01:00
anisotropy = p_anisotropy ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > anisotropy , p_anisotropy ) ;
2016-10-27 16:50:26 +02:00
}
2017-04-07 04:36:37 +02:00
float SpatialMaterial : : get_anisotropy ( ) const {
2016-10-27 16:50:26 +02:00
return anisotropy ;
2014-06-28 04:21:45 +02:00
}
2017-06-04 23:08:06 +02:00
void SpatialMaterial : : set_depth_scale ( float p_depth_scale ) {
depth_scale = p_depth_scale ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > depth_scale , p_depth_scale ) ;
2014-02-10 02:10:30 +01:00
}
2017-06-04 23:08:06 +02:00
float SpatialMaterial : : get_depth_scale ( ) const {
return depth_scale ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_subsurface_scattering_strength ( float p_subsurface_scattering_strength ) {
2017-03-05 16:44:50 +01:00
subsurface_scattering_strength = p_subsurface_scattering_strength ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > subsurface_scattering_strength , subsurface_scattering_strength ) ;
2016-10-27 16:50:26 +02:00
}
2017-04-07 04:36:37 +02:00
float SpatialMaterial : : get_subsurface_scattering_strength ( ) const {
2016-12-03 02:23:16 +01:00
return subsurface_scattering_strength ;
2014-02-10 02:10:30 +01:00
}
2017-09-03 15:29:56 +02:00
void SpatialMaterial : : set_transmission ( const Color & p_transmission ) {
transmission = p_transmission ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > transmission , transmission ) ;
}
Color SpatialMaterial : : get_transmission ( ) const {
return transmission ;
}
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_refraction ( float p_refraction ) {
2017-03-05 16:44:50 +01:00
refraction = p_refraction ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > refraction , refraction ) ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
float SpatialMaterial : : get_refraction ( ) const {
2016-10-27 16:50:26 +02:00
return refraction ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_detail_uv ( DetailUV p_detail_uv ) {
2021-05-05 12:44:11 +02:00
if ( detail_uv = = p_detail_uv ) {
2016-10-27 16:50:26 +02:00
return ;
2021-05-05 12:44:11 +02:00
}
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
detail_uv = p_detail_uv ;
2016-10-27 16:50:26 +02:00
_queue_shader_change ( ) ;
}
2017-04-07 04:36:37 +02:00
SpatialMaterial : : DetailUV SpatialMaterial : : get_detail_uv ( ) const {
2016-10-27 16:50:26 +02:00
return detail_uv ;
}
2014-02-10 02:10:30 +01:00
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_blend_mode ( BlendMode p_mode ) {
2021-05-05 12:44:11 +02:00
if ( blend_mode = = p_mode ) {
2016-10-27 16:50:26 +02:00
return ;
2021-05-05 12:44:11 +02:00
}
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
blend_mode = p_mode ;
2016-10-27 16:50:26 +02:00
_queue_shader_change ( ) ;
}
2017-04-07 04:36:37 +02:00
SpatialMaterial : : BlendMode SpatialMaterial : : get_blend_mode ( ) const {
2016-10-27 16:50:26 +02:00
return blend_mode ;
}
2014-02-10 02:10:30 +01:00
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_detail_blend_mode ( BlendMode p_mode ) {
2017-03-05 16:44:50 +01:00
detail_blend_mode = p_mode ;
2016-10-27 16:50:26 +02:00
_queue_shader_change ( ) ;
}
2017-04-07 04:36:37 +02:00
SpatialMaterial : : BlendMode SpatialMaterial : : get_detail_blend_mode ( ) const {
2016-10-27 16:50:26 +02:00
return detail_blend_mode ;
}
2014-02-10 02:10:30 +01:00
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_depth_draw_mode ( DepthDrawMode p_mode ) {
2021-05-05 12:44:11 +02:00
if ( depth_draw_mode = = p_mode ) {
2016-10-27 16:50:26 +02:00
return ;
2021-05-05 12:44:11 +02:00
}
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
depth_draw_mode = p_mode ;
2016-10-27 16:50:26 +02:00
_queue_shader_change ( ) ;
}
2017-04-07 04:36:37 +02:00
SpatialMaterial : : DepthDrawMode SpatialMaterial : : get_depth_draw_mode ( ) const {
2016-10-27 16:50:26 +02:00
return depth_draw_mode ;
}
2014-02-10 02:10:30 +01:00
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_cull_mode ( CullMode p_mode ) {
2021-05-05 12:44:11 +02:00
if ( cull_mode = = p_mode ) {
2016-10-27 16:50:26 +02:00
return ;
2021-05-05 12:44:11 +02:00
}
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
cull_mode = p_mode ;
2016-10-27 16:50:26 +02:00
_queue_shader_change ( ) ;
}
2017-04-07 04:36:37 +02:00
SpatialMaterial : : CullMode SpatialMaterial : : get_cull_mode ( ) const {
2016-10-27 16:50:26 +02:00
return cull_mode ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_diffuse_mode ( DiffuseMode p_mode ) {
2021-05-05 12:44:11 +02:00
if ( diffuse_mode = = p_mode ) {
2016-10-27 16:50:26 +02:00
return ;
2021-05-05 12:44:11 +02:00
}
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
diffuse_mode = p_mode ;
2016-10-27 16:50:26 +02:00
_queue_shader_change ( ) ;
}
2017-04-07 04:36:37 +02:00
SpatialMaterial : : DiffuseMode SpatialMaterial : : get_diffuse_mode ( ) const {
2016-10-27 16:50:26 +02:00
return diffuse_mode ;
}
2014-02-10 02:10:30 +01:00
2017-07-08 17:34:05 +02:00
void SpatialMaterial : : set_specular_mode ( SpecularMode p_mode ) {
2021-05-05 12:44:11 +02:00
if ( specular_mode = = p_mode ) {
2017-07-08 17:34:05 +02:00
return ;
2021-05-05 12:44:11 +02:00
}
2017-07-08 17:34:05 +02:00
specular_mode = p_mode ;
_queue_shader_change ( ) ;
}
SpatialMaterial : : SpecularMode SpatialMaterial : : get_specular_mode ( ) const {
return specular_mode ;
}
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_flag ( Flags p_flag , bool p_enabled ) {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_flag , FLAG_MAX ) ;
2014-02-10 02:10:30 +01:00
2021-05-05 12:44:11 +02:00
if ( flags [ p_flag ] = = p_enabled ) {
2016-10-27 16:50:26 +02:00
return ;
2021-05-05 12:44:11 +02:00
}
2014-10-03 13:58:41 +02:00
2017-03-05 16:44:50 +01:00
flags [ p_flag ] = p_enabled ;
2021-07-17 04:17:57 +02:00
if (
p_flag = = FLAG_USE_ALPHA_SCISSOR | |
p_flag = = FLAG_UNSHADED | |
p_flag = = FLAG_USE_SHADOW_TO_OPACITY | |
p_flag = = FLAG_UV1_USE_TRIPLANAR | |
p_flag = = FLAG_UV2_USE_TRIPLANAR ) {
2017-08-08 22:23:44 +02:00
_change_notify ( ) ;
}
2021-07-17 04:17:57 +02:00
2016-10-27 16:50:26 +02:00
_queue_shader_change ( ) ;
}
2014-02-10 02:10:30 +01:00
2017-04-07 04:36:37 +02:00
bool SpatialMaterial : : get_flag ( Flags p_flag ) const {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_flag , FLAG_MAX , false ) ;
2016-10-27 16:50:26 +02:00
return flags [ p_flag ] ;
}
2014-02-10 02:10:30 +01:00
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_feature ( Feature p_feature , bool p_enabled ) {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_feature , FEATURE_MAX ) ;
2021-05-05 12:44:11 +02:00
if ( features [ p_feature ] = = p_enabled ) {
2016-10-27 16:50:26 +02:00
return ;
2021-05-05 12:44:11 +02:00
}
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
features [ p_feature ] = p_enabled ;
2016-10-27 16:50:26 +02:00
_change_notify ( ) ;
_queue_shader_change ( ) ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
bool SpatialMaterial : : get_feature ( Feature p_feature ) const {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_feature , FEATURE_MAX , false ) ;
2016-10-27 16:50:26 +02:00
return features [ p_feature ] ;
}
2014-12-17 02:31:57 +01:00
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_texture ( TextureParam p_param , const Ref < Texture > & p_texture ) {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_param , TEXTURE_MAX ) ;
textures [ p_param ] = p_texture ;
2016-10-30 01:48:09 +02:00
RID rid = p_texture . is_valid ( ) ? p_texture - > get_rid ( ) : RID ( ) ;
2017-03-05 16:44:50 +01:00
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > texture_names [ p_param ] , rid ) ;
2019-11-03 01:42:36 +01:00
_change_notify ( ) ;
2019-11-17 20:09:56 +01:00
_queue_shader_change ( ) ;
2016-10-27 16:50:26 +02:00
}
2015-01-11 15:43:31 +01:00
2017-04-07 04:36:37 +02:00
Ref < Texture > SpatialMaterial : : get_texture ( TextureParam p_param ) const {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_param , TEXTURE_MAX , Ref < Texture > ( ) ) ;
2016-10-27 16:50:26 +02:00
return textures [ p_param ] ;
}
2017-10-16 11:14:39 +02:00
Ref < Texture > SpatialMaterial : : get_texture_by_name ( StringName p_name ) const {
for ( int i = 0 ; i < ( int ) SpatialMaterial : : TEXTURE_MAX ; i + + ) {
TextureParam param = TextureParam ( i ) ;
2021-05-05 12:44:11 +02:00
if ( p_name = = shader_names - > texture_names [ param ] ) {
2017-10-16 11:14:39 +02:00
return textures [ param ] ;
2021-05-05 12:44:11 +02:00
}
2017-10-16 11:14:39 +02:00
}
return Ref < Texture > ( ) ;
}
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : _validate_feature ( const String & text , Feature feature , PropertyInfo & property ) const {
2017-03-05 16:44:50 +01:00
if ( property . name . begins_with ( text ) & & property . name ! = text + " _enabled " & & ! features [ feature ] ) {
property . usage = 0 ;
2014-02-10 02:10:30 +01:00
}
}
2018-09-29 01:32:40 +02:00
void SpatialMaterial : : _validate_high_end ( const String & text , PropertyInfo & property ) const {
if ( property . name . begins_with ( text ) ) {
property . usage | = PROPERTY_USAGE_HIGH_END_GFX ;
}
}
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : _validate_property ( PropertyInfo & property ) const {
2017-03-05 16:44:50 +01:00
_validate_feature ( " normal " , FEATURE_NORMAL_MAPPING , property ) ;
_validate_feature ( " emission " , FEATURE_EMISSION , property ) ;
_validate_feature ( " rim " , FEATURE_RIM , property ) ;
_validate_feature ( " clearcoat " , FEATURE_CLEARCOAT , property ) ;
_validate_feature ( " anisotropy " , FEATURE_ANISOTROPY , property ) ;
_validate_feature ( " ao " , FEATURE_AMBIENT_OCCLUSION , property ) ;
2017-06-04 23:08:06 +02:00
_validate_feature ( " depth " , FEATURE_DEPTH_MAPPING , property ) ;
2017-03-05 16:44:50 +01:00
_validate_feature ( " subsurf_scatter " , FEATURE_SUBSURACE_SCATTERING , property ) ;
2017-09-03 15:29:56 +02:00
_validate_feature ( " transmission " , FEATURE_TRANSMISSION , property ) ;
2017-03-05 16:44:50 +01:00
_validate_feature ( " refraction " , FEATURE_REFRACTION , property ) ;
_validate_feature ( " detail " , FEATURE_DETAIL , property ) ;
2018-09-29 01:32:40 +02:00
_validate_high_end ( " subsurf_scatter " , property ) ;
_validate_high_end ( " depth " , property ) ;
2017-04-07 04:36:37 +02:00
if ( property . name . begins_with ( " particles_anim_ " ) & & billboard_mode ! = BILLBOARD_PARTICLES ) {
property . usage = 0 ;
}
2017-07-08 17:34:05 +02:00
if ( property . name = = " params_grow_amount " & & ! grow_enabled ) {
property . usage = 0 ;
}
2017-08-08 22:23:44 +02:00
2017-10-25 20:27:52 +02:00
if ( property . name = = " proximity_fade_distance " & & ! proximity_fade_enabled ) {
2017-09-21 20:20:00 +02:00
property . usage = 0 ;
}
2018-08-22 15:23:28 +02:00
if ( ( property . name = = " distance_fade_max_distance " | | property . name = = " distance_fade_min_distance " ) & & distance_fade = = DISTANCE_FADE_DISABLED ) {
2017-09-21 20:20:00 +02:00
property . usage = 0 ;
}
2021-07-17 04:17:57 +02:00
if ( property . name = = " uv1_triplanar_sharpness " & & ! flags [ FLAG_UV1_USE_TRIPLANAR ] ) {
property . usage = 0 ;
}
if ( property . name = = " uv2_triplanar_sharpness " & & ! flags [ FLAG_UV2_USE_TRIPLANAR ] ) {
property . usage = 0 ;
}
2017-08-08 22:23:44 +02:00
if ( property . name = = " params_alpha_scissor_threshold " & & ! flags [ FLAG_USE_ALPHA_SCISSOR ] ) {
property . usage = 0 ;
}
if ( ( property . name = = " depth_min_layers " | | property . name = = " depth_max_layers " ) & & ! deep_parallax ) {
property . usage = 0 ;
}
2018-09-27 01:44:43 +02:00
if ( flags [ FLAG_UNSHADED ] ) {
if ( property . name . begins_with ( " anisotropy " ) ) {
property . usage = 0 ;
}
if ( property . name . begins_with ( " ao " ) ) {
property . usage = 0 ;
}
if ( property . name . begins_with ( " clearcoat " ) ) {
property . usage = 0 ;
}
if ( property . name . begins_with ( " emission " ) ) {
property . usage = 0 ;
}
if ( property . name . begins_with ( " metallic " ) ) {
property . usage = 0 ;
}
if ( property . name . begins_with ( " normal " ) ) {
property . usage = 0 ;
}
if ( property . name . begins_with ( " rim " ) ) {
property . usage = 0 ;
}
if ( property . name . begins_with ( " roughness " ) ) {
property . usage = 0 ;
}
if ( property . name . begins_with ( " subsurf_scatter " ) ) {
property . usage = 0 ;
}
if ( property . name . begins_with ( " transmission " ) ) {
property . usage = 0 ;
}
}
2016-10-27 16:50:26 +02:00
}
2014-02-10 02:10:30 +01:00
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_line_width ( float p_line_width ) {
2017-03-05 16:44:50 +01:00
line_width = p_line_width ;
VS : : get_singleton ( ) - > material_set_line_width ( _get_material ( ) , line_width ) ;
2016-10-30 01:48:09 +02:00
}
2015-01-11 15:43:31 +01:00
2017-04-07 04:36:37 +02:00
float SpatialMaterial : : get_line_width ( ) const {
2016-10-30 01:48:09 +02:00
return line_width ;
}
2014-02-10 02:10:30 +01:00
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_point_size ( float p_point_size ) {
2017-03-05 16:44:50 +01:00
point_size = p_point_size ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > point_size , p_point_size ) ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
float SpatialMaterial : : get_point_size ( ) const {
2016-10-30 01:48:09 +02:00
return point_size ;
}
2014-02-10 02:10:30 +01:00
2017-07-08 13:06:13 +02:00
void SpatialMaterial : : set_uv1_scale ( const Vector3 & p_scale ) {
2017-03-05 16:44:50 +01:00
uv1_scale = p_scale ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > uv1_scale , p_scale ) ;
2016-11-21 02:49:53 +01:00
}
2014-02-10 02:10:30 +01:00
2017-07-08 13:06:13 +02:00
Vector3 SpatialMaterial : : get_uv1_scale ( ) const {
2016-11-21 02:49:53 +01:00
return uv1_scale ;
2014-02-10 02:10:30 +01:00
}
2017-07-08 13:06:13 +02:00
void SpatialMaterial : : set_uv1_offset ( const Vector3 & p_offset ) {
2017-03-05 16:44:50 +01:00
uv1_offset = p_offset ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > uv1_offset , p_offset ) ;
2014-02-10 02:10:30 +01:00
}
2017-07-08 13:06:13 +02:00
Vector3 SpatialMaterial : : get_uv1_offset ( ) const {
2016-11-21 02:49:53 +01:00
return uv1_offset ;
}
2014-02-10 02:10:30 +01:00
2017-07-08 13:06:13 +02:00
void SpatialMaterial : : set_uv1_triplanar_blend_sharpness ( float p_sharpness ) {
2022-02-27 18:58:22 +01:00
// Negative values or values higher than 150 can result in NaNs, leading to broken rendering.
uv1_triplanar_sharpness = CLAMP ( p_sharpness , 0.0 , 150.0 ) ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > uv1_blend_sharpness , uv1_triplanar_sharpness ) ;
2017-07-08 13:06:13 +02:00
}
float SpatialMaterial : : get_uv1_triplanar_blend_sharpness ( ) const {
return uv1_triplanar_sharpness ;
}
void SpatialMaterial : : set_uv2_scale ( const Vector3 & p_scale ) {
2017-03-05 16:44:50 +01:00
uv2_scale = p_scale ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > uv2_scale , p_scale ) ;
2014-02-10 02:10:30 +01:00
}
2017-07-08 13:06:13 +02:00
Vector3 SpatialMaterial : : get_uv2_scale ( ) const {
2016-11-21 02:49:53 +01:00
return uv2_scale ;
2014-02-10 02:10:30 +01:00
}
2017-07-08 13:06:13 +02:00
void SpatialMaterial : : set_uv2_offset ( const Vector3 & p_offset ) {
2017-03-05 16:44:50 +01:00
uv2_offset = p_offset ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > uv2_offset , p_offset ) ;
2014-02-10 02:10:30 +01:00
}
2017-07-08 13:06:13 +02:00
Vector3 SpatialMaterial : : get_uv2_offset ( ) const {
2016-11-21 02:49:53 +01:00
return uv2_offset ;
2014-02-10 02:10:30 +01:00
}
2017-07-08 13:06:13 +02:00
void SpatialMaterial : : set_uv2_triplanar_blend_sharpness ( float p_sharpness ) {
2022-02-27 18:58:22 +01:00
// Negative values or values higher than 150 can result in NaNs, leading to broken rendering.
uv2_triplanar_sharpness = CLAMP ( p_sharpness , 0.0 , 150.0 ) ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > uv2_blend_sharpness , uv2_triplanar_sharpness ) ;
2017-07-08 13:06:13 +02:00
}
float SpatialMaterial : : get_uv2_triplanar_blend_sharpness ( ) const {
return uv2_triplanar_sharpness ;
}
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : set_billboard_mode ( BillboardMode p_mode ) {
billboard_mode = p_mode ;
_queue_shader_change ( ) ;
_change_notify ( ) ;
}
SpatialMaterial : : BillboardMode SpatialMaterial : : get_billboard_mode ( ) const {
return billboard_mode ;
}
void SpatialMaterial : : set_particles_anim_h_frames ( int p_frames ) {
particles_anim_h_frames = p_frames ;
2017-08-17 15:49:17 +02:00
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > particles_anim_h_frames , p_frames ) ;
2017-04-07 04:36:37 +02:00
}
int SpatialMaterial : : get_particles_anim_h_frames ( ) const {
return particles_anim_h_frames ;
}
void SpatialMaterial : : set_particles_anim_v_frames ( int p_frames ) {
particles_anim_v_frames = p_frames ;
2017-08-17 15:49:17 +02:00
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > particles_anim_v_frames , p_frames ) ;
2017-04-07 04:36:37 +02:00
}
int SpatialMaterial : : get_particles_anim_v_frames ( ) const {
return particles_anim_v_frames ;
}
2014-02-10 02:10:30 +01:00
2018-09-27 13:05:57 +02:00
void SpatialMaterial : : set_particles_anim_loop ( bool p_loop ) {
particles_anim_loop = p_loop ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > particles_anim_loop , particles_anim_loop ) ;
2017-04-07 04:36:37 +02:00
}
2014-10-28 02:54:32 +01:00
2018-09-27 13:05:57 +02:00
bool SpatialMaterial : : get_particles_anim_loop ( ) const {
2017-04-07 04:36:37 +02:00
return particles_anim_loop ;
}
2014-02-10 02:10:30 +01:00
2017-06-04 23:08:06 +02:00
void SpatialMaterial : : set_depth_deep_parallax ( bool p_enable ) {
deep_parallax = p_enable ;
_queue_shader_change ( ) ;
_change_notify ( ) ;
}
bool SpatialMaterial : : is_depth_deep_parallax_enabled ( ) const {
return deep_parallax ;
}
void SpatialMaterial : : set_depth_deep_parallax_min_layers ( int p_layer ) {
deep_parallax_min_layers = p_layer ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > depth_min_layers , p_layer ) ;
}
int SpatialMaterial : : get_depth_deep_parallax_min_layers ( ) const {
return deep_parallax_min_layers ;
}
void SpatialMaterial : : set_depth_deep_parallax_max_layers ( int p_layer ) {
deep_parallax_max_layers = p_layer ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > depth_max_layers , p_layer ) ;
}
int SpatialMaterial : : get_depth_deep_parallax_max_layers ( ) const {
return deep_parallax_max_layers ;
}
2018-11-14 14:15:15 +01:00
void SpatialMaterial : : set_depth_deep_parallax_flip_tangent ( bool p_flip ) {
depth_parallax_flip_tangent = p_flip ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > depth_flip , Vector2 ( depth_parallax_flip_tangent ? - 1 : 1 , depth_parallax_flip_binormal ? - 1 : 1 ) ) ;
}
bool SpatialMaterial : : get_depth_deep_parallax_flip_tangent ( ) const {
return depth_parallax_flip_tangent ;
}
void SpatialMaterial : : set_depth_deep_parallax_flip_binormal ( bool p_flip ) {
depth_parallax_flip_binormal = p_flip ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > depth_flip , Vector2 ( depth_parallax_flip_tangent ? - 1 : 1 , depth_parallax_flip_binormal ? - 1 : 1 ) ) ;
}
bool SpatialMaterial : : get_depth_deep_parallax_flip_binormal ( ) const {
return depth_parallax_flip_binormal ;
}
2017-07-08 17:34:05 +02:00
void SpatialMaterial : : set_grow_enabled ( bool p_enable ) {
grow_enabled = p_enable ;
_queue_shader_change ( ) ;
_change_notify ( ) ;
}
bool SpatialMaterial : : is_grow_enabled ( ) const {
return grow_enabled ;
}
2018-02-21 17:30:55 +01:00
void SpatialMaterial : : set_alpha_scissor_threshold ( float p_threshold ) {
alpha_scissor_threshold = p_threshold ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > alpha_scissor_threshold , p_threshold ) ;
2017-08-08 22:23:44 +02:00
}
float SpatialMaterial : : get_alpha_scissor_threshold ( ) const {
return alpha_scissor_threshold ;
}
2017-07-08 17:34:05 +02:00
void SpatialMaterial : : set_grow ( float p_grow ) {
grow = p_grow ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > grow , p_grow ) ;
}
float SpatialMaterial : : get_grow ( ) const {
return grow ;
}
2017-08-02 20:34:55 +02:00
static Plane _get_texture_mask ( SpatialMaterial : : TextureChannel p_channel ) {
static const Plane masks [ 5 ] = {
Plane ( 1 , 0 , 0 , 0 ) ,
Plane ( 0 , 1 , 0 , 0 ) ,
Plane ( 0 , 0 , 1 , 0 ) ,
Plane ( 0 , 0 , 0 , 1 ) ,
Plane ( 0.3333333 , 0.3333333 , 0.3333333 , 0 ) ,
} ;
return masks [ p_channel ] ;
}
void SpatialMaterial : : set_metallic_texture_channel ( TextureChannel p_channel ) {
2017-08-17 23:26:57 +02:00
ERR_FAIL_INDEX ( p_channel , 5 ) ;
2017-08-02 20:34:55 +02:00
metallic_texture_channel = p_channel ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > metallic_texture_channel , _get_texture_mask ( p_channel ) ) ;
}
SpatialMaterial : : TextureChannel SpatialMaterial : : get_metallic_texture_channel ( ) const {
return metallic_texture_channel ;
}
void SpatialMaterial : : set_roughness_texture_channel ( TextureChannel p_channel ) {
2017-08-17 23:26:57 +02:00
ERR_FAIL_INDEX ( p_channel , 5 ) ;
2017-08-02 20:34:55 +02:00
roughness_texture_channel = p_channel ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > roughness_texture_channel , _get_texture_mask ( p_channel ) ) ;
}
SpatialMaterial : : TextureChannel SpatialMaterial : : get_roughness_texture_channel ( ) const {
return roughness_texture_channel ;
}
void SpatialMaterial : : set_ao_texture_channel ( TextureChannel p_channel ) {
2019-10-28 08:07:29 +01:00
ERR_FAIL_INDEX ( p_channel , 5 ) ;
2017-08-02 20:34:55 +02:00
ao_texture_channel = p_channel ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > ao_texture_channel , _get_texture_mask ( p_channel ) ) ;
}
SpatialMaterial : : TextureChannel SpatialMaterial : : get_ao_texture_channel ( ) const {
return ao_texture_channel ;
}
void SpatialMaterial : : set_refraction_texture_channel ( TextureChannel p_channel ) {
2019-10-28 08:07:29 +01:00
ERR_FAIL_INDEX ( p_channel , 5 ) ;
2017-08-02 20:34:55 +02:00
refraction_texture_channel = p_channel ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > refraction_texture_channel , _get_texture_mask ( p_channel ) ) ;
}
SpatialMaterial : : TextureChannel SpatialMaterial : : get_refraction_texture_channel ( ) const {
return refraction_texture_channel ;
}
2022-05-21 19:12:12 +02:00
RID SpatialMaterial : : get_material_rid_for_2d ( bool p_shaded , bool p_transparent , bool p_double_sided , bool p_cut_alpha , bool p_opaque_prepass , bool p_billboard , bool p_billboard_y , bool p_no_depth_test , bool p_fixed_size , bool p_sdf ) {
uint64_t hash = 0 ;
2021-05-05 12:44:11 +02:00
if ( p_shaded ) {
2022-05-21 19:12:12 +02:00
hash | = 1 < < 0 ;
2021-05-05 12:44:11 +02:00
}
if ( p_transparent ) {
2022-05-21 19:12:12 +02:00
hash | = 1 < < 1 ;
2021-05-05 12:44:11 +02:00
}
if ( p_cut_alpha ) {
2022-05-21 19:12:12 +02:00
hash | = 1 < < 2 ;
2021-05-05 12:44:11 +02:00
}
if ( p_opaque_prepass ) {
2022-05-21 19:12:12 +02:00
hash | = 1 < < 3 ;
2021-05-05 12:44:11 +02:00
}
if ( p_double_sided ) {
2022-05-21 19:12:12 +02:00
hash | = 1 < < 4 ;
2021-05-05 12:44:11 +02:00
}
if ( p_billboard ) {
2022-05-21 19:12:12 +02:00
hash | = 1 < < 5 ;
2021-05-05 12:44:11 +02:00
}
if ( p_billboard_y ) {
2022-05-21 19:12:12 +02:00
hash | = 1 < < 6 ;
}
if ( p_no_depth_test ) {
hash | = 1 < < 7 ;
}
if ( p_fixed_size ) {
hash | = 1 < < 8 ;
}
if ( p_sdf ) {
hash | = 1 < < 9 ;
2021-05-05 12:44:11 +02:00
}
2017-08-08 22:23:44 +02:00
2022-05-21 19:12:12 +02:00
if ( materials_for_2d . has ( hash ) ) {
return materials_for_2d [ hash ] - > get_rid ( ) ;
2017-08-08 22:23:44 +02:00
}
Ref < SpatialMaterial > material ;
material . instance ( ) ;
material - > set_flag ( FLAG_UNSHADED , ! p_shaded ) ;
material - > set_feature ( FEATURE_TRANSPARENT , p_transparent ) ;
material - > set_cull_mode ( p_double_sided ? CULL_DISABLED : CULL_BACK ) ;
material - > set_depth_draw_mode ( p_opaque_prepass ? DEPTH_DRAW_ALPHA_OPAQUE_PREPASS : DEPTH_DRAW_OPAQUE_ONLY ) ;
material - > set_flag ( FLAG_SRGB_VERTEX_COLOR , true ) ;
material - > set_flag ( FLAG_ALBEDO_FROM_VERTEX_COLOR , true ) ;
material - > set_flag ( FLAG_USE_ALPHA_SCISSOR , p_cut_alpha ) ;
2022-05-21 19:12:12 +02:00
material - > set_flag ( FLAG_DISABLE_DEPTH_TEST , p_no_depth_test ) ;
material - > set_flag ( FLAG_FIXED_SIZE , p_fixed_size ) ;
material - > set_flag ( FLAG_ALBEDO_TEXTURE_SDF , p_sdf ) ;
2019-10-23 13:22:37 +02:00
if ( p_billboard | | p_billboard_y ) {
material - > set_flag ( FLAG_BILLBOARD_KEEP_SCALE , true ) ;
material - > set_billboard_mode ( p_billboard_y ? BILLBOARD_FIXED_Y : BILLBOARD_ENABLED ) ;
2019-07-17 01:04:36 +02:00
}
2017-08-08 22:23:44 +02:00
2022-05-21 19:12:12 +02:00
materials_for_2d [ hash ] = material ;
2020-06-27 05:22:25 +02:00
// flush before using so we can access the shader right away
flush_changes ( ) ;
2017-08-08 22:23:44 +02:00
2022-05-21 19:12:12 +02:00
return materials_for_2d [ hash ] - > get_rid ( ) ;
2017-08-08 22:23:44 +02:00
}
2017-09-01 17:56:52 +02:00
void SpatialMaterial : : set_on_top_of_alpha ( ) {
set_feature ( FEATURE_TRANSPARENT , true ) ;
set_render_priority ( RENDER_PRIORITY_MAX ) ;
set_flag ( FLAG_DISABLE_DEPTH_TEST , true ) ;
}
2017-09-21 20:20:00 +02:00
void SpatialMaterial : : set_proximity_fade ( bool p_enable ) {
proximity_fade_enabled = p_enable ;
_queue_shader_change ( ) ;
_change_notify ( ) ;
}
bool SpatialMaterial : : is_proximity_fade_enabled ( ) const {
return proximity_fade_enabled ;
}
void SpatialMaterial : : set_proximity_fade_distance ( float p_distance ) {
proximity_fade_distance = p_distance ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > proximity_fade_distance , p_distance ) ;
}
float SpatialMaterial : : get_proximity_fade_distance ( ) const {
return proximity_fade_distance ;
}
2018-08-22 15:23:28 +02:00
void SpatialMaterial : : set_distance_fade ( DistanceFadeMode p_mode ) {
distance_fade = p_mode ;
2017-09-21 20:20:00 +02:00
_queue_shader_change ( ) ;
_change_notify ( ) ;
}
2018-08-22 15:23:28 +02:00
SpatialMaterial : : DistanceFadeMode SpatialMaterial : : get_distance_fade ( ) const {
return distance_fade ;
2017-09-21 20:20:00 +02:00
}
void SpatialMaterial : : set_distance_fade_max_distance ( float p_distance ) {
distance_fade_max_distance = p_distance ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > distance_fade_max , distance_fade_max_distance ) ;
}
float SpatialMaterial : : get_distance_fade_max_distance ( ) const {
return distance_fade_max_distance ;
}
void SpatialMaterial : : set_distance_fade_min_distance ( float p_distance ) {
distance_fade_min_distance = p_distance ;
VS : : get_singleton ( ) - > material_set_param ( _get_material ( ) , shader_names - > distance_fade_min , distance_fade_min_distance ) ;
}
float SpatialMaterial : : get_distance_fade_min_distance ( ) const {
return distance_fade_min_distance ;
}
2017-11-15 16:39:24 +01:00
void SpatialMaterial : : set_emission_operator ( EmissionOperator p_op ) {
2021-05-05 12:44:11 +02:00
if ( emission_op = = p_op ) {
2017-11-15 16:39:24 +01:00
return ;
2021-05-05 12:44:11 +02:00
}
2017-11-15 16:39:24 +01:00
emission_op = p_op ;
_queue_shader_change ( ) ;
}
SpatialMaterial : : EmissionOperator SpatialMaterial : : get_emission_operator ( ) const {
return emission_op ;
}
2017-09-22 14:20:28 +02:00
RID SpatialMaterial : : get_shader_rid ( ) const {
ERR_FAIL_COND_V ( ! shader_map . has ( current_key ) , RID ( ) ) ;
return shader_map [ current_key ] . shader ;
}
2017-12-06 23:43:22 +01:00
Shader : : Mode SpatialMaterial : : get_shader_mode ( ) const {
return Shader : : MODE_SPATIAL ;
}
2021-09-26 21:31:17 +02:00
void SpatialMaterial : : set_async_mode ( AsyncMode p_mode ) {
async_mode = p_mode ;
_queue_shader_change ( ) ;
_change_notify ( ) ;
}
SpatialMaterial : : AsyncMode SpatialMaterial : : get_async_mode ( ) const {
return async_mode ;
}
2017-04-07 04:36:37 +02:00
void SpatialMaterial : : _bind_methods ( ) {
ClassDB : : bind_method ( D_METHOD ( " set_albedo " , " albedo " ) , & SpatialMaterial : : set_albedo ) ;
ClassDB : : bind_method ( D_METHOD ( " get_albedo " ) , & SpatialMaterial : : get_albedo ) ;
2014-12-17 02:31:57 +01:00
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_specular " , " specular " ) , & SpatialMaterial : : set_specular ) ;
ClassDB : : bind_method ( D_METHOD ( " get_specular " ) , & SpatialMaterial : : get_specular ) ;
2016-10-27 16:50:26 +02:00
2017-06-01 01:16:38 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_metallic " , " metallic " ) , & SpatialMaterial : : set_metallic ) ;
ClassDB : : bind_method ( D_METHOD ( " get_metallic " ) , & SpatialMaterial : : get_metallic ) ;
2016-10-27 16:50:26 +02:00
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_roughness " , " roughness " ) , & SpatialMaterial : : set_roughness ) ;
ClassDB : : bind_method ( D_METHOD ( " get_roughness " ) , & SpatialMaterial : : get_roughness ) ;
2016-10-27 16:50:26 +02:00
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_emission " , " emission " ) , & SpatialMaterial : : set_emission ) ;
ClassDB : : bind_method ( D_METHOD ( " get_emission " ) , & SpatialMaterial : : get_emission ) ;
2016-10-27 16:50:26 +02:00
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_emission_energy " , " emission_energy " ) , & SpatialMaterial : : set_emission_energy ) ;
ClassDB : : bind_method ( D_METHOD ( " get_emission_energy " ) , & SpatialMaterial : : get_emission_energy ) ;
2016-10-27 16:50:26 +02:00
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_normal_scale " , " normal_scale " ) , & SpatialMaterial : : set_normal_scale ) ;
ClassDB : : bind_method ( D_METHOD ( " get_normal_scale " ) , & SpatialMaterial : : get_normal_scale ) ;
2016-10-27 16:50:26 +02:00
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_rim " , " rim " ) , & SpatialMaterial : : set_rim ) ;
ClassDB : : bind_method ( D_METHOD ( " get_rim " ) , & SpatialMaterial : : get_rim ) ;
2016-10-27 16:50:26 +02:00
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_rim_tint " , " rim_tint " ) , & SpatialMaterial : : set_rim_tint ) ;
ClassDB : : bind_method ( D_METHOD ( " get_rim_tint " ) , & SpatialMaterial : : get_rim_tint ) ;
2016-10-27 16:50:26 +02:00
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_clearcoat " , " clearcoat " ) , & SpatialMaterial : : set_clearcoat ) ;
ClassDB : : bind_method ( D_METHOD ( " get_clearcoat " ) , & SpatialMaterial : : get_clearcoat ) ;
2016-10-27 16:50:26 +02:00
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_clearcoat_gloss " , " clearcoat_gloss " ) , & SpatialMaterial : : set_clearcoat_gloss ) ;
ClassDB : : bind_method ( D_METHOD ( " get_clearcoat_gloss " ) , & SpatialMaterial : : get_clearcoat_gloss ) ;
2016-10-27 16:50:26 +02:00
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_anisotropy " , " anisotropy " ) , & SpatialMaterial : : set_anisotropy ) ;
ClassDB : : bind_method ( D_METHOD ( " get_anisotropy " ) , & SpatialMaterial : : get_anisotropy ) ;
2016-10-30 01:48:09 +02:00
2017-06-04 23:08:06 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_depth_scale " , " depth_scale " ) , & SpatialMaterial : : set_depth_scale ) ;
ClassDB : : bind_method ( D_METHOD ( " get_depth_scale " ) , & SpatialMaterial : : get_depth_scale ) ;
2016-10-30 01:48:09 +02:00
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_subsurface_scattering_strength " , " strength " ) , & SpatialMaterial : : set_subsurface_scattering_strength ) ;
ClassDB : : bind_method ( D_METHOD ( " get_subsurface_scattering_strength " ) , & SpatialMaterial : : get_subsurface_scattering_strength ) ;
2016-10-27 16:50:26 +02:00
2017-09-03 15:29:56 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_transmission " , " transmission " ) , & SpatialMaterial : : set_transmission ) ;
ClassDB : : bind_method ( D_METHOD ( " get_transmission " ) , & SpatialMaterial : : get_transmission ) ;
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_refraction " , " refraction " ) , & SpatialMaterial : : set_refraction ) ;
ClassDB : : bind_method ( D_METHOD ( " get_refraction " ) , & SpatialMaterial : : get_refraction ) ;
2016-10-27 16:50:26 +02:00
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_line_width " , " line_width " ) , & SpatialMaterial : : set_line_width ) ;
ClassDB : : bind_method ( D_METHOD ( " get_line_width " ) , & SpatialMaterial : : get_line_width ) ;
2016-10-27 16:50:26 +02:00
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_point_size " , " point_size " ) , & SpatialMaterial : : set_point_size ) ;
ClassDB : : bind_method ( D_METHOD ( " get_point_size " ) , & SpatialMaterial : : get_point_size ) ;
2016-10-27 16:50:26 +02:00
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_detail_uv " , " detail_uv " ) , & SpatialMaterial : : set_detail_uv ) ;
ClassDB : : bind_method ( D_METHOD ( " get_detail_uv " ) , & SpatialMaterial : : get_detail_uv ) ;
2016-10-27 16:50:26 +02:00
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_blend_mode " , " blend_mode " ) , & SpatialMaterial : : set_blend_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_blend_mode " ) , & SpatialMaterial : : get_blend_mode ) ;
2016-10-27 16:50:26 +02:00
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_depth_draw_mode " , " depth_draw_mode " ) , & SpatialMaterial : : set_depth_draw_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_depth_draw_mode " ) , & SpatialMaterial : : get_depth_draw_mode ) ;
2016-10-27 16:50:26 +02:00
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_cull_mode " , " cull_mode " ) , & SpatialMaterial : : set_cull_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_cull_mode " ) , & SpatialMaterial : : get_cull_mode ) ;
2016-10-27 16:50:26 +02:00
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_diffuse_mode " , " diffuse_mode " ) , & SpatialMaterial : : set_diffuse_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_diffuse_mode " ) , & SpatialMaterial : : get_diffuse_mode ) ;
2016-11-21 02:49:53 +01:00
2017-07-08 17:34:05 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_specular_mode " , " specular_mode " ) , & SpatialMaterial : : set_specular_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_specular_mode " ) , & SpatialMaterial : : get_specular_mode ) ;
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_flag " , " flag " , " enable " ) , & SpatialMaterial : : set_flag ) ;
2017-07-22 12:11:42 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_flag " , " flag " ) , & SpatialMaterial : : get_flag ) ;
2016-11-21 02:49:53 +01:00
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_feature " , " feature " , " enable " ) , & SpatialMaterial : : set_feature ) ;
ClassDB : : bind_method ( D_METHOD ( " get_feature " , " feature " ) , & SpatialMaterial : : get_feature ) ;
2017-08-09 13:19:41 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_texture " , " param " , " texture " ) , & SpatialMaterial : : set_texture ) ;
ClassDB : : bind_method ( D_METHOD ( " get_texture " , " param " ) , & SpatialMaterial : : get_texture ) ;
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_detail_blend_mode " , " detail_blend_mode " ) , & SpatialMaterial : : set_detail_blend_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_detail_blend_mode " ) , & SpatialMaterial : : get_detail_blend_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " set_uv1_scale " , " scale " ) , & SpatialMaterial : : set_uv1_scale ) ;
ClassDB : : bind_method ( D_METHOD ( " get_uv1_scale " ) , & SpatialMaterial : : get_uv1_scale ) ;
ClassDB : : bind_method ( D_METHOD ( " set_uv1_offset " , " offset " ) , & SpatialMaterial : : set_uv1_offset ) ;
ClassDB : : bind_method ( D_METHOD ( " get_uv1_offset " ) , & SpatialMaterial : : get_uv1_offset ) ;
2017-07-08 13:06:13 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_uv1_triplanar_blend_sharpness " , " sharpness " ) , & SpatialMaterial : : set_uv1_triplanar_blend_sharpness ) ;
ClassDB : : bind_method ( D_METHOD ( " get_uv1_triplanar_blend_sharpness " ) , & SpatialMaterial : : get_uv1_triplanar_blend_sharpness ) ;
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_uv2_scale " , " scale " ) , & SpatialMaterial : : set_uv2_scale ) ;
ClassDB : : bind_method ( D_METHOD ( " get_uv2_scale " ) , & SpatialMaterial : : get_uv2_scale ) ;
ClassDB : : bind_method ( D_METHOD ( " set_uv2_offset " , " offset " ) , & SpatialMaterial : : set_uv2_offset ) ;
ClassDB : : bind_method ( D_METHOD ( " get_uv2_offset " ) , & SpatialMaterial : : get_uv2_offset ) ;
2017-07-08 13:06:13 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_uv2_triplanar_blend_sharpness " , " sharpness " ) , & SpatialMaterial : : set_uv2_triplanar_blend_sharpness ) ;
ClassDB : : bind_method ( D_METHOD ( " get_uv2_triplanar_blend_sharpness " ) , & SpatialMaterial : : get_uv2_triplanar_blend_sharpness ) ;
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_billboard_mode " , " mode " ) , & SpatialMaterial : : set_billboard_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_billboard_mode " ) , & SpatialMaterial : : get_billboard_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " set_particles_anim_h_frames " , " frames " ) , & SpatialMaterial : : set_particles_anim_h_frames ) ;
ClassDB : : bind_method ( D_METHOD ( " get_particles_anim_h_frames " ) , & SpatialMaterial : : get_particles_anim_h_frames ) ;
ClassDB : : bind_method ( D_METHOD ( " set_particles_anim_v_frames " , " frames " ) , & SpatialMaterial : : set_particles_anim_v_frames ) ;
ClassDB : : bind_method ( D_METHOD ( " get_particles_anim_v_frames " ) , & SpatialMaterial : : get_particles_anim_v_frames ) ;
2018-09-27 13:05:57 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_particles_anim_loop " , " loop " ) , & SpatialMaterial : : set_particles_anim_loop ) ;
2017-04-07 04:36:37 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_particles_anim_loop " ) , & SpatialMaterial : : get_particles_anim_loop ) ;
2016-11-21 02:49:53 +01:00
2017-06-04 23:08:06 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_depth_deep_parallax " , " enable " ) , & SpatialMaterial : : set_depth_deep_parallax ) ;
ClassDB : : bind_method ( D_METHOD ( " is_depth_deep_parallax_enabled " ) , & SpatialMaterial : : is_depth_deep_parallax_enabled ) ;
ClassDB : : bind_method ( D_METHOD ( " set_depth_deep_parallax_min_layers " , " layer " ) , & SpatialMaterial : : set_depth_deep_parallax_min_layers ) ;
ClassDB : : bind_method ( D_METHOD ( " get_depth_deep_parallax_min_layers " ) , & SpatialMaterial : : get_depth_deep_parallax_min_layers ) ;
ClassDB : : bind_method ( D_METHOD ( " set_depth_deep_parallax_max_layers " , " layer " ) , & SpatialMaterial : : set_depth_deep_parallax_max_layers ) ;
ClassDB : : bind_method ( D_METHOD ( " get_depth_deep_parallax_max_layers " ) , & SpatialMaterial : : get_depth_deep_parallax_max_layers ) ;
2018-11-14 14:15:15 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_depth_deep_parallax_flip_tangent " , " flip " ) , & SpatialMaterial : : set_depth_deep_parallax_flip_tangent ) ;
ClassDB : : bind_method ( D_METHOD ( " get_depth_deep_parallax_flip_tangent " ) , & SpatialMaterial : : get_depth_deep_parallax_flip_tangent ) ;
ClassDB : : bind_method ( D_METHOD ( " set_depth_deep_parallax_flip_binormal " , " flip " ) , & SpatialMaterial : : set_depth_deep_parallax_flip_binormal ) ;
ClassDB : : bind_method ( D_METHOD ( " get_depth_deep_parallax_flip_binormal " ) , & SpatialMaterial : : get_depth_deep_parallax_flip_binormal ) ;
2017-07-08 17:34:05 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_grow " , " amount " ) , & SpatialMaterial : : set_grow ) ;
ClassDB : : bind_method ( D_METHOD ( " get_grow " ) , & SpatialMaterial : : get_grow ) ;
2017-11-15 16:39:24 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_emission_operator " , " operator " ) , & SpatialMaterial : : set_emission_operator ) ;
ClassDB : : bind_method ( D_METHOD ( " get_emission_operator " ) , & SpatialMaterial : : get_emission_operator ) ;
2017-09-24 04:10:34 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_ao_light_affect " , " amount " ) , & SpatialMaterial : : set_ao_light_affect ) ;
ClassDB : : bind_method ( D_METHOD ( " get_ao_light_affect " ) , & SpatialMaterial : : get_ao_light_affect ) ;
2017-08-08 22:23:44 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_alpha_scissor_threshold " , " threshold " ) , & SpatialMaterial : : set_alpha_scissor_threshold ) ;
ClassDB : : bind_method ( D_METHOD ( " get_alpha_scissor_threshold " ) , & SpatialMaterial : : get_alpha_scissor_threshold ) ;
2017-07-08 17:34:05 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_grow_enabled " , " enable " ) , & SpatialMaterial : : set_grow_enabled ) ;
ClassDB : : bind_method ( D_METHOD ( " is_grow_enabled " ) , & SpatialMaterial : : is_grow_enabled ) ;
2017-08-02 20:34:55 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_metallic_texture_channel " , " channel " ) , & SpatialMaterial : : set_metallic_texture_channel ) ;
ClassDB : : bind_method ( D_METHOD ( " get_metallic_texture_channel " ) , & SpatialMaterial : : get_metallic_texture_channel ) ;
ClassDB : : bind_method ( D_METHOD ( " set_roughness_texture_channel " , " channel " ) , & SpatialMaterial : : set_roughness_texture_channel ) ;
ClassDB : : bind_method ( D_METHOD ( " get_roughness_texture_channel " ) , & SpatialMaterial : : get_roughness_texture_channel ) ;
ClassDB : : bind_method ( D_METHOD ( " set_ao_texture_channel " , " channel " ) , & SpatialMaterial : : set_ao_texture_channel ) ;
ClassDB : : bind_method ( D_METHOD ( " get_ao_texture_channel " ) , & SpatialMaterial : : get_ao_texture_channel ) ;
ClassDB : : bind_method ( D_METHOD ( " set_refraction_texture_channel " , " channel " ) , & SpatialMaterial : : set_refraction_texture_channel ) ;
ClassDB : : bind_method ( D_METHOD ( " get_refraction_texture_channel " ) , & SpatialMaterial : : get_refraction_texture_channel ) ;
2017-09-21 20:20:00 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_proximity_fade " , " enabled " ) , & SpatialMaterial : : set_proximity_fade ) ;
ClassDB : : bind_method ( D_METHOD ( " is_proximity_fade_enabled " ) , & SpatialMaterial : : is_proximity_fade_enabled ) ;
ClassDB : : bind_method ( D_METHOD ( " set_proximity_fade_distance " , " distance " ) , & SpatialMaterial : : set_proximity_fade_distance ) ;
ClassDB : : bind_method ( D_METHOD ( " get_proximity_fade_distance " ) , & SpatialMaterial : : get_proximity_fade_distance ) ;
2018-08-22 15:23:28 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_distance_fade " , " mode " ) , & SpatialMaterial : : set_distance_fade ) ;
ClassDB : : bind_method ( D_METHOD ( " get_distance_fade " ) , & SpatialMaterial : : get_distance_fade ) ;
2017-09-21 20:20:00 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_distance_fade_max_distance " , " distance " ) , & SpatialMaterial : : set_distance_fade_max_distance ) ;
ClassDB : : bind_method ( D_METHOD ( " get_distance_fade_max_distance " ) , & SpatialMaterial : : get_distance_fade_max_distance ) ;
ClassDB : : bind_method ( D_METHOD ( " set_distance_fade_min_distance " , " distance " ) , & SpatialMaterial : : set_distance_fade_min_distance ) ;
ClassDB : : bind_method ( D_METHOD ( " get_distance_fade_min_distance " ) , & SpatialMaterial : : get_distance_fade_min_distance ) ;
2021-09-26 21:31:17 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_async_mode " , " mode " ) , & SpatialMaterial : : set_async_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_async_mode " ) , & SpatialMaterial : : get_async_mode ) ;
2017-03-05 16:44:50 +01:00
ADD_GROUP ( " Flags " , " flags_ " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " flags_transparent " ) , " set_feature " , " get_feature " , FEATURE_TRANSPARENT ) ;
2019-05-20 16:37:13 +02:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " flags_use_shadow_to_opacity " ) , " set_flag " , " get_flag " , FLAG_USE_SHADOW_TO_OPACITY ) ;
2017-03-05 16:44:50 +01:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " flags_unshaded " ) , " set_flag " , " get_flag " , FLAG_UNSHADED ) ;
2017-07-22 19:07:38 +02:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " flags_vertex_lighting " ) , " set_flag " , " get_flag " , FLAG_USE_VERTEX_LIGHTING ) ;
2017-09-01 17:56:52 +02:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " flags_no_depth_test " ) , " set_flag " , " get_flag " , FLAG_DISABLE_DEPTH_TEST ) ;
2017-03-05 16:44:50 +01:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " flags_use_point_size " ) , " set_flag " , " get_flag " , FLAG_USE_POINT_SIZE ) ;
2017-09-02 14:56:12 +02:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " flags_world_triplanar " ) , " set_flag " , " get_flag " , FLAG_TRIPLANAR_USE_WORLD ) ;
2017-04-07 04:36:37 +02:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " flags_fixed_size " ) , " set_flag " , " get_flag " , FLAG_FIXED_SIZE ) ;
2017-12-04 19:55:20 +01:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " flags_albedo_tex_force_srgb " ) , " set_flag " , " get_flag " , FLAG_ALBEDO_TEXTURE_FORCE_SRGB ) ;
2018-03-29 18:46:42 +02:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " flags_do_not_receive_shadows " ) , " set_flag " , " get_flag " , FLAG_DONT_RECEIVE_SHADOWS ) ;
2018-07-17 21:30:43 +02:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " flags_disable_ambient_light " ) , " set_flag " , " get_flag " , FLAG_DISABLE_AMBIENT_LIGHT ) ;
2018-06-21 00:12:12 +02:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " flags_ensure_correct_normals " ) , " set_flag " , " get_flag " , FLAG_ENSURE_CORRECT_NORMALS ) ;
2022-05-21 19:12:12 +02:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " flags_albedo_tex_msdf " ) , " set_flag " , " get_flag " , FLAG_ALBEDO_TEXTURE_SDF ) ;
2017-03-05 16:44:50 +01:00
ADD_GROUP ( " Vertex Color " , " vertex_color " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " vertex_color_use_as_albedo " ) , " set_flag " , " get_flag " , FLAG_ALBEDO_FROM_VERTEX_COLOR ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " vertex_color_is_srgb " ) , " set_flag " , " get_flag " , FLAG_SRGB_VERTEX_COLOR ) ;
ADD_GROUP ( " Parameters " , " params_ " ) ;
2017-10-02 00:08:49 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " params_diffuse_mode " , PROPERTY_HINT_ENUM , " Burley,Lambert,Lambert Wrap,Oren Nayar,Toon " ) , " set_diffuse_mode " , " get_diffuse_mode " ) ;
2017-10-23 07:42:36 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " params_specular_mode " , PROPERTY_HINT_ENUM , " SchlickGGX,Blinn,Phong,Toon,Disabled " ) , " set_specular_mode " , " get_specular_mode " ) ;
2017-03-05 16:44:50 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " params_blend_mode " , PROPERTY_HINT_ENUM , " Mix,Add,Sub,Mul " ) , " set_blend_mode " , " get_blend_mode " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " params_cull_mode " , PROPERTY_HINT_ENUM , " Back,Front,Disabled " ) , " set_cull_mode " , " get_cull_mode " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " params_depth_draw_mode " , PROPERTY_HINT_ENUM , " Opaque Only,Always,Never,Opaque Pre-Pass " ) , " set_depth_draw_mode " , " get_depth_draw_mode " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " params_line_width " , PROPERTY_HINT_RANGE , " 0.1,128,0.1 " ) , " set_line_width " , " get_line_width " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " params_point_size " , PROPERTY_HINT_RANGE , " 0.1,128,0.1 " ) , " set_point_size " , " get_point_size " ) ;
2018-08-21 06:35:48 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " params_billboard_mode " , PROPERTY_HINT_ENUM , " Disabled,Enabled,Y-Billboard,Particle Billboard " ) , " set_billboard_mode " , " get_billboard_mode " ) ;
2018-04-22 12:11:05 +02:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " params_billboard_keep_scale " ) , " set_flag " , " get_flag " , FLAG_BILLBOARD_KEEP_SCALE ) ;
2017-07-08 17:34:05 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " params_grow " ) , " set_grow_enabled " , " is_grow_enabled " ) ;
2019-06-16 23:47:50 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " params_grow_amount " , PROPERTY_HINT_RANGE , " -16,16,0.001 " ) , " set_grow " , " get_grow " ) ;
2017-08-08 22:23:44 +02:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " params_use_alpha_scissor " ) , " set_flag " , " get_flag " , FLAG_USE_ALPHA_SCISSOR ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " params_alpha_scissor_threshold " , PROPERTY_HINT_RANGE , " 0,1,0.01 " ) , " set_alpha_scissor_threshold " , " get_alpha_scissor_threshold " ) ;
2017-04-07 04:36:37 +02:00
ADD_GROUP ( " Particles Anim " , " particles_anim_ " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " particles_anim_h_frames " , PROPERTY_HINT_RANGE , " 1,128,1 " ) , " set_particles_anim_h_frames " , " get_particles_anim_h_frames " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " particles_anim_v_frames " , PROPERTY_HINT_RANGE , " 1,128,1 " ) , " set_particles_anim_v_frames " , " get_particles_anim_v_frames " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " particles_anim_loop " ) , " set_particles_anim_loop " , " get_particles_anim_loop " ) ;
2017-03-05 16:44:50 +01:00
ADD_GROUP ( " Albedo " , " albedo_ " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : COLOR , " albedo_color " ) , " set_albedo " , " get_albedo " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : OBJECT , " albedo_texture " , PROPERTY_HINT_RESOURCE_TYPE , " Texture " ) , " set_texture " , " get_texture " , TEXTURE_ALBEDO ) ;
2017-06-01 01:16:38 +02:00
ADD_GROUP ( " Metallic " , " metallic_ " ) ;
2017-06-25 23:57:28 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " metallic " , PROPERTY_HINT_RANGE , " 0,1,0.01 " ) , " set_metallic " , " get_metallic " ) ;
2017-06-01 01:16:38 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " metallic_specular " , PROPERTY_HINT_RANGE , " 0,1,0.01 " ) , " set_specular " , " get_specular " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : OBJECT , " metallic_texture " , PROPERTY_HINT_RESOURCE_TYPE , " Texture " ) , " set_texture " , " get_texture " , TEXTURE_METALLIC ) ;
2017-08-02 20:34:55 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " metallic_texture_channel " , PROPERTY_HINT_ENUM , " Red,Green,Blue,Alpha,Gray " ) , " set_metallic_texture_channel " , " get_metallic_texture_channel " ) ;
2017-06-01 01:16:38 +02:00
ADD_GROUP ( " Roughness " , " roughness_ " ) ;
2017-06-25 23:57:28 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " roughness " , PROPERTY_HINT_RANGE , " 0,1,0.01 " ) , " set_roughness " , " get_roughness " ) ;
2017-06-01 01:16:38 +02:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : OBJECT , " roughness_texture " , PROPERTY_HINT_RESOURCE_TYPE , " Texture " ) , " set_texture " , " get_texture " , TEXTURE_ROUGHNESS ) ;
2017-08-02 20:34:55 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " roughness_texture_channel " , PROPERTY_HINT_ENUM , " Red,Green,Blue,Alpha,Gray " ) , " set_roughness_texture_channel " , " get_roughness_texture_channel " ) ;
2017-03-05 16:44:50 +01:00
ADD_GROUP ( " Emission " , " emission_ " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " emission_enabled " ) , " set_feature " , " get_feature " , FEATURE_EMISSION ) ;
2017-06-25 23:57:28 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : COLOR , " emission " , PROPERTY_HINT_COLOR_NO_ALPHA ) , " set_emission " , " get_emission " ) ;
2019-06-16 23:47:50 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " emission_energy " , PROPERTY_HINT_RANGE , " 0,16,0.01,or_greater " ) , " set_emission_energy " , " get_emission_energy " ) ;
2017-11-15 16:39:24 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " emission_operator " , PROPERTY_HINT_ENUM , " Add,Multiply " ) , " set_emission_operator " , " get_emission_operator " ) ;
2017-12-14 12:59:46 +01:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " emission_on_uv2 " ) , " set_flag " , " get_flag " , FLAG_EMISSION_ON_UV2 ) ;
2017-03-05 16:44:50 +01:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : OBJECT , " emission_texture " , PROPERTY_HINT_RESOURCE_TYPE , " Texture " ) , " set_texture " , " get_texture " , TEXTURE_EMISSION ) ;
2017-04-06 23:18:09 +02:00
ADD_GROUP ( " NormalMap " , " normal_ " ) ;
2017-03-05 16:44:50 +01:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " normal_enabled " ) , " set_feature " , " get_feature " , FEATURE_NORMAL_MAPPING ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " normal_scale " , PROPERTY_HINT_RANGE , " -16,16,0.01 " ) , " set_normal_scale " , " get_normal_scale " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : OBJECT , " normal_texture " , PROPERTY_HINT_RESOURCE_TYPE , " Texture " ) , " set_texture " , " get_texture " , TEXTURE_NORMAL ) ;
ADD_GROUP ( " Rim " , " rim_ " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " rim_enabled " ) , " set_feature " , " get_feature " , FEATURE_RIM ) ;
2017-06-25 23:57:28 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " rim " , PROPERTY_HINT_RANGE , " 0,1,0.01 " ) , " set_rim " , " get_rim " ) ;
2017-03-05 16:44:50 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " rim_tint " , PROPERTY_HINT_RANGE , " 0,1,0.01 " ) , " set_rim_tint " , " get_rim_tint " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : OBJECT , " rim_texture " , PROPERTY_HINT_RESOURCE_TYPE , " Texture " ) , " set_texture " , " get_texture " , TEXTURE_RIM ) ;
ADD_GROUP ( " Clearcoat " , " clearcoat_ " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " clearcoat_enabled " ) , " set_feature " , " get_feature " , FEATURE_CLEARCOAT ) ;
2017-06-25 23:57:28 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " clearcoat " , PROPERTY_HINT_RANGE , " 0,1,0.01 " ) , " set_clearcoat " , " get_clearcoat " ) ;
2017-03-05 16:44:50 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " clearcoat_gloss " , PROPERTY_HINT_RANGE , " 0,1,0.01 " ) , " set_clearcoat_gloss " , " get_clearcoat_gloss " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : OBJECT , " clearcoat_texture " , PROPERTY_HINT_RESOURCE_TYPE , " Texture " ) , " set_texture " , " get_texture " , TEXTURE_CLEARCOAT ) ;
ADD_GROUP ( " Anisotropy " , " anisotropy_ " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " anisotropy_enabled " ) , " set_feature " , " get_feature " , FEATURE_ANISOTROPY ) ;
2017-07-03 15:44:45 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " anisotropy " , PROPERTY_HINT_RANGE , " -1,1,0.01 " ) , " set_anisotropy " , " get_anisotropy " ) ;
2017-03-05 16:44:50 +01:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : OBJECT , " anisotropy_flowmap " , PROPERTY_HINT_RESOURCE_TYPE , " Texture " ) , " set_texture " , " get_texture " , TEXTURE_FLOWMAP ) ;
ADD_GROUP ( " Ambient Occlusion " , " ao_ " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " ao_enabled " ) , " set_feature " , " get_feature " , FEATURE_AMBIENT_OCCLUSION ) ;
2017-09-24 04:10:34 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " ao_light_affect " , PROPERTY_HINT_RANGE , " 0,1,0.01 " ) , " set_ao_light_affect " , " get_ao_light_affect " ) ;
2017-03-05 16:44:50 +01:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : OBJECT , " ao_texture " , PROPERTY_HINT_RESOURCE_TYPE , " Texture " ) , " set_texture " , " get_texture " , TEXTURE_AMBIENT_OCCLUSION ) ;
2017-07-08 13:06:13 +02:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " ao_on_uv2 " ) , " set_flag " , " get_flag " , FLAG_AO_ON_UV2 ) ;
2017-08-02 20:34:55 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " ao_texture_channel " , PROPERTY_HINT_ENUM , " Red,Green,Blue,Alpha,Gray " ) , " set_ao_texture_channel " , " get_ao_texture_channel " ) ;
2017-03-05 16:44:50 +01:00
2017-06-04 23:08:06 +02:00
ADD_GROUP ( " Depth " , " depth_ " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " depth_enabled " ) , " set_feature " , " get_feature " , FEATURE_DEPTH_MAPPING ) ;
2020-12-05 21:44:39 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " depth_scale " , PROPERTY_HINT_RANGE , " -16,16,0.001 " ) , " set_depth_scale " , " get_depth_scale " ) ;
2017-06-04 23:08:06 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " depth_deep_parallax " ) , " set_depth_deep_parallax " , " is_depth_deep_parallax_enabled " ) ;
2020-12-05 21:44:39 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " depth_min_layers " , PROPERTY_HINT_RANGE , " 1,64,1 " ) , " set_depth_deep_parallax_min_layers " , " get_depth_deep_parallax_min_layers " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " depth_max_layers " , PROPERTY_HINT_RANGE , " 1,64,1 " ) , " set_depth_deep_parallax_max_layers " , " get_depth_deep_parallax_max_layers " ) ;
2018-11-14 14:15:15 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " depth_flip_tangent " ) , " set_depth_deep_parallax_flip_tangent " , " get_depth_deep_parallax_flip_tangent " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " depth_flip_binormal " ) , " set_depth_deep_parallax_flip_binormal " , " get_depth_deep_parallax_flip_binormal " ) ;
2017-06-04 23:08:06 +02:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : OBJECT , " depth_texture " , PROPERTY_HINT_RESOURCE_TYPE , " Texture " ) , " set_texture " , " get_texture " , TEXTURE_DEPTH ) ;
2017-03-05 16:44:50 +01:00
ADD_GROUP ( " Subsurf Scatter " , " subsurf_scatter_ " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " subsurf_scatter_enabled " ) , " set_feature " , " get_feature " , FEATURE_SUBSURACE_SCATTERING ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " subsurf_scatter_strength " , PROPERTY_HINT_RANGE , " 0,1,0.01 " ) , " set_subsurface_scattering_strength " , " get_subsurface_scattering_strength " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : OBJECT , " subsurf_scatter_texture " , PROPERTY_HINT_RESOURCE_TYPE , " Texture " ) , " set_texture " , " get_texture " , TEXTURE_SUBSURFACE_SCATTERING ) ;
2017-09-03 15:29:56 +02:00
ADD_GROUP ( " Transmission " , " transmission_ " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " transmission_enabled " ) , " set_feature " , " get_feature " , FEATURE_TRANSMISSION ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : COLOR , " transmission " , PROPERTY_HINT_COLOR_NO_ALPHA ) , " set_transmission " , " get_transmission " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : OBJECT , " transmission_texture " , PROPERTY_HINT_RESOURCE_TYPE , " Texture " ) , " set_texture " , " get_texture " , TEXTURE_TRANSMISSION ) ;
2017-03-05 16:44:50 +01:00
ADD_GROUP ( " Refraction " , " refraction_ " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " refraction_enabled " ) , " set_feature " , " get_feature " , FEATURE_REFRACTION ) ;
2017-06-06 03:33:01 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " refraction_scale " , PROPERTY_HINT_RANGE , " -1,1,0.01 " ) , " set_refraction " , " get_refraction " ) ;
2017-03-05 16:44:50 +01:00
ADD_PROPERTYI ( PropertyInfo ( Variant : : OBJECT , " refraction_texture " , PROPERTY_HINT_RESOURCE_TYPE , " Texture " ) , " set_texture " , " get_texture " , TEXTURE_REFRACTION ) ;
2017-08-02 20:34:55 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " refraction_texture_channel " , PROPERTY_HINT_ENUM , " Red,Green,Blue,Alpha,Gray " ) , " set_refraction_texture_channel " , " get_refraction_texture_channel " ) ;
2017-03-05 16:44:50 +01:00
ADD_GROUP ( " Detail " , " detail_ " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " detail_enabled " ) , " set_feature " , " get_feature " , FEATURE_DETAIL ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : OBJECT , " detail_mask " , PROPERTY_HINT_RESOURCE_TYPE , " Texture " ) , " set_texture " , " get_texture " , TEXTURE_DETAIL_MASK ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " detail_blend_mode " , PROPERTY_HINT_ENUM , " Mix,Add,Sub,Mul " ) , " set_detail_blend_mode " , " get_detail_blend_mode " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " detail_uv_layer " , PROPERTY_HINT_ENUM , " UV1,UV2 " ) , " set_detail_uv " , " get_detail_uv " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : OBJECT , " detail_albedo " , PROPERTY_HINT_RESOURCE_TYPE , " Texture " ) , " set_texture " , " get_texture " , TEXTURE_DETAIL_ALBEDO ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : OBJECT , " detail_normal " , PROPERTY_HINT_RESOURCE_TYPE , " Texture " ) , " set_texture " , " get_texture " , TEXTURE_DETAIL_NORMAL ) ;
ADD_GROUP ( " UV1 " , " uv1_ " ) ;
2017-07-08 13:06:13 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR3 , " uv1_scale " ) , " set_uv1_scale " , " get_uv1_scale " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR3 , " uv1_offset " ) , " set_uv1_offset " , " get_uv1_offset " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " uv1_triplanar " ) , " set_flag " , " get_flag " , FLAG_UV1_USE_TRIPLANAR ) ;
2017-07-08 17:34:05 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " uv1_triplanar_sharpness " , PROPERTY_HINT_EXP_EASING ) , " set_uv1_triplanar_blend_sharpness " , " get_uv1_triplanar_blend_sharpness " ) ;
2017-03-05 16:44:50 +01:00
ADD_GROUP ( " UV2 " , " uv2_ " ) ;
2017-07-08 13:06:13 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR3 , " uv2_scale " ) , " set_uv2_scale " , " get_uv2_scale " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : VECTOR3 , " uv2_offset " ) , " set_uv2_offset " , " get_uv2_offset " ) ;
ADD_PROPERTYI ( PropertyInfo ( Variant : : BOOL , " uv2_triplanar " ) , " set_flag " , " get_flag " , FLAG_UV2_USE_TRIPLANAR ) ;
2017-07-08 17:34:05 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " uv2_triplanar_sharpness " , PROPERTY_HINT_EXP_EASING ) , " set_uv2_triplanar_blend_sharpness " , " get_uv2_triplanar_blend_sharpness " ) ;
2017-03-05 16:44:50 +01:00
2017-09-21 20:20:00 +02:00
ADD_GROUP ( " Proximity Fade " , " proximity_fade_ " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " proximity_fade_enable " ) , " set_proximity_fade " , " is_proximity_fade_enabled " ) ;
2019-06-16 23:47:50 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " proximity_fade_distance " , PROPERTY_HINT_RANGE , " 0,4096,0.01 " ) , " set_proximity_fade_distance " , " get_proximity_fade_distance " ) ;
2017-09-21 20:20:00 +02:00
ADD_GROUP ( " Distance Fade " , " distance_fade_ " ) ;
2018-08-22 15:23:28 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " distance_fade_mode " , PROPERTY_HINT_ENUM , " Disabled,PixelAlpha,PixelDither,ObjectDither " ) , " set_distance_fade " , " get_distance_fade " ) ;
2019-06-16 23:47:50 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " distance_fade_min_distance " , PROPERTY_HINT_RANGE , " 0,4096,0.01 " ) , " set_distance_fade_min_distance " , " get_distance_fade_min_distance " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : REAL , " distance_fade_max_distance " , PROPERTY_HINT_RANGE , " 0,4096,0.01 " ) , " set_distance_fade_max_distance " , " get_distance_fade_max_distance " ) ;
2017-09-21 20:20:00 +02:00
2021-09-26 21:31:17 +02:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " async_mode " , PROPERTY_HINT_ENUM , " Visible,Hidden " ) , " set_async_mode " , " get_async_mode " ) ;
2017-08-20 17:45:01 +02:00
BIND_ENUM_CONSTANT ( TEXTURE_ALBEDO ) ;
BIND_ENUM_CONSTANT ( TEXTURE_METALLIC ) ;
BIND_ENUM_CONSTANT ( TEXTURE_ROUGHNESS ) ;
BIND_ENUM_CONSTANT ( TEXTURE_EMISSION ) ;
BIND_ENUM_CONSTANT ( TEXTURE_NORMAL ) ;
BIND_ENUM_CONSTANT ( TEXTURE_RIM ) ;
BIND_ENUM_CONSTANT ( TEXTURE_CLEARCOAT ) ;
BIND_ENUM_CONSTANT ( TEXTURE_FLOWMAP ) ;
BIND_ENUM_CONSTANT ( TEXTURE_AMBIENT_OCCLUSION ) ;
BIND_ENUM_CONSTANT ( TEXTURE_DEPTH ) ;
BIND_ENUM_CONSTANT ( TEXTURE_SUBSURFACE_SCATTERING ) ;
2017-09-03 15:29:56 +02:00
BIND_ENUM_CONSTANT ( TEXTURE_TRANSMISSION ) ;
2017-08-20 17:45:01 +02:00
BIND_ENUM_CONSTANT ( TEXTURE_REFRACTION ) ;
BIND_ENUM_CONSTANT ( TEXTURE_DETAIL_MASK ) ;
BIND_ENUM_CONSTANT ( TEXTURE_DETAIL_ALBEDO ) ;
BIND_ENUM_CONSTANT ( TEXTURE_DETAIL_NORMAL ) ;
BIND_ENUM_CONSTANT ( TEXTURE_MAX ) ;
BIND_ENUM_CONSTANT ( DETAIL_UV_1 ) ;
BIND_ENUM_CONSTANT ( DETAIL_UV_2 ) ;
BIND_ENUM_CONSTANT ( FEATURE_TRANSPARENT ) ;
BIND_ENUM_CONSTANT ( FEATURE_EMISSION ) ;
BIND_ENUM_CONSTANT ( FEATURE_NORMAL_MAPPING ) ;
BIND_ENUM_CONSTANT ( FEATURE_RIM ) ;
BIND_ENUM_CONSTANT ( FEATURE_CLEARCOAT ) ;
BIND_ENUM_CONSTANT ( FEATURE_ANISOTROPY ) ;
BIND_ENUM_CONSTANT ( FEATURE_AMBIENT_OCCLUSION ) ;
BIND_ENUM_CONSTANT ( FEATURE_DEPTH_MAPPING ) ;
BIND_ENUM_CONSTANT ( FEATURE_SUBSURACE_SCATTERING ) ;
2017-09-03 15:29:56 +02:00
BIND_ENUM_CONSTANT ( FEATURE_TRANSMISSION ) ;
2017-08-20 17:45:01 +02:00
BIND_ENUM_CONSTANT ( FEATURE_REFRACTION ) ;
BIND_ENUM_CONSTANT ( FEATURE_DETAIL ) ;
BIND_ENUM_CONSTANT ( FEATURE_MAX ) ;
BIND_ENUM_CONSTANT ( BLEND_MODE_MIX ) ;
BIND_ENUM_CONSTANT ( BLEND_MODE_ADD ) ;
BIND_ENUM_CONSTANT ( BLEND_MODE_SUB ) ;
BIND_ENUM_CONSTANT ( BLEND_MODE_MUL ) ;
BIND_ENUM_CONSTANT ( DEPTH_DRAW_OPAQUE_ONLY ) ;
BIND_ENUM_CONSTANT ( DEPTH_DRAW_ALWAYS ) ;
BIND_ENUM_CONSTANT ( DEPTH_DRAW_DISABLED ) ;
BIND_ENUM_CONSTANT ( DEPTH_DRAW_ALPHA_OPAQUE_PREPASS ) ;
BIND_ENUM_CONSTANT ( CULL_BACK ) ;
BIND_ENUM_CONSTANT ( CULL_FRONT ) ;
BIND_ENUM_CONSTANT ( CULL_DISABLED ) ;
BIND_ENUM_CONSTANT ( FLAG_UNSHADED ) ;
BIND_ENUM_CONSTANT ( FLAG_USE_VERTEX_LIGHTING ) ;
2017-09-01 17:56:52 +02:00
BIND_ENUM_CONSTANT ( FLAG_DISABLE_DEPTH_TEST ) ;
2017-08-20 17:45:01 +02:00
BIND_ENUM_CONSTANT ( FLAG_ALBEDO_FROM_VERTEX_COLOR ) ;
BIND_ENUM_CONSTANT ( FLAG_SRGB_VERTEX_COLOR ) ;
BIND_ENUM_CONSTANT ( FLAG_USE_POINT_SIZE ) ;
BIND_ENUM_CONSTANT ( FLAG_FIXED_SIZE ) ;
2018-04-22 12:11:05 +02:00
BIND_ENUM_CONSTANT ( FLAG_BILLBOARD_KEEP_SCALE ) ;
2017-08-20 17:45:01 +02:00
BIND_ENUM_CONSTANT ( FLAG_UV1_USE_TRIPLANAR ) ;
BIND_ENUM_CONSTANT ( FLAG_UV2_USE_TRIPLANAR ) ;
BIND_ENUM_CONSTANT ( FLAG_AO_ON_UV2 ) ;
2017-12-14 12:59:46 +01:00
BIND_ENUM_CONSTANT ( FLAG_EMISSION_ON_UV2 ) ;
2017-08-20 17:45:01 +02:00
BIND_ENUM_CONSTANT ( FLAG_USE_ALPHA_SCISSOR ) ;
2017-09-02 14:56:12 +02:00
BIND_ENUM_CONSTANT ( FLAG_TRIPLANAR_USE_WORLD ) ;
2017-12-04 19:55:20 +01:00
BIND_ENUM_CONSTANT ( FLAG_ALBEDO_TEXTURE_FORCE_SRGB ) ;
2018-03-29 18:46:42 +02:00
BIND_ENUM_CONSTANT ( FLAG_DONT_RECEIVE_SHADOWS ) ;
2018-07-17 21:30:43 +02:00
BIND_ENUM_CONSTANT ( FLAG_DISABLE_AMBIENT_LIGHT ) ;
2018-06-21 00:12:12 +02:00
BIND_ENUM_CONSTANT ( FLAG_ENSURE_CORRECT_NORMALS ) ;
2019-05-20 16:37:13 +02:00
BIND_ENUM_CONSTANT ( FLAG_USE_SHADOW_TO_OPACITY ) ;
2022-05-21 19:12:12 +02:00
BIND_ENUM_CONSTANT ( FLAG_ALBEDO_TEXTURE_SDF ) ;
2017-08-20 17:45:01 +02:00
BIND_ENUM_CONSTANT ( FLAG_MAX ) ;
2017-10-02 00:08:49 +02:00
BIND_ENUM_CONSTANT ( DIFFUSE_BURLEY ) ;
2017-08-20 17:45:01 +02:00
BIND_ENUM_CONSTANT ( DIFFUSE_LAMBERT ) ;
2017-09-03 15:29:56 +02:00
BIND_ENUM_CONSTANT ( DIFFUSE_LAMBERT_WRAP ) ;
2017-08-20 17:45:01 +02:00
BIND_ENUM_CONSTANT ( DIFFUSE_OREN_NAYAR ) ;
BIND_ENUM_CONSTANT ( DIFFUSE_TOON ) ;
2017-10-23 07:42:36 +02:00
BIND_ENUM_CONSTANT ( SPECULAR_SCHLICK_GGX ) ;
2017-08-20 17:45:01 +02:00
BIND_ENUM_CONSTANT ( SPECULAR_BLINN ) ;
BIND_ENUM_CONSTANT ( SPECULAR_PHONG ) ;
BIND_ENUM_CONSTANT ( SPECULAR_TOON ) ;
BIND_ENUM_CONSTANT ( SPECULAR_DISABLED ) ;
BIND_ENUM_CONSTANT ( BILLBOARD_DISABLED ) ;
BIND_ENUM_CONSTANT ( BILLBOARD_ENABLED ) ;
BIND_ENUM_CONSTANT ( BILLBOARD_FIXED_Y ) ;
BIND_ENUM_CONSTANT ( BILLBOARD_PARTICLES ) ;
BIND_ENUM_CONSTANT ( TEXTURE_CHANNEL_RED ) ;
BIND_ENUM_CONSTANT ( TEXTURE_CHANNEL_GREEN ) ;
BIND_ENUM_CONSTANT ( TEXTURE_CHANNEL_BLUE ) ;
BIND_ENUM_CONSTANT ( TEXTURE_CHANNEL_ALPHA ) ;
BIND_ENUM_CONSTANT ( TEXTURE_CHANNEL_GRAYSCALE ) ;
2017-11-15 16:39:24 +01:00
BIND_ENUM_CONSTANT ( EMISSION_OP_ADD ) ;
BIND_ENUM_CONSTANT ( EMISSION_OP_MULTIPLY ) ;
2018-08-22 15:23:28 +02:00
BIND_ENUM_CONSTANT ( DISTANCE_FADE_DISABLED ) ;
BIND_ENUM_CONSTANT ( DISTANCE_FADE_PIXEL_ALPHA ) ;
BIND_ENUM_CONSTANT ( DISTANCE_FADE_PIXEL_DITHER ) ;
BIND_ENUM_CONSTANT ( DISTANCE_FADE_OBJECT_DITHER ) ;
2021-09-26 21:31:17 +02:00
BIND_ENUM_CONSTANT ( ASYNC_MODE_VISIBLE ) ;
BIND_ENUM_CONSTANT ( ASYNC_MODE_HIDDEN ) ;
2017-03-05 16:44:50 +01:00
}
2017-12-06 21:36:34 +01:00
SpatialMaterial : : SpatialMaterial ( ) :
element ( this ) {
2018-08-07 17:00:56 +02:00
// Initialize to the same values as the shader
2017-08-09 10:11:36 +02:00
set_albedo ( Color ( 1.0 , 1.0 , 1.0 , 1.0 ) ) ;
2017-06-01 01:16:38 +02:00
set_specular ( 0.5 ) ;
2018-08-07 17:00:56 +02:00
set_roughness ( 1.0 ) ;
2017-08-09 10:11:36 +02:00
set_metallic ( 0.0 ) ;
2017-03-05 16:44:50 +01:00
set_emission ( Color ( 0 , 0 , 0 ) ) ;
2016-11-21 02:49:53 +01:00
set_emission_energy ( 1.0 ) ;
2016-10-27 16:50:26 +02:00
set_normal_scale ( 1 ) ;
2016-11-21 02:49:53 +01:00
set_rim ( 1.0 ) ;
set_rim_tint ( 0.5 ) ;
set_clearcoat ( 1 ) ;
2016-10-27 16:50:26 +02:00
set_clearcoat_gloss ( 0.5 ) ;
set_anisotropy ( 0 ) ;
2017-06-04 23:08:06 +02:00
set_depth_scale ( 0.05 ) ;
2016-12-03 02:23:16 +01:00
set_subsurface_scattering_strength ( 0 ) ;
2017-09-03 15:29:56 +02:00
set_transmission ( Color ( 0 , 0 , 0 ) ) ;
2017-06-06 03:33:01 +02:00
set_refraction ( 0.05 ) ;
2016-10-30 01:48:09 +02:00
set_line_width ( 1 ) ;
set_point_size ( 1 ) ;
2017-07-08 13:06:13 +02:00
set_uv1_offset ( Vector3 ( 0 , 0 , 0 ) ) ;
set_uv1_scale ( Vector3 ( 1 , 1 , 1 ) ) ;
set_uv1_triplanar_blend_sharpness ( 1 ) ;
set_uv2_offset ( Vector3 ( 0 , 0 , 0 ) ) ;
set_uv2_scale ( Vector3 ( 1 , 1 , 1 ) ) ;
set_uv2_triplanar_blend_sharpness ( 1 ) ;
2017-04-07 04:36:37 +02:00
set_billboard_mode ( BILLBOARD_DISABLED ) ;
set_particles_anim_h_frames ( 1 ) ;
set_particles_anim_v_frames ( 1 ) ;
set_particles_anim_loop ( false ) ;
2017-08-08 22:23:44 +02:00
set_alpha_scissor_threshold ( 0.98 ) ;
2017-11-15 16:39:24 +01:00
emission_op = EMISSION_OP_ADD ;
2017-03-05 16:44:50 +01:00
2017-09-21 20:20:00 +02:00
proximity_fade_enabled = false ;
2018-08-22 15:23:28 +02:00
distance_fade = DISTANCE_FADE_DISABLED ;
2017-09-21 20:20:00 +02:00
set_proximity_fade_distance ( 1 ) ;
set_distance_fade_min_distance ( 0 ) ;
set_distance_fade_max_distance ( 10 ) ;
2017-09-24 04:10:34 +02:00
set_ao_light_affect ( 0.0 ) ;
2019-07-22 11:56:41 +02:00
set_metallic_texture_channel ( TEXTURE_CHANNEL_RED ) ;
set_roughness_texture_channel ( TEXTURE_CHANNEL_RED ) ;
2017-08-02 20:34:55 +02:00
set_ao_texture_channel ( TEXTURE_CHANNEL_RED ) ;
set_refraction_texture_channel ( TEXTURE_CHANNEL_RED ) ;
2017-07-08 17:34:05 +02:00
grow_enabled = false ;
set_grow ( 0.0 ) ;
2017-06-04 23:08:06 +02:00
deep_parallax = false ;
2018-11-14 14:15:15 +01:00
depth_parallax_flip_tangent = false ;
2018-11-17 02:11:35 +01:00
depth_parallax_flip_binormal = false ;
2017-06-04 23:08:06 +02:00
set_depth_deep_parallax_min_layers ( 8 ) ;
set_depth_deep_parallax_max_layers ( 32 ) ;
2018-11-14 14:15:15 +01:00
set_depth_deep_parallax_flip_tangent ( false ) ; //also sets binormal
2017-06-04 23:08:06 +02:00
2017-03-05 16:44:50 +01:00
detail_uv = DETAIL_UV_1 ;
blend_mode = BLEND_MODE_MIX ;
detail_blend_mode = BLEND_MODE_MIX ;
depth_draw_mode = DEPTH_DRAW_OPAQUE_ONLY ;
cull_mode = CULL_BACK ;
for ( int i = 0 ; i < FLAG_MAX ; i + + ) {
2021-05-04 16:28:24 +02:00
flags [ i ] = false ;
2016-10-27 16:50:26 +02:00
}
2020-10-04 00:29:00 +02:00
force_vertex_shading = GLOBAL_GET ( " rendering/quality/shading/force_vertex_shading " ) ;
2018-01-12 15:50:08 +01:00
diffuse_mode = DIFFUSE_BURLEY ;
2017-10-23 07:42:36 +02:00
specular_mode = SPECULAR_SCHLICK_GGX ;
2016-10-27 16:50:26 +02:00
2021-09-26 21:31:17 +02:00
async_mode = ASYNC_MODE_VISIBLE ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < FEATURE_MAX ; i + + ) {
features [ i ] = false ;
2016-10-27 16:50:26 +02:00
}
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
current_key . key = 0 ;
current_key . invalid_key = 1 ;
2021-09-06 14:32:59 +02:00
is_initialized = true ;
2016-10-27 16:50:26 +02:00
_queue_shader_change ( ) ;
2014-02-10 02:10:30 +01:00
}
2017-04-07 04:36:37 +02:00
SpatialMaterial : : ~ SpatialMaterial ( ) {
2021-01-27 10:43:02 +01:00
material_mutex . lock ( ) ;
2016-10-27 16:50:26 +02:00
if ( shader_map . has ( current_key ) ) {
shader_map [ current_key ] . users - - ;
2017-03-05 16:44:50 +01:00
if ( shader_map [ current_key ] . users = = 0 ) {
2016-10-27 16:50:26 +02:00
//deallocate shader, as it's no longer in use
VS : : get_singleton ( ) - > free ( shader_map [ current_key ] . shader ) ;
shader_map . erase ( current_key ) ;
}
2017-03-05 16:44:50 +01:00
VS : : get_singleton ( ) - > material_set_shader ( _get_material ( ) , RID ( ) ) ;
2016-10-27 16:50:26 +02:00
}
2021-01-27 10:43:02 +01:00
material_mutex . unlock ( ) ;
2016-10-27 16:50:26 +02:00
}