| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/io/resource.h" |
| 34 |
#include "core/templates/self_list.h" |
| 35 |
#include "scene/resources/shader.h" |
| 36 |
#include "scene/resources/texture.h" |
| 37 |
#include "servers/rendering/rendering_server.h" |
| 38 |
|
| 39 |
class Material : public Resource { |
| 40 |
GDCLASS(Material, Resource); |
| 41 |
RES_BASE_EXTENSION("material") |
| 42 |
OBJ_SAVE_TYPE(Material); |
| 43 |
|
| 44 |
mutable RID material; |
| 45 |
Ref<Material> next_pass; |
| 46 |
int render_priority; |
| 47 |
|
| 48 |
enum { |
| 49 |
INIT_STATE_UNINITIALIZED, |
| 50 |
INIT_STATE_INITIALIZING, |
| 51 |
INIT_STATE_READY, |
| 52 |
} init_state = INIT_STATE_UNINITIALIZED; |
| 53 |
|
| 54 |
void inspect_native_shader_code(); |
| 55 |
|
| 56 |
protected: |
| 57 |
_FORCE_INLINE_ void _set_material(RID p_material) const { material = p_material; } |
| 58 |
_FORCE_INLINE_ RID _get_material() const { return material; } |
| 59 |
static void _bind_methods(); |
| 60 |
virtual bool _can_do_next_pass() const; |
| 61 |
virtual bool _can_use_render_priority() const; |
| 62 |
|
| 63 |
void _validate_property(PropertyInfo &p_property) const; |
| 64 |
|
| 65 |
void _mark_ready(); |
| 66 |
void _mark_initialized(const Callable &p_add_to_dirty_list, const Callable &p_update_shader); |
| 67 |
|
| 68 |
GDVIRTUAL0RC_REQUIRED(RID, _get_shader_rid) |
| 69 |
GDVIRTUAL0RC_REQUIRED(Shader::Mode, _get_shader_mode) |
| 70 |
GDVIRTUAL0RC(bool, _can_do_next_pass) |
| 71 |
GDVIRTUAL0RC(bool, _can_use_render_priority) |
| 72 |
public: |
| 73 |
enum { |
| 74 |
RENDER_PRIORITY_MAX = RS::MATERIAL_RENDER_PRIORITY_MAX, |
| 75 |
RENDER_PRIORITY_MIN = RS::MATERIAL_RENDER_PRIORITY_MIN, |
| 76 |
}; |
| 77 |
|
| 78 |
bool _is_initialized() { return init_state == INIT_STATE_READY; } |
| 79 |
|
| 80 |
void set_next_pass(const Ref<Material> &p_pass); |
| 81 |
Ref<Material> get_next_pass() const; |
| 82 |
|
| 83 |
void set_render_priority(int p_priority); |
| 84 |
int get_render_priority() const; |
| 85 |
|
| 86 |
virtual RID get_rid() const override; |
| 87 |
virtual RID get_shader_rid() const; |
| 88 |
virtual Shader::Mode get_shader_mode() const; |
| 89 |
|
| 90 |
virtual Ref<Resource> create_placeholder() const; |
| 91 |
|
| 92 |
Material(); |
| 93 |
virtual ~Material(); |
| 94 |
}; |
| 95 |
|
| 96 |
class ShaderMaterial : public Material { |
| 97 |
GDCLASS(ShaderMaterial, Material); |
| 98 |
Ref<Shader> shader; |
| 99 |
|
| 100 |
mutable HashMap<StringName, StringName> remap_cache; |
| 101 |
mutable HashMap<StringName, Variant> param_cache; |
| 102 |
mutable Mutex material_rid_mutex; |
| 103 |
|
| 104 |
protected: |
| 105 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 106 |
bool _get(const StringName &p_name, Variant &r_ret) const; |
| 107 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 108 |
bool _property_can_revert(const StringName &p_name) const; |
| 109 |
bool _property_get_revert(const StringName &p_name, Variant &r_property) const; |
| 110 |
|
| 111 |
static void _bind_methods(); |
| 112 |
|
| 113 |
#ifdef TOOLS_ENABLED |
| 114 |
void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override; |
| 115 |
#endif |
| 116 |
|
| 117 |
virtual bool _can_do_next_pass() const override; |
| 118 |
virtual bool _can_use_render_priority() const override; |
| 119 |
|
| 120 |
void _shader_changed(); |
| 121 |
void _check_material_rid() const; |
| 122 |
|
| 123 |
public: |
| 124 |
void set_shader(const Ref<Shader> &p_shader); |
| 125 |
Ref<Shader> get_shader() const; |
| 126 |
|
| 127 |
void set_shader_parameter(const StringName &p_param, const Variant &p_value); |
| 128 |
Variant get_shader_parameter(const StringName &p_param) const; |
| 129 |
|
| 130 |
virtual Shader::Mode get_shader_mode() const override; |
| 131 |
|
| 132 |
virtual RID get_rid() const override; |
| 133 |
virtual RID get_shader_rid() const override; |
| 134 |
|
| 135 |
ShaderMaterial(); |
| 136 |
~ShaderMaterial(); |
| 137 |
}; |
| 138 |
|
| 139 |
class StandardMaterial3D; |
| 140 |
|
| 141 |
class BaseMaterial3D : public Material { |
| 142 |
GDCLASS(BaseMaterial3D, Material); |
| 143 |
|
| 144 |
private: |
| 145 |
mutable Mutex material_rid_mutex; |
| 146 |
|
| 147 |
public: |
| 148 |
enum TextureParam { |
| 149 |
TEXTURE_ALBEDO, |
| 150 |
TEXTURE_METALLIC, |
| 151 |
TEXTURE_ROUGHNESS, |
| 152 |
TEXTURE_EMISSION, |
| 153 |
TEXTURE_NORMAL, |
| 154 |
TEXTURE_RIM, |
| 155 |
TEXTURE_CLEARCOAT, |
| 156 |
TEXTURE_FLOWMAP, |
| 157 |
TEXTURE_AMBIENT_OCCLUSION, |
| 158 |
TEXTURE_HEIGHTMAP, |
| 159 |
TEXTURE_SUBSURFACE_SCATTERING, |
| 160 |
TEXTURE_SUBSURFACE_TRANSMITTANCE, |
| 161 |
TEXTURE_BACKLIGHT, |
| 162 |
TEXTURE_REFRACTION, |
| 163 |
TEXTURE_DETAIL_MASK, |
| 164 |
TEXTURE_DETAIL_ALBEDO, |
| 165 |
TEXTURE_DETAIL_NORMAL, |
| 166 |
TEXTURE_ORM, |
| 167 |
TEXTURE_BENT_NORMAL, |
| 168 |
TEXTURE_MAX |
| 169 |
}; |
| 170 |
|
| 171 |
enum TextureFilter { |
| 172 |
TEXTURE_FILTER_NEAREST, |
| 173 |
TEXTURE_FILTER_LINEAR, |
| 174 |
TEXTURE_FILTER_NEAREST_WITH_MIPMAPS, |
| 175 |
TEXTURE_FILTER_LINEAR_WITH_MIPMAPS, |
| 176 |
TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC, |
| 177 |
TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC, |
| 178 |
TEXTURE_FILTER_MAX |
| 179 |
}; |
| 180 |
|
| 181 |
enum DetailUV { |
| 182 |
DETAIL_UV_1, |
| 183 |
DETAIL_UV_2, |
| 184 |
DETAIL_UV_MAX |
| 185 |
}; |
| 186 |
|
| 187 |
enum Transparency { |
| 188 |
TRANSPARENCY_DISABLED, |
| 189 |
TRANSPARENCY_ALPHA, |
| 190 |
TRANSPARENCY_ALPHA_SCISSOR, |
| 191 |
TRANSPARENCY_ALPHA_HASH, |
| 192 |
TRANSPARENCY_ALPHA_DEPTH_PRE_PASS, |
| 193 |
TRANSPARENCY_MAX, |
| 194 |
}; |
| 195 |
|
| 196 |
enum AlphaAntiAliasing { |
| 197 |
ALPHA_ANTIALIASING_OFF, |
| 198 |
ALPHA_ANTIALIASING_ALPHA_TO_COVERAGE, |
| 199 |
ALPHA_ANTIALIASING_ALPHA_TO_COVERAGE_AND_TO_ONE, |
| 200 |
ALPHA_ANTIALIASING_MAX |
| 201 |
}; |
| 202 |
|
| 203 |
enum ShadingMode { |
| 204 |
SHADING_MODE_UNSHADED, |
| 205 |
SHADING_MODE_PER_PIXEL, |
| 206 |
SHADING_MODE_PER_VERTEX, |
| 207 |
SHADING_MODE_MAX |
| 208 |
}; |
| 209 |
|
| 210 |
enum Feature { |
| 211 |
FEATURE_EMISSION, |
| 212 |
FEATURE_NORMAL_MAPPING, |
| 213 |
FEATURE_RIM, |
| 214 |
FEATURE_CLEARCOAT, |
| 215 |
FEATURE_ANISOTROPY, |
| 216 |
FEATURE_AMBIENT_OCCLUSION, |
| 217 |
FEATURE_HEIGHT_MAPPING, |
| 218 |
FEATURE_SUBSURFACE_SCATTERING, |
| 219 |
FEATURE_SUBSURFACE_TRANSMITTANCE, |
| 220 |
FEATURE_BACKLIGHT, |
| 221 |
FEATURE_REFRACTION, |
| 222 |
FEATURE_DETAIL, |
| 223 |
FEATURE_BENT_NORMAL_MAPPING, |
| 224 |
FEATURE_MAX |
| 225 |
}; |
| 226 |
|
| 227 |
enum BlendMode { |
| 228 |
BLEND_MODE_MIX, |
| 229 |
BLEND_MODE_ADD, |
| 230 |
BLEND_MODE_SUB, |
| 231 |
BLEND_MODE_MUL, |
| 232 |
BLEND_MODE_PREMULT_ALPHA, |
| 233 |
BLEND_MODE_MAX |
| 234 |
}; |
| 235 |
|
| 236 |
enum DepthDrawMode { |
| 237 |
DEPTH_DRAW_OPAQUE_ONLY, |
| 238 |
DEPTH_DRAW_ALWAYS, |
| 239 |
DEPTH_DRAW_DISABLED, |
| 240 |
DEPTH_DRAW_MAX |
| 241 |
}; |
| 242 |
|
| 243 |
enum DepthTest { |
| 244 |
DEPTH_TEST_DEFAULT, |
| 245 |
DEPTH_TEST_INVERTED, |
| 246 |
DEPTH_TEST_MAX |
| 247 |
}; |
| 248 |
|
| 249 |
enum CullMode { |
| 250 |
CULL_BACK, |
| 251 |
CULL_FRONT, |
| 252 |
CULL_DISABLED, |
| 253 |
CULL_MAX |
| 254 |
}; |
| 255 |
|
| 256 |
enum Flags { |
| 257 |
FLAG_DISABLE_DEPTH_TEST, |
| 258 |
FLAG_ALBEDO_FROM_VERTEX_COLOR, |
| 259 |
FLAG_SRGB_VERTEX_COLOR, |
| 260 |
FLAG_USE_POINT_SIZE, |
| 261 |
FLAG_FIXED_SIZE, |
| 262 |
FLAG_BILLBOARD_KEEP_SCALE, |
| 263 |
FLAG_UV1_USE_TRIPLANAR, |
| 264 |
FLAG_UV2_USE_TRIPLANAR, |
| 265 |
FLAG_UV1_USE_WORLD_TRIPLANAR, |
| 266 |
FLAG_UV2_USE_WORLD_TRIPLANAR, |
| 267 |
FLAG_AO_ON_UV2, |
| 268 |
FLAG_EMISSION_ON_UV2, |
| 269 |
FLAG_ALBEDO_TEXTURE_FORCE_SRGB, |
| 270 |
FLAG_DONT_RECEIVE_SHADOWS, |
| 271 |
FLAG_DISABLE_AMBIENT_LIGHT, |
| 272 |
FLAG_USE_SHADOW_TO_OPACITY, |
| 273 |
FLAG_USE_TEXTURE_REPEAT, |
| 274 |
FLAG_INVERT_HEIGHTMAP, |
| 275 |
FLAG_SUBSURFACE_MODE_SKIN, |
| 276 |
FLAG_PARTICLE_TRAILS_MODE, |
| 277 |
FLAG_ALBEDO_TEXTURE_MSDF, |
| 278 |
FLAG_DISABLE_FOG, |
| 279 |
FLAG_DISABLE_SPECULAR_OCCLUSION, |
| 280 |
FLAG_USE_Z_CLIP_SCALE, |
| 281 |
FLAG_USE_FOV_OVERRIDE, |
| 282 |
FLAG_MAX |
| 283 |
}; |
| 284 |
|
| 285 |
enum DiffuseMode { |
| 286 |
DIFFUSE_BURLEY, |
| 287 |
DIFFUSE_LAMBERT, |
| 288 |
DIFFUSE_LAMBERT_WRAP, |
| 289 |
DIFFUSE_TOON, |
| 290 |
DIFFUSE_MAX |
| 291 |
}; |
| 292 |
|
| 293 |
enum SpecularMode { |
| 294 |
SPECULAR_SCHLICK_GGX, |
| 295 |
SPECULAR_TOON, |
| 296 |
SPECULAR_DISABLED, |
| 297 |
SPECULAR_MAX |
| 298 |
}; |
| 299 |
|
| 300 |
enum BillboardMode { |
| 301 |
BILLBOARD_DISABLED, |
| 302 |
BILLBOARD_ENABLED, |
| 303 |
BILLBOARD_FIXED_Y, |
| 304 |
BILLBOARD_PARTICLES, |
| 305 |
BILLBOARD_MAX |
| 306 |
}; |
| 307 |
|
| 308 |
enum TextureChannel { |
| 309 |
TEXTURE_CHANNEL_RED, |
| 310 |
TEXTURE_CHANNEL_GREEN, |
| 311 |
TEXTURE_CHANNEL_BLUE, |
| 312 |
TEXTURE_CHANNEL_ALPHA, |
| 313 |
TEXTURE_CHANNEL_GRAYSCALE, |
| 314 |
TEXTURE_CHANNEL_MAX |
| 315 |
}; |
| 316 |
|
| 317 |
enum EmissionOperator { |
| 318 |
EMISSION_OP_ADD, |
| 319 |
EMISSION_OP_MULTIPLY, |
| 320 |
EMISSION_OP_MAX |
| 321 |
}; |
| 322 |
|
| 323 |
enum DistanceFadeMode { |
| 324 |
DISTANCE_FADE_DISABLED, |
| 325 |
DISTANCE_FADE_PIXEL_ALPHA, |
| 326 |
DISTANCE_FADE_PIXEL_DITHER, |
| 327 |
DISTANCE_FADE_OBJECT_DITHER, |
| 328 |
DISTANCE_FADE_MAX |
| 329 |
}; |
| 330 |
|
| 331 |
enum StencilMode { |
| 332 |
STENCIL_MODE_DISABLED, |
| 333 |
STENCIL_MODE_OUTLINE, |
| 334 |
STENCIL_MODE_XRAY, |
| 335 |
STENCIL_MODE_CUSTOM, |
| 336 |
STENCIL_MODE_MAX |
| 337 |
}; |
| 338 |
|
| 339 |
enum StencilFlags { |
| 340 |
STENCIL_FLAG_READ = 1, |
| 341 |
STENCIL_FLAG_WRITE = 2, |
| 342 |
STENCIL_FLAG_WRITE_DEPTH_FAIL = 4, |
| 343 |
|
| 344 |
STENCIL_FLAG_NUM_BITS = 3 |
| 345 |
}; |
| 346 |
|
| 347 |
enum StencilCompare { |
| 348 |
STENCIL_COMPARE_ALWAYS, |
| 349 |
STENCIL_COMPARE_LESS, |
| 350 |
STENCIL_COMPARE_EQUAL, |
| 351 |
STENCIL_COMPARE_LESS_OR_EQUAL, |
| 352 |
STENCIL_COMPARE_GREATER, |
| 353 |
STENCIL_COMPARE_NOT_EQUAL, |
| 354 |
STENCIL_COMPARE_GREATER_OR_EQUAL, |
| 355 |
STENCIL_COMPARE_MAX |
| 356 |
}; |
| 357 |
|
| 358 |
private: |
| 359 |
struct MaterialKey { |
| 360 |
|
| 361 |
uint64_t texture_filter : get_num_bits(TEXTURE_FILTER_MAX - 1); |
| 362 |
uint64_t detail_uv : get_num_bits(DETAIL_UV_MAX - 1); |
| 363 |
uint64_t transparency : get_num_bits(TRANSPARENCY_MAX - 1); |
| 364 |
uint64_t alpha_antialiasing_mode : get_num_bits(ALPHA_ANTIALIASING_MAX - 1); |
| 365 |
uint64_t shading_mode : get_num_bits(SHADING_MODE_MAX - 1); |
| 366 |
uint64_t blend_mode : get_num_bits(BLEND_MODE_MAX - 1); |
| 367 |
uint64_t depth_draw_mode : get_num_bits(DEPTH_DRAW_MAX - 1); |
| 368 |
uint64_t depth_test : get_num_bits(DEPTH_TEST_MAX - 1); |
| 369 |
uint64_t cull_mode : get_num_bits(CULL_MAX - 1); |
| 370 |
uint64_t diffuse_mode : get_num_bits(DIFFUSE_MAX - 1); |
| 371 |
uint64_t specular_mode : get_num_bits(SPECULAR_MAX - 1); |
| 372 |
uint64_t billboard_mode : get_num_bits(BILLBOARD_MAX - 1); |
| 373 |
uint64_t detail_blend_mode : get_num_bits(BLEND_MODE_MAX - 1); |
| 374 |
uint64_t roughness_channel : get_num_bits(TEXTURE_CHANNEL_MAX - 1); |
| 375 |
uint64_t emission_op : get_num_bits(EMISSION_OP_MAX - 1); |
| 376 |
uint64_t distance_fade : get_num_bits(DISTANCE_FADE_MAX - 1); |
| 377 |
|
| 378 |
|
| 379 |
uint64_t stencil_mode : get_num_bits(STENCIL_MODE_MAX - 1); |
| 380 |
uint64_t stencil_flags : STENCIL_FLAG_NUM_BITS; |
| 381 |
uint64_t stencil_compare : get_num_bits(STENCIL_COMPARE_MAX - 1); |
| 382 |
uint64_t stencil_reference : 8; |
| 383 |
|
| 384 |
|
| 385 |
uint64_t invalid_key : 1; |
| 386 |
uint64_t deep_parallax : 1; |
| 387 |
uint64_t grow : 1; |
| 388 |
uint64_t proximity_fade : 1; |
| 389 |
uint64_t orm : 1; |
| 390 |
|
| 391 |
|
| 392 |
uint32_t feature_mask; |
| 393 |
uint32_t flags; |
| 394 |
|
| 395 |
MaterialKey() { |
| 396 |
memset(this, 0, sizeof(MaterialKey)); |
| 397 |
} |
| 398 |
|
| 399 |
static uint32_t hash(const MaterialKey &p_key) { |
| 400 |
return hash_djb2_buffer((const uint8_t *)&p_key, sizeof(MaterialKey)); |
| 401 |
} |
| 402 |
bool operator==(const MaterialKey &p_key) const { |
| 403 |
return memcmp(this, &p_key, sizeof(MaterialKey)) == 0; |
| 404 |
} |
| 405 |
|
| 406 |
bool operator<(const MaterialKey &p_key) const { |
| 407 |
return memcmp(this, &p_key, sizeof(MaterialKey)) < 0; |
| 408 |
} |
| 409 |
}; |
| 410 |
|
| 411 |
struct ShaderData { |
| 412 |
RID shader; |
| 413 |
int users = 0; |
| 414 |
}; |
| 415 |
|
| 416 |
static HashMap<MaterialKey, ShaderData, MaterialKey> shader_map; |
| 417 |
static Mutex shader_map_mutex; |
| 418 |
|
| 419 |
MaterialKey current_key; |
| 420 |
|
| 421 |
_FORCE_INLINE_ MaterialKey _compute_key() const { |
| 422 |
MaterialKey mk; |
| 423 |
|
| 424 |
mk.detail_uv = detail_uv; |
| 425 |
mk.blend_mode = blend_mode; |
| 426 |
mk.depth_draw_mode = depth_draw_mode; |
| 427 |
mk.depth_test = depth_test; |
| 428 |
mk.cull_mode = cull_mode; |
| 429 |
mk.texture_filter = texture_filter; |
| 430 |
mk.transparency = transparency; |
| 431 |
mk.shading_mode = shading_mode; |
| 432 |
mk.roughness_channel = roughness_texture_channel; |
| 433 |
mk.detail_blend_mode = detail_blend_mode; |
| 434 |
mk.diffuse_mode = diffuse_mode; |
| 435 |
mk.specular_mode = specular_mode; |
| 436 |
mk.billboard_mode = billboard_mode; |
| 437 |
mk.deep_parallax = deep_parallax; |
| 438 |
mk.grow = grow_enabled; |
| 439 |
mk.proximity_fade = proximity_fade_enabled; |
| 440 |
mk.distance_fade = distance_fade; |
| 441 |
mk.emission_op = emission_op; |
| 442 |
mk.alpha_antialiasing_mode = alpha_antialiasing_mode; |
| 443 |
mk.orm = orm; |
| 444 |
|
| 445 |
mk.stencil_mode = stencil_mode; |
| 446 |
mk.stencil_flags = stencil_flags; |
| 447 |
mk.stencil_compare = stencil_compare; |
| 448 |
mk.stencil_reference = stencil_reference; |
| 449 |
|
| 450 |
for (int i = 0; i < FEATURE_MAX; i++) { |
| 451 |
if (features[i]) { |
| 452 |
mk.feature_mask |= ((uint64_t)1 << i); |
| 453 |
} |
| 454 |
} |
| 455 |
|
| 456 |
for (int i = 0; i < FLAG_MAX; i++) { |
| 457 |
if (flags[i]) { |
| 458 |
mk.flags |= ((uint64_t)1 << i); |
| 459 |
} |
| 460 |
} |
| 461 |
|
| 462 |
return mk; |
| 463 |
} |
| 464 |
|
| 465 |
struct ShaderNames { |
| 466 |
StringName albedo; |
| 467 |
StringName specular; |
| 468 |
StringName metallic; |
| 469 |
StringName roughness; |
| 470 |
StringName emission; |
| 471 |
StringName emission_energy; |
| 472 |
StringName normal_scale; |
| 473 |
StringName rim; |
| 474 |
StringName rim_tint; |
| 475 |
StringName clearcoat; |
| 476 |
StringName clearcoat_roughness; |
| 477 |
StringName anisotropy; |
| 478 |
StringName heightmap_scale; |
| 479 |
StringName subsurface_scattering_strength; |
| 480 |
StringName transmittance_color; |
| 481 |
StringName transmittance_depth; |
| 482 |
StringName transmittance_boost; |
| 483 |
StringName backlight; |
| 484 |
StringName refraction; |
| 485 |
StringName point_size; |
| 486 |
StringName uv1_scale; |
| 487 |
StringName uv1_offset; |
| 488 |
StringName uv2_scale; |
| 489 |
StringName uv2_offset; |
| 490 |
StringName particles_anim_h_frames; |
| 491 |
StringName particles_anim_v_frames; |
| 492 |
StringName particles_anim_loop; |
| 493 |
StringName heightmap_min_layers; |
| 494 |
StringName heightmap_max_layers; |
| 495 |
StringName heightmap_flip; |
| 496 |
StringName uv1_blend_sharpness; |
| 497 |
StringName uv2_blend_sharpness; |
| 498 |
StringName grow; |
| 499 |
StringName proximity_fade_distance; |
| 500 |
StringName msdf_pixel_range; |
| 501 |
StringName msdf_outline_size; |
| 502 |
StringName distance_fade_min; |
| 503 |
StringName distance_fade_max; |
| 504 |
StringName ao_light_affect; |
| 505 |
|
| 506 |
StringName metallic_texture_channel; |
| 507 |
StringName ao_texture_channel; |
| 508 |
StringName clearcoat_texture_channel; |
| 509 |
StringName rim_texture_channel; |
| 510 |
StringName heightmap_texture_channel; |
| 511 |
StringName refraction_texture_channel; |
| 512 |
|
| 513 |
StringName texture_names[TEXTURE_MAX]; |
| 514 |
|
| 515 |
StringName alpha_scissor_threshold; |
| 516 |
StringName alpha_hash_scale; |
| 517 |
|
| 518 |
StringName alpha_antialiasing_edge; |
| 519 |
StringName albedo_texture_size; |
| 520 |
StringName z_clip_scale; |
| 521 |
StringName fov_override; |
| 522 |
}; |
| 523 |
|
| 524 |
static Mutex material_mutex; |
| 525 |
static SelfList<BaseMaterial3D>::List dirty_materials; |
| 526 |
static ShaderNames *shader_names; |
| 527 |
|
| 528 |
SelfList<BaseMaterial3D> element; |
| 529 |
|
| 530 |
void _update_shader(); |
| 531 |
_FORCE_INLINE_ void _queue_shader_change(); |
| 532 |
void _check_material_rid(); |
| 533 |
void _material_set_param(const StringName &p_name, const Variant &p_value); |
| 534 |
|
| 535 |
bool orm; |
| 536 |
RID shader_rid; |
| 537 |
HashMap<StringName, Variant> pending_params; |
| 538 |
|
| 539 |
Color albedo; |
| 540 |
float specular = 0.0f; |
| 541 |
float metallic = 0.0f; |
| 542 |
float roughness = 0.0f; |
| 543 |
Color emission; |
| 544 |
float emission_energy_multiplier = 1.0f; |
| 545 |
float emission_intensity = 1000.0f; |
| 546 |
float normal_scale = 0.0f; |
| 547 |
float rim = 0.0f; |
| 548 |
float rim_tint = 0.0f; |
| 549 |
float clearcoat = 0.0f; |
| 550 |
float clearcoat_roughness = 0.0f; |
| 551 |
float anisotropy = 0.0f; |
| 552 |
float heightmap_scale = 0.0f; |
| 553 |
float subsurface_scattering_strength = 0.0f; |
| 554 |
Color transmittance_color; |
| 555 |
float transmittance_depth = 0.0f; |
| 556 |
float transmittance_boost = 0.0f; |
| 557 |
|
| 558 |
Color backlight; |
| 559 |
float refraction = 0.0f; |
| 560 |
float point_size = 0.0f; |
| 561 |
float alpha_scissor_threshold = 0.0f; |
| 562 |
float alpha_hash_scale = 0.0f; |
| 563 |
float alpha_antialiasing_edge = 0.0f; |
| 564 |
bool grow_enabled = false; |
| 565 |
float ao_light_affect = 0.0f; |
| 566 |
float grow = 0.0f; |
| 567 |
int particles_anim_h_frames = 0; |
| 568 |
int particles_anim_v_frames = 0; |
| 569 |
bool particles_anim_loop = false; |
| 570 |
Transparency transparency = TRANSPARENCY_DISABLED; |
| 571 |
ShadingMode shading_mode = SHADING_MODE_PER_PIXEL; |
| 572 |
|
| 573 |
TextureFilter texture_filter = TEXTURE_FILTER_LINEAR_WITH_MIPMAPS; |
| 574 |
|
| 575 |
Vector3 uv1_scale; |
| 576 |
Vector3 uv1_offset; |
| 577 |
float uv1_triplanar_sharpness = 0.0f; |
| 578 |
|
| 579 |
Vector3 uv2_scale; |
| 580 |
Vector3 uv2_offset; |
| 581 |
float uv2_triplanar_sharpness = 0.0f; |
| 582 |
|
| 583 |
DetailUV detail_uv = DETAIL_UV_1; |
| 584 |
|
| 585 |
bool deep_parallax = false; |
| 586 |
int deep_parallax_min_layers = 0; |
| 587 |
int deep_parallax_max_layers = 0; |
| 588 |
bool heightmap_parallax_flip_tangent = false; |
| 589 |
bool heightmap_parallax_flip_binormal = false; |
| 590 |
|
| 591 |
bool proximity_fade_enabled = false; |
| 592 |
float proximity_fade_distance = 0.0f; |
| 593 |
|
| 594 |
float msdf_pixel_range = 4.f; |
| 595 |
float msdf_outline_size = 0.f; |
| 596 |
|
| 597 |
DistanceFadeMode distance_fade = DISTANCE_FADE_DISABLED; |
| 598 |
float distance_fade_max_distance = 0.0f; |
| 599 |
float distance_fade_min_distance = 0.0f; |
| 600 |
|
| 601 |
BlendMode blend_mode = BLEND_MODE_MIX; |
| 602 |
BlendMode detail_blend_mode = BLEND_MODE_MIX; |
| 603 |
DepthDrawMode depth_draw_mode = DEPTH_DRAW_OPAQUE_ONLY; |
| 604 |
DepthTest depth_test = DEPTH_TEST_DEFAULT; |
| 605 |
CullMode cull_mode = CULL_BACK; |
| 606 |
bool flags[FLAG_MAX] = {}; |
| 607 |
SpecularMode specular_mode = SPECULAR_SCHLICK_GGX; |
| 608 |
DiffuseMode diffuse_mode = DIFFUSE_BURLEY; |
| 609 |
BillboardMode billboard_mode; |
| 610 |
EmissionOperator emission_op = EMISSION_OP_ADD; |
| 611 |
|
| 612 |
TextureChannel metallic_texture_channel; |
| 613 |
TextureChannel roughness_texture_channel; |
| 614 |
TextureChannel ao_texture_channel; |
| 615 |
TextureChannel refraction_texture_channel; |
| 616 |
|
| 617 |
AlphaAntiAliasing alpha_antialiasing_mode = ALPHA_ANTIALIASING_OFF; |
| 618 |
|
| 619 |
float z_clip_scale = 1.0; |
| 620 |
float fov_override = 75.0; |
| 621 |
|
| 622 |
StencilMode stencil_mode = STENCIL_MODE_DISABLED; |
| 623 |
int stencil_flags = 0; |
| 624 |
StencilCompare stencil_compare = STENCIL_COMPARE_ALWAYS; |
| 625 |
int stencil_reference = 1; |
| 626 |
|
| 627 |
Color stencil_effect_color; |
| 628 |
float stencil_effect_outline_thickness = 0.01f; |
| 629 |
|
| 630 |
bool features[FEATURE_MAX] = {}; |
| 631 |
|
| 632 |
Ref<Texture2D> textures[TEXTURE_MAX]; |
| 633 |
|
| 634 |
void _prepare_stencil_effect(); |
| 635 |
Ref<BaseMaterial3D> _get_stencil_next_pass() const; |
| 636 |
|
| 637 |
static HashMap<uint64_t, Ref<StandardMaterial3D>> materials_for_2d; |
| 638 |
|
| 639 |
protected: |
| 640 |
static void _bind_methods(); |
| 641 |
void _validate_property(PropertyInfo &p_property) const; |
| 642 |
virtual bool _can_do_next_pass() const override { return true; } |
| 643 |
virtual bool _can_use_render_priority() const override { return true; } |
| 644 |
|
| 645 |
public: |
| 646 |
void set_albedo(const Color &p_albedo); |
| 647 |
Color get_albedo() const; |
| 648 |
|
| 649 |
void set_specular(float p_specular); |
| 650 |
float get_specular() const; |
| 651 |
|
| 652 |
void set_metallic(float p_metallic); |
| 653 |
float get_metallic() const; |
| 654 |
|
| 655 |
void set_roughness(float p_roughness); |
| 656 |
float get_roughness() const; |
| 657 |
|
| 658 |
void set_emission(const Color &p_emission); |
| 659 |
Color get_emission() const; |
| 660 |
|
| 661 |
void set_emission_energy_multiplier(float p_emission_energy_multiplier); |
| 662 |
float get_emission_energy_multiplier() const; |
| 663 |
|
| 664 |
void set_emission_intensity(float p_emission_intensity); |
| 665 |
float get_emission_intensity() const; |
| 666 |
|
| 667 |
void set_normal_scale(float p_normal_scale); |
| 668 |
float get_normal_scale() const; |
| 669 |
|
| 670 |
void set_rim(float p_rim); |
| 671 |
float get_rim() const; |
| 672 |
|
| 673 |
void set_rim_tint(float p_rim_tint); |
| 674 |
float get_rim_tint() const; |
| 675 |
|
| 676 |
void set_ao_light_affect(float p_ao_light_affect); |
| 677 |
float get_ao_light_affect() const; |
| 678 |
|
| 679 |
void set_clearcoat(float p_clearcoat); |
| 680 |
float get_clearcoat() const; |
| 681 |
|
| 682 |
void set_clearcoat_roughness(float p_clearcoat_roughness); |
| 683 |
float get_clearcoat_roughness() const; |
| 684 |
|
| 685 |
void set_anisotropy(float p_anisotropy); |
| 686 |
float get_anisotropy() const; |
| 687 |
|
| 688 |
void set_heightmap_scale(float p_heightmap_scale); |
| 689 |
float get_heightmap_scale() const; |
| 690 |
|
| 691 |
void set_heightmap_deep_parallax(bool p_enable); |
| 692 |
bool is_heightmap_deep_parallax_enabled() const; |
| 693 |
|
| 694 |
void set_heightmap_deep_parallax_min_layers(int p_layer); |
| 695 |
int get_heightmap_deep_parallax_min_layers() const; |
| 696 |
|
| 697 |
void set_heightmap_deep_parallax_max_layers(int p_layer); |
| 698 |
int get_heightmap_deep_parallax_max_layers() const; |
| 699 |
|
| 700 |
void set_heightmap_deep_parallax_flip_tangent(bool p_flip); |
| 701 |
bool get_heightmap_deep_parallax_flip_tangent() const; |
| 702 |
|
| 703 |
void set_heightmap_deep_parallax_flip_binormal(bool p_flip); |
| 704 |
bool get_heightmap_deep_parallax_flip_binormal() const; |
| 705 |
|
| 706 |
void set_subsurface_scattering_strength(float p_subsurface_scattering_strength); |
| 707 |
float get_subsurface_scattering_strength() const; |
| 708 |
|
| 709 |
void set_transmittance_color(const Color &p_color); |
| 710 |
Color get_transmittance_color() const; |
| 711 |
|
| 712 |
void set_transmittance_depth(float p_depth); |
| 713 |
float get_transmittance_depth() const; |
| 714 |
|
| 715 |
void set_transmittance_boost(float p_boost); |
| 716 |
float get_transmittance_boost() const; |
| 717 |
|
| 718 |
void set_backlight(const Color &p_backlight); |
| 719 |
Color get_backlight() const; |
| 720 |
|
| 721 |
void set_refraction(float p_refraction); |
| 722 |
float get_refraction() const; |
| 723 |
|
| 724 |
void set_point_size(float p_point_size); |
| 725 |
float get_point_size() const; |
| 726 |
|
| 727 |
void set_transparency(Transparency p_transparency); |
| 728 |
Transparency get_transparency() const; |
| 729 |
|
| 730 |
void set_alpha_antialiasing(AlphaAntiAliasing p_alpha_aa); |
| 731 |
AlphaAntiAliasing get_alpha_antialiasing() const; |
| 732 |
|
| 733 |
void set_alpha_antialiasing_edge(float p_edge); |
| 734 |
float get_alpha_antialiasing_edge() const; |
| 735 |
|
| 736 |
void set_shading_mode(ShadingMode p_shading_mode); |
| 737 |
ShadingMode get_shading_mode() const; |
| 738 |
|
| 739 |
void set_detail_uv(DetailUV p_detail_uv); |
| 740 |
DetailUV get_detail_uv() const; |
| 741 |
|
| 742 |
void set_blend_mode(BlendMode p_mode); |
| 743 |
BlendMode get_blend_mode() const; |
| 744 |
|
| 745 |
void set_detail_blend_mode(BlendMode p_mode); |
| 746 |
BlendMode get_detail_blend_mode() const; |
| 747 |
|
| 748 |
void set_depth_draw_mode(DepthDrawMode p_mode); |
| 749 |
DepthDrawMode get_depth_draw_mode() const; |
| 750 |
|
| 751 |
void set_depth_test(DepthTest p_func); |
| 752 |
DepthTest get_depth_test() const; |
| 753 |
|
| 754 |
void set_cull_mode(CullMode p_mode); |
| 755 |
CullMode get_cull_mode() const; |
| 756 |
|
| 757 |
void set_diffuse_mode(DiffuseMode p_mode); |
| 758 |
DiffuseMode get_diffuse_mode() const; |
| 759 |
|
| 760 |
void set_specular_mode(SpecularMode p_mode); |
| 761 |
SpecularMode get_specular_mode() const; |
| 762 |
|
| 763 |
void set_flag(Flags p_flag, bool p_enabled); |
| 764 |
bool get_flag(Flags p_flag) const; |
| 765 |
|
| 766 |
void set_texture(TextureParam p_param, const Ref<Texture2D> &p_texture); |
| 767 |
Ref<Texture2D> get_texture(TextureParam p_param) const; |
| 768 |
|
| 769 |
Ref<Texture2D> get_texture_by_name(const StringName &p_name) const; |
| 770 |
|
| 771 |
void set_texture_filter(TextureFilter p_filter); |
| 772 |
TextureFilter get_texture_filter() const; |
| 773 |
|
| 774 |
void set_feature(Feature p_feature, bool p_enabled); |
| 775 |
bool get_feature(Feature p_feature) const; |
| 776 |
|
| 777 |
void set_uv1_scale(const Vector3 &p_scale); |
| 778 |
Vector3 get_uv1_scale() const; |
| 779 |
|
| 780 |
void set_uv1_offset(const Vector3 &p_offset); |
| 781 |
Vector3 get_uv1_offset() const; |
| 782 |
|
| 783 |
void set_uv1_triplanar_blend_sharpness(float p_sharpness); |
| 784 |
float get_uv1_triplanar_blend_sharpness() const; |
| 785 |
|
| 786 |
void set_uv2_scale(const Vector3 &p_scale); |
| 787 |
Vector3 get_uv2_scale() const; |
| 788 |
|
| 789 |
void set_uv2_offset(const Vector3 &p_offset); |
| 790 |
Vector3 get_uv2_offset() const; |
| 791 |
|
| 792 |
void set_uv2_triplanar_blend_sharpness(float p_sharpness); |
| 793 |
float get_uv2_triplanar_blend_sharpness() const; |
| 794 |
|
| 795 |
void set_billboard_mode(BillboardMode p_mode); |
| 796 |
BillboardMode get_billboard_mode() const; |
| 797 |
|
| 798 |
void set_particles_anim_h_frames(int p_frames); |
| 799 |
int get_particles_anim_h_frames() const; |
| 800 |
void set_particles_anim_v_frames(int p_frames); |
| 801 |
int get_particles_anim_v_frames() const; |
| 802 |
|
| 803 |
void set_particles_anim_loop(bool p_loop); |
| 804 |
bool get_particles_anim_loop() const; |
| 805 |
|
| 806 |
void set_grow_enabled(bool p_enable); |
| 807 |
bool is_grow_enabled() const; |
| 808 |
|
| 809 |
void set_grow(float p_grow); |
| 810 |
float get_grow() const; |
| 811 |
|
| 812 |
void set_alpha_scissor_threshold(float p_threshold); |
| 813 |
float get_alpha_scissor_threshold() const; |
| 814 |
|
| 815 |
void set_alpha_hash_scale(float p_scale); |
| 816 |
float get_alpha_hash_scale() const; |
| 817 |
|
| 818 |
void set_on_top_of_alpha(); |
| 819 |
|
| 820 |
void set_proximity_fade_enabled(bool p_enable); |
| 821 |
bool is_proximity_fade_enabled() const; |
| 822 |
|
| 823 |
void set_proximity_fade_distance(float p_distance); |
| 824 |
float get_proximity_fade_distance() const; |
| 825 |
|
| 826 |
void set_msdf_pixel_range(float p_range); |
| 827 |
float get_msdf_pixel_range() const; |
| 828 |
|
| 829 |
void set_msdf_outline_size(float p_size); |
| 830 |
float get_msdf_outline_size() const; |
| 831 |
|
| 832 |
void set_distance_fade(DistanceFadeMode p_mode); |
| 833 |
DistanceFadeMode get_distance_fade() const; |
| 834 |
|
| 835 |
void set_distance_fade_max_distance(float p_distance); |
| 836 |
float get_distance_fade_max_distance() const; |
| 837 |
|
| 838 |
void set_distance_fade_min_distance(float p_distance); |
| 839 |
float get_distance_fade_min_distance() const; |
| 840 |
|
| 841 |
void set_emission_operator(EmissionOperator p_op); |
| 842 |
EmissionOperator get_emission_operator() const; |
| 843 |
|
| 844 |
void set_stencil_mode(StencilMode p_stencil_mode); |
| 845 |
StencilMode get_stencil_mode() const; |
| 846 |
|
| 847 |
void set_stencil_flags(int p_stencil_flags); |
| 848 |
int get_stencil_flags() const; |
| 849 |
|
| 850 |
void set_stencil_compare(StencilCompare p_op); |
| 851 |
StencilCompare get_stencil_compare() const; |
| 852 |
|
| 853 |
void set_stencil_reference(int p_reference); |
| 854 |
int get_stencil_reference() const; |
| 855 |
|
| 856 |
void set_stencil_effect_color(const Color &p_color); |
| 857 |
Color get_stencil_effect_color() const; |
| 858 |
|
| 859 |
void set_stencil_effect_outline_thickness(float p_outline_thickness); |
| 860 |
float get_stencil_effect_outline_thickness() const; |
| 861 |
|
| 862 |
void set_metallic_texture_channel(TextureChannel p_channel); |
| 863 |
TextureChannel get_metallic_texture_channel() const; |
| 864 |
void set_roughness_texture_channel(TextureChannel p_channel); |
| 865 |
TextureChannel get_roughness_texture_channel() const; |
| 866 |
void set_ao_texture_channel(TextureChannel p_channel); |
| 867 |
TextureChannel get_ao_texture_channel() const; |
| 868 |
void set_refraction_texture_channel(TextureChannel p_channel); |
| 869 |
TextureChannel get_refraction_texture_channel() const; |
| 870 |
|
| 871 |
void set_z_clip_scale(float p_z_clip_scale); |
| 872 |
float get_z_clip_scale() const; |
| 873 |
void set_fov_override(float p_fov_override); |
| 874 |
float get_fov_override() const; |
| 875 |
|
| 876 |
static void init_shaders(); |
| 877 |
static void finish_shaders(); |
| 878 |
static void flush_changes(); |
| 879 |
|
| 880 |
static Ref<Material> get_material_for_2d(bool p_shaded, Transparency p_transparency, bool p_double_sided, bool p_billboard = false, bool p_billboard_y = false, bool p_msdf = false, bool p_no_depth = false, bool p_fixed_size = false, TextureFilter p_filter = TEXTURE_FILTER_LINEAR_WITH_MIPMAPS, AlphaAntiAliasing p_alpha_antialiasing_mode = ALPHA_ANTIALIASING_OFF, bool p_texture_repeat = false, RID *r_shader_rid = nullptr); |
| 881 |
|
| 882 |
virtual RID get_rid() const override; |
| 883 |
virtual RID get_shader_rid() const override; |
| 884 |
|
| 885 |
virtual Shader::Mode get_shader_mode() const override; |
| 886 |
|
| 887 |
BaseMaterial3D(bool p_orm); |
| 888 |
virtual ~BaseMaterial3D(); |
| 889 |
}; |
| 890 |
|
| 891 |
VARIANT_ENUM_CAST(BaseMaterial3D::TextureParam) |
| 892 |
VARIANT_ENUM_CAST(BaseMaterial3D::TextureFilter) |
| 893 |
VARIANT_ENUM_CAST(BaseMaterial3D::ShadingMode) |
| 894 |
VARIANT_ENUM_CAST(BaseMaterial3D::Transparency) |
| 895 |
VARIANT_ENUM_CAST(BaseMaterial3D::AlphaAntiAliasing) |
| 896 |
VARIANT_ENUM_CAST(BaseMaterial3D::DetailUV) |
| 897 |
VARIANT_ENUM_CAST(BaseMaterial3D::Feature) |
| 898 |
VARIANT_ENUM_CAST(BaseMaterial3D::BlendMode) |
| 899 |
VARIANT_ENUM_CAST(BaseMaterial3D::DepthDrawMode) |
| 900 |
VARIANT_ENUM_CAST(BaseMaterial3D::DepthTest) |
| 901 |
VARIANT_ENUM_CAST(BaseMaterial3D::CullMode) |
| 902 |
VARIANT_ENUM_CAST(BaseMaterial3D::Flags) |
| 903 |
VARIANT_ENUM_CAST(BaseMaterial3D::DiffuseMode) |
| 904 |
VARIANT_ENUM_CAST(BaseMaterial3D::SpecularMode) |
| 905 |
VARIANT_ENUM_CAST(BaseMaterial3D::BillboardMode) |
| 906 |
VARIANT_ENUM_CAST(BaseMaterial3D::TextureChannel) |
| 907 |
VARIANT_ENUM_CAST(BaseMaterial3D::EmissionOperator) |
| 908 |
VARIANT_ENUM_CAST(BaseMaterial3D::DistanceFadeMode) |
| 909 |
VARIANT_ENUM_CAST(BaseMaterial3D::StencilMode) |
| 910 |
VARIANT_ENUM_CAST(BaseMaterial3D::StencilFlags) |
| 911 |
VARIANT_ENUM_CAST(BaseMaterial3D::StencilCompare) |
| 912 |
|
| 913 |
class StandardMaterial3D : public BaseMaterial3D { |
| 914 |
GDCLASS(StandardMaterial3D, BaseMaterial3D) |
| 915 |
protected: |
| 916 |
#ifndef DISABLE_DEPRECATED |
| 917 |
|
| 918 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 919 |
#endif |
| 920 |
|
| 921 |
public: |
| 922 |
StandardMaterial3D() : |
| 923 |
BaseMaterial3D(false) {} |
| 924 |
}; |
| 925 |
|
| 926 |
class ORMMaterial3D : public BaseMaterial3D { |
| 927 |
GDCLASS(ORMMaterial3D, BaseMaterial3D) |
| 928 |
public: |
| 929 |
ORMMaterial3D() : |
| 930 |
BaseMaterial3D(true) {} |
| 931 |
}; |
| 932 |
|
| 933 |
class PlaceholderMaterial : public Material { |
| 934 |
GDCLASS(PlaceholderMaterial, Material) |
| 935 |
public: |
| 936 |
virtual RID get_shader_rid() const override { return RID(); } |
| 937 |
virtual Shader::Mode get_shader_mode() const override { return Shader::MODE_CANVAS_ITEM; } |
| 938 |
}; |
| 939 |
|
| 940 |
|