1/**************************************************************************/
2/* material.h */
3/**************************************************************************/
4/* This file is part of: */
5/* GODOT ENGINE */
6/* https://godotengine.org */
7/**************************************************************************/
8/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10/* */
11/* Permission is hereby granted, free of charge, to any person obtaining */
12/* a copy of this software and associated documentation files (the */
13/* "Software"), to deal in the Software without restriction, including */
14/* without limitation the rights to use, copy, modify, merge, publish, */
15/* distribute, sublicense, and/or sell copies of the Software, and to */
16/* permit persons to whom the Software is furnished to do so, subject to */
17/* the following conditions: */
18/* */
19/* The above copyright notice and this permission notice shall be */
20/* included in all copies or substantial portions of the Software. */
21/* */
22/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29/**************************************************************************/
30
31#ifndef MATERIAL_H
32#define MATERIAL_H
33
34#include "core/io/resource.h"
35#include "core/templates/self_list.h"
36#include "scene/resources/shader.h"
37#include "scene/resources/texture.h"
38#include "servers/rendering_server.h"
39
40class Material : public Resource {
41 GDCLASS(Material, Resource);
42 RES_BASE_EXTENSION("material")
43 OBJ_SAVE_TYPE(Material);
44
45 RID material;
46 Ref<Material> next_pass;
47 int render_priority;
48
49 enum {
50 INIT_STATE_UNINITIALIZED,
51 INIT_STATE_INITIALIZING,
52 INIT_STATE_READY,
53 } init_state = INIT_STATE_UNINITIALIZED;
54
55 void inspect_native_shader_code();
56
57protected:
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_initialized(const Callable &p_queue_shader_change_callable);
66 bool _is_initialized() { return init_state == INIT_STATE_READY; }
67
68 GDVIRTUAL0RC(RID, _get_shader_rid)
69 GDVIRTUAL0RC(Shader::Mode, _get_shader_mode)
70 GDVIRTUAL0RC(bool, _can_do_next_pass)
71 GDVIRTUAL0RC(bool, _can_use_render_priority)
72public:
73 enum {
74 RENDER_PRIORITY_MAX = RS::MATERIAL_RENDER_PRIORITY_MAX,
75 RENDER_PRIORITY_MIN = RS::MATERIAL_RENDER_PRIORITY_MIN,
76 };
77 void set_next_pass(const Ref<Material> &p_pass);
78 Ref<Material> get_next_pass() const;
79
80 void set_render_priority(int p_priority);
81 int get_render_priority() const;
82
83 virtual RID get_rid() const override;
84 virtual RID get_shader_rid() const;
85 virtual Shader::Mode get_shader_mode() const;
86
87 virtual Ref<Resource> create_placeholder() const;
88
89 Material();
90 virtual ~Material();
91};
92
93class ShaderMaterial : public Material {
94 GDCLASS(ShaderMaterial, Material);
95 Ref<Shader> shader;
96
97 mutable HashMap<StringName, StringName> remap_cache;
98 mutable HashMap<StringName, Variant> param_cache;
99
100protected:
101 bool _set(const StringName &p_name, const Variant &p_value);
102 bool _get(const StringName &p_name, Variant &r_ret) const;
103 void _get_property_list(List<PropertyInfo> *p_list) const;
104 bool _property_can_revert(const StringName &p_name) const;
105 bool _property_get_revert(const StringName &p_name, Variant &r_property) const;
106
107 static void _bind_methods();
108
109 void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
110
111 virtual bool _can_do_next_pass() const override;
112 virtual bool _can_use_render_priority() const override;
113
114 void _shader_changed();
115
116public:
117 void set_shader(const Ref<Shader> &p_shader);
118 Ref<Shader> get_shader() const;
119
120 void set_shader_parameter(const StringName &p_param, const Variant &p_value);
121 Variant get_shader_parameter(const StringName &p_param) const;
122
123 virtual Shader::Mode get_shader_mode() const override;
124
125 virtual RID get_shader_rid() const override;
126
127 ShaderMaterial();
128 ~ShaderMaterial();
129};
130
131class StandardMaterial3D;
132
133class BaseMaterial3D : public Material {
134 GDCLASS(BaseMaterial3D, Material);
135
136public:
137 enum TextureParam {
138 TEXTURE_ALBEDO,
139 TEXTURE_METALLIC,
140 TEXTURE_ROUGHNESS,
141 TEXTURE_EMISSION,
142 TEXTURE_NORMAL,
143 TEXTURE_RIM,
144 TEXTURE_CLEARCOAT,
145 TEXTURE_FLOWMAP,
146 TEXTURE_AMBIENT_OCCLUSION,
147 TEXTURE_HEIGHTMAP,
148 TEXTURE_SUBSURFACE_SCATTERING,
149 TEXTURE_SUBSURFACE_TRANSMITTANCE,
150 TEXTURE_BACKLIGHT,
151 TEXTURE_REFRACTION,
152 TEXTURE_DETAIL_MASK,
153 TEXTURE_DETAIL_ALBEDO,
154 TEXTURE_DETAIL_NORMAL,
155 TEXTURE_ORM,
156 TEXTURE_MAX
157
158 };
159
160 enum TextureFilter {
161 TEXTURE_FILTER_NEAREST,
162 TEXTURE_FILTER_LINEAR,
163 TEXTURE_FILTER_NEAREST_WITH_MIPMAPS,
164 TEXTURE_FILTER_LINEAR_WITH_MIPMAPS,
165 TEXTURE_FILTER_NEAREST_WITH_MIPMAPS_ANISOTROPIC,
166 TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC,
167 TEXTURE_FILTER_MAX
168 };
169
170 enum DetailUV {
171 DETAIL_UV_1,
172 DETAIL_UV_2,
173 DETAIL_UV_MAX
174 };
175
176 enum Transparency {
177 TRANSPARENCY_DISABLED,
178 TRANSPARENCY_ALPHA,
179 TRANSPARENCY_ALPHA_SCISSOR,
180 TRANSPARENCY_ALPHA_HASH,
181 TRANSPARENCY_ALPHA_DEPTH_PRE_PASS,
182 TRANSPARENCY_MAX,
183 };
184
185 enum AlphaAntiAliasing {
186 ALPHA_ANTIALIASING_OFF,
187 ALPHA_ANTIALIASING_ALPHA_TO_COVERAGE,
188 ALPHA_ANTIALIASING_ALPHA_TO_COVERAGE_AND_TO_ONE,
189 ALPHA_ANTIALIASING_MAX
190 };
191
192 enum ShadingMode {
193 SHADING_MODE_UNSHADED,
194 SHADING_MODE_PER_PIXEL,
195 SHADING_MODE_PER_VERTEX,
196 SHADING_MODE_MAX
197 };
198
199 enum Feature {
200 FEATURE_EMISSION,
201 FEATURE_NORMAL_MAPPING,
202 FEATURE_RIM,
203 FEATURE_CLEARCOAT,
204 FEATURE_ANISOTROPY,
205 FEATURE_AMBIENT_OCCLUSION,
206 FEATURE_HEIGHT_MAPPING,
207 FEATURE_SUBSURFACE_SCATTERING,
208 FEATURE_SUBSURFACE_TRANSMITTANCE,
209 FEATURE_BACKLIGHT,
210 FEATURE_REFRACTION,
211 FEATURE_DETAIL,
212 FEATURE_MAX
213 };
214
215 enum BlendMode {
216 BLEND_MODE_MIX,
217 BLEND_MODE_ADD,
218 BLEND_MODE_SUB,
219 BLEND_MODE_MUL,
220 BLEND_MODE_MAX
221 };
222
223 enum DepthDrawMode {
224 DEPTH_DRAW_OPAQUE_ONLY,
225 DEPTH_DRAW_ALWAYS,
226 DEPTH_DRAW_DISABLED,
227 DEPTH_DRAW_MAX
228 };
229
230 enum CullMode {
231 CULL_BACK,
232 CULL_FRONT,
233 CULL_DISABLED,
234 CULL_MAX
235 };
236
237 enum Flags {
238 FLAG_DISABLE_DEPTH_TEST,
239 FLAG_ALBEDO_FROM_VERTEX_COLOR,
240 FLAG_SRGB_VERTEX_COLOR,
241 FLAG_USE_POINT_SIZE,
242 FLAG_FIXED_SIZE,
243 FLAG_BILLBOARD_KEEP_SCALE,
244 FLAG_UV1_USE_TRIPLANAR,
245 FLAG_UV2_USE_TRIPLANAR,
246 FLAG_UV1_USE_WORLD_TRIPLANAR,
247 FLAG_UV2_USE_WORLD_TRIPLANAR,
248 FLAG_AO_ON_UV2,
249 FLAG_EMISSION_ON_UV2,
250 FLAG_ALBEDO_TEXTURE_FORCE_SRGB,
251 FLAG_DONT_RECEIVE_SHADOWS,
252 FLAG_DISABLE_AMBIENT_LIGHT,
253 FLAG_USE_SHADOW_TO_OPACITY,
254 FLAG_USE_TEXTURE_REPEAT,
255 FLAG_INVERT_HEIGHTMAP,
256 FLAG_SUBSURFACE_MODE_SKIN,
257 FLAG_PARTICLE_TRAILS_MODE,
258 FLAG_ALBEDO_TEXTURE_MSDF,
259 FLAG_DISABLE_FOG,
260 FLAG_MAX
261 };
262
263 enum DiffuseMode {
264 DIFFUSE_BURLEY,
265 DIFFUSE_LAMBERT,
266 DIFFUSE_LAMBERT_WRAP,
267 DIFFUSE_TOON,
268 DIFFUSE_MAX
269 };
270
271 enum SpecularMode {
272 SPECULAR_SCHLICK_GGX,
273 SPECULAR_TOON,
274 SPECULAR_DISABLED,
275 SPECULAR_MAX
276 };
277
278 enum BillboardMode {
279 BILLBOARD_DISABLED,
280 BILLBOARD_ENABLED,
281 BILLBOARD_FIXED_Y,
282 BILLBOARD_PARTICLES,
283 BILLBOARD_MAX
284 };
285
286 enum TextureChannel {
287 TEXTURE_CHANNEL_RED,
288 TEXTURE_CHANNEL_GREEN,
289 TEXTURE_CHANNEL_BLUE,
290 TEXTURE_CHANNEL_ALPHA,
291 TEXTURE_CHANNEL_GRAYSCALE,
292 TEXTURE_CHANNEL_MAX
293 };
294
295 enum EmissionOperator {
296 EMISSION_OP_ADD,
297 EMISSION_OP_MULTIPLY,
298 EMISSION_OP_MAX
299 };
300
301 enum DistanceFadeMode {
302 DISTANCE_FADE_DISABLED,
303 DISTANCE_FADE_PIXEL_ALPHA,
304 DISTANCE_FADE_PIXEL_DITHER,
305 DISTANCE_FADE_OBJECT_DITHER,
306 DISTANCE_FADE_MAX
307 };
308
309private:
310 struct MaterialKey {
311 // enum values
312 uint64_t texture_filter : get_num_bits(TEXTURE_FILTER_MAX - 1);
313 uint64_t detail_uv : get_num_bits(DETAIL_UV_MAX - 1);
314 uint64_t transparency : get_num_bits(TRANSPARENCY_MAX - 1);
315 uint64_t alpha_antialiasing_mode : get_num_bits(ALPHA_ANTIALIASING_MAX - 1);
316 uint64_t shading_mode : get_num_bits(SHADING_MODE_MAX - 1);
317 uint64_t blend_mode : get_num_bits(BLEND_MODE_MAX - 1);
318 uint64_t depth_draw_mode : get_num_bits(DEPTH_DRAW_MAX - 1);
319 uint64_t cull_mode : get_num_bits(CULL_MAX - 1);
320 uint64_t diffuse_mode : get_num_bits(DIFFUSE_MAX - 1);
321 uint64_t specular_mode : get_num_bits(SPECULAR_MAX - 1);
322 uint64_t billboard_mode : get_num_bits(BILLBOARD_MAX - 1);
323 uint64_t detail_blend_mode : get_num_bits(BLEND_MODE_MAX - 1);
324 uint64_t roughness_channel : get_num_bits(TEXTURE_CHANNEL_MAX - 1);
325 uint64_t emission_op : get_num_bits(EMISSION_OP_MAX - 1);
326 uint64_t distance_fade : get_num_bits(DISTANCE_FADE_MAX - 1);
327 // booleans
328 uint64_t deep_parallax : 1;
329 uint64_t grow : 1;
330 uint64_t proximity_fade : 1;
331 uint64_t orm : 1;
332
333 // flag bitfield
334 uint32_t feature_mask;
335 uint32_t flags;
336
337 MaterialKey() {
338 memset(this, 0, sizeof(MaterialKey));
339 }
340
341 static uint32_t hash(const MaterialKey &p_key) {
342 return hash_djb2_buffer((const uint8_t *)&p_key, sizeof(MaterialKey));
343 }
344 bool operator==(const MaterialKey &p_key) const {
345 return memcmp(this, &p_key, sizeof(MaterialKey)) == 0;
346 }
347
348 bool operator<(const MaterialKey &p_key) const {
349 return memcmp(this, &p_key, sizeof(MaterialKey)) < 0;
350 }
351 };
352
353 struct ShaderData {
354 RID shader;
355 int users = 0;
356 };
357
358 static HashMap<MaterialKey, ShaderData, MaterialKey> shader_map;
359
360 MaterialKey current_key;
361
362 _FORCE_INLINE_ MaterialKey _compute_key() const {
363 MaterialKey mk;
364
365 mk.detail_uv = detail_uv;
366 mk.blend_mode = blend_mode;
367 mk.depth_draw_mode = depth_draw_mode;
368 mk.cull_mode = cull_mode;
369 mk.texture_filter = texture_filter;
370 mk.transparency = transparency;
371 mk.shading_mode = shading_mode;
372 mk.roughness_channel = roughness_texture_channel;
373 mk.detail_blend_mode = detail_blend_mode;
374 mk.diffuse_mode = diffuse_mode;
375 mk.specular_mode = specular_mode;
376 mk.billboard_mode = billboard_mode;
377 mk.deep_parallax = deep_parallax;
378 mk.grow = grow_enabled;
379 mk.proximity_fade = proximity_fade_enabled;
380 mk.distance_fade = distance_fade;
381 mk.emission_op = emission_op;
382 mk.alpha_antialiasing_mode = alpha_antialiasing_mode;
383 mk.orm = orm;
384
385 for (int i = 0; i < FEATURE_MAX; i++) {
386 if (features[i]) {
387 mk.feature_mask |= ((uint64_t)1 << i);
388 }
389 }
390
391 for (int i = 0; i < FLAG_MAX; i++) {
392 if (flags[i]) {
393 mk.flags |= ((uint64_t)1 << i);
394 }
395 }
396
397 return mk;
398 }
399
400 struct ShaderNames {
401 StringName albedo;
402 StringName specular;
403 StringName metallic;
404 StringName roughness;
405 StringName emission;
406 StringName emission_energy;
407 StringName normal_scale;
408 StringName rim;
409 StringName rim_tint;
410 StringName clearcoat;
411 StringName clearcoat_roughness;
412 StringName anisotropy;
413 StringName heightmap_scale;
414 StringName subsurface_scattering_strength;
415 StringName transmittance_color;
416 StringName transmittance_depth;
417 StringName transmittance_boost;
418 StringName backlight;
419 StringName refraction;
420 StringName point_size;
421 StringName uv1_scale;
422 StringName uv1_offset;
423 StringName uv2_scale;
424 StringName uv2_offset;
425 StringName particles_anim_h_frames;
426 StringName particles_anim_v_frames;
427 StringName particles_anim_loop;
428 StringName heightmap_min_layers;
429 StringName heightmap_max_layers;
430 StringName heightmap_flip;
431 StringName uv1_blend_sharpness;
432 StringName uv2_blend_sharpness;
433 StringName grow;
434 StringName proximity_fade_distance;
435 StringName msdf_pixel_range;
436 StringName msdf_outline_size;
437 StringName distance_fade_min;
438 StringName distance_fade_max;
439 StringName ao_light_affect;
440
441 StringName metallic_texture_channel;
442 StringName ao_texture_channel;
443 StringName clearcoat_texture_channel;
444 StringName rim_texture_channel;
445 StringName heightmap_texture_channel;
446 StringName refraction_texture_channel;
447
448 StringName texture_names[TEXTURE_MAX];
449
450 StringName alpha_scissor_threshold;
451 StringName alpha_hash_scale;
452
453 StringName alpha_antialiasing_edge;
454 StringName albedo_texture_size;
455 };
456
457 static Mutex material_mutex;
458 static SelfList<BaseMaterial3D>::List dirty_materials;
459 static ShaderNames *shader_names;
460
461 SelfList<BaseMaterial3D> element;
462
463 void _update_shader();
464 _FORCE_INLINE_ void _queue_shader_change();
465 _FORCE_INLINE_ bool _is_shader_dirty() const;
466
467 bool orm;
468
469 Color albedo;
470 float specular = 0.0f;
471 float metallic = 0.0f;
472 float roughness = 0.0f;
473 Color emission;
474 float emission_energy_multiplier = 1.0f;
475 float emission_intensity = 1000.0f; // In nits, equivalent to indoor lighting.
476 float normal_scale = 0.0f;
477 float rim = 0.0f;
478 float rim_tint = 0.0f;
479 float clearcoat = 0.0f;
480 float clearcoat_roughness = 0.0f;
481 float anisotropy = 0.0f;
482 float heightmap_scale = 0.0f;
483 float subsurface_scattering_strength = 0.0f;
484 float transmittance_amount = 0.0f;
485 Color transmittance_color;
486 float transmittance_depth = 0.0f;
487 float transmittance_boost = 0.0f;
488
489 Color backlight;
490 float refraction = 0.0f;
491 float point_size = 0.0f;
492 float alpha_scissor_threshold = 0.0f;
493 float alpha_hash_scale = 0.0f;
494 float alpha_antialiasing_edge = 0.0f;
495 bool grow_enabled = false;
496 float ao_light_affect = 0.0f;
497 float grow = 0.0f;
498 int particles_anim_h_frames = 0;
499 int particles_anim_v_frames = 0;
500 bool particles_anim_loop = false;
501 Transparency transparency = TRANSPARENCY_DISABLED;
502 ShadingMode shading_mode = SHADING_MODE_PER_PIXEL;
503
504 TextureFilter texture_filter = TEXTURE_FILTER_LINEAR_WITH_MIPMAPS;
505
506 Vector3 uv1_scale;
507 Vector3 uv1_offset;
508 float uv1_triplanar_sharpness = 0.0f;
509
510 Vector3 uv2_scale;
511 Vector3 uv2_offset;
512 float uv2_triplanar_sharpness = 0.0f;
513
514 DetailUV detail_uv = DETAIL_UV_1;
515
516 bool deep_parallax = false;
517 int deep_parallax_min_layers = 0;
518 int deep_parallax_max_layers = 0;
519 bool heightmap_parallax_flip_tangent = false;
520 bool heightmap_parallax_flip_binormal = false;
521
522 bool proximity_fade_enabled = false;
523 float proximity_fade_distance = 0.0f;
524
525 float msdf_pixel_range = 4.f;
526 float msdf_outline_size = 0.f;
527
528 DistanceFadeMode distance_fade = DISTANCE_FADE_DISABLED;
529 float distance_fade_max_distance = 0.0f;
530 float distance_fade_min_distance = 0.0f;
531
532 BlendMode blend_mode = BLEND_MODE_MIX;
533 BlendMode detail_blend_mode = BLEND_MODE_MIX;
534 DepthDrawMode depth_draw_mode = DEPTH_DRAW_OPAQUE_ONLY;
535 CullMode cull_mode = CULL_BACK;
536 bool flags[FLAG_MAX] = {};
537 SpecularMode specular_mode = SPECULAR_SCHLICK_GGX;
538 DiffuseMode diffuse_mode = DIFFUSE_BURLEY;
539 BillboardMode billboard_mode;
540 EmissionOperator emission_op = EMISSION_OP_ADD;
541
542 TextureChannel metallic_texture_channel;
543 TextureChannel roughness_texture_channel;
544 TextureChannel ao_texture_channel;
545 TextureChannel refraction_texture_channel;
546
547 AlphaAntiAliasing alpha_antialiasing_mode = ALPHA_ANTIALIASING_OFF;
548
549 bool features[FEATURE_MAX] = {};
550
551 Ref<Texture2D> textures[TEXTURE_MAX];
552
553 _FORCE_INLINE_ void _validate_feature(const String &text, Feature feature, PropertyInfo &property) const;
554
555 static HashMap<uint64_t, Ref<StandardMaterial3D>> materials_for_2d; //used by Sprite3D, Label3D and other stuff
556
557protected:
558 static void _bind_methods();
559 void _validate_property(PropertyInfo &p_property) const;
560 virtual bool _can_do_next_pass() const override { return true; }
561 virtual bool _can_use_render_priority() const override { return true; }
562
563public:
564 void set_albedo(const Color &p_albedo);
565 Color get_albedo() const;
566
567 void set_specular(float p_specular);
568 float get_specular() const;
569
570 void set_metallic(float p_metallic);
571 float get_metallic() const;
572
573 void set_roughness(float p_roughness);
574 float get_roughness() const;
575
576 void set_emission(const Color &p_emission);
577 Color get_emission() const;
578
579 void set_emission_energy_multiplier(float p_emission_energy_multiplier);
580 float get_emission_energy_multiplier() const;
581
582 void set_emission_intensity(float p_emission_intensity);
583 float get_emission_intensity() const;
584
585 void set_normal_scale(float p_normal_scale);
586 float get_normal_scale() const;
587
588 void set_rim(float p_rim);
589 float get_rim() const;
590
591 void set_rim_tint(float p_rim_tint);
592 float get_rim_tint() const;
593
594 void set_ao_light_affect(float p_ao_light_affect);
595 float get_ao_light_affect() const;
596
597 void set_clearcoat(float p_clearcoat);
598 float get_clearcoat() const;
599
600 void set_clearcoat_roughness(float p_clearcoat_roughness);
601 float get_clearcoat_roughness() const;
602
603 void set_anisotropy(float p_anisotropy);
604 float get_anisotropy() const;
605
606 void set_heightmap_scale(float p_heightmap_scale);
607 float get_heightmap_scale() const;
608
609 void set_heightmap_deep_parallax(bool p_enable);
610 bool is_heightmap_deep_parallax_enabled() const;
611
612 void set_heightmap_deep_parallax_min_layers(int p_layer);
613 int get_heightmap_deep_parallax_min_layers() const;
614
615 void set_heightmap_deep_parallax_max_layers(int p_layer);
616 int get_heightmap_deep_parallax_max_layers() const;
617
618 void set_heightmap_deep_parallax_flip_tangent(bool p_flip);
619 bool get_heightmap_deep_parallax_flip_tangent() const;
620
621 void set_heightmap_deep_parallax_flip_binormal(bool p_flip);
622 bool get_heightmap_deep_parallax_flip_binormal() const;
623
624 void set_subsurface_scattering_strength(float p_subsurface_scattering_strength);
625 float get_subsurface_scattering_strength() const;
626
627 void set_transmittance_color(const Color &p_color);
628 Color get_transmittance_color() const;
629
630 void set_transmittance_depth(float p_depth);
631 float get_transmittance_depth() const;
632
633 void set_transmittance_boost(float p_boost);
634 float get_transmittance_boost() const;
635
636 void set_backlight(const Color &p_backlight);
637 Color get_backlight() const;
638
639 void set_refraction(float p_refraction);
640 float get_refraction() const;
641
642 void set_point_size(float p_point_size);
643 float get_point_size() const;
644
645 void set_transparency(Transparency p_transparency);
646 Transparency get_transparency() const;
647
648 void set_alpha_antialiasing(AlphaAntiAliasing p_alpha_aa);
649 AlphaAntiAliasing get_alpha_antialiasing() const;
650
651 void set_alpha_antialiasing_edge(float p_edge);
652 float get_alpha_antialiasing_edge() const;
653
654 void set_shading_mode(ShadingMode p_shading_mode);
655 ShadingMode get_shading_mode() const;
656
657 void set_detail_uv(DetailUV p_detail_uv);
658 DetailUV get_detail_uv() const;
659
660 void set_blend_mode(BlendMode p_mode);
661 BlendMode get_blend_mode() const;
662
663 void set_detail_blend_mode(BlendMode p_mode);
664 BlendMode get_detail_blend_mode() const;
665
666 void set_depth_draw_mode(DepthDrawMode p_mode);
667 DepthDrawMode get_depth_draw_mode() const;
668
669 void set_cull_mode(CullMode p_mode);
670 CullMode get_cull_mode() const;
671
672 void set_diffuse_mode(DiffuseMode p_mode);
673 DiffuseMode get_diffuse_mode() const;
674
675 void set_specular_mode(SpecularMode p_mode);
676 SpecularMode get_specular_mode() const;
677
678 void set_flag(Flags p_flag, bool p_enabled);
679 bool get_flag(Flags p_flag) const;
680
681 void set_texture(TextureParam p_param, const Ref<Texture2D> &p_texture);
682 Ref<Texture2D> get_texture(TextureParam p_param) const;
683 // Used only for shader material conversion
684 Ref<Texture2D> get_texture_by_name(StringName p_name) const;
685
686 void set_texture_filter(TextureFilter p_filter);
687 TextureFilter get_texture_filter() const;
688
689 void set_feature(Feature p_feature, bool p_enabled);
690 bool get_feature(Feature p_feature) const;
691
692 void set_uv1_scale(const Vector3 &p_scale);
693 Vector3 get_uv1_scale() const;
694
695 void set_uv1_offset(const Vector3 &p_offset);
696 Vector3 get_uv1_offset() const;
697
698 void set_uv1_triplanar_blend_sharpness(float p_sharpness);
699 float get_uv1_triplanar_blend_sharpness() const;
700
701 void set_uv2_scale(const Vector3 &p_scale);
702 Vector3 get_uv2_scale() const;
703
704 void set_uv2_offset(const Vector3 &p_offset);
705 Vector3 get_uv2_offset() const;
706
707 void set_uv2_triplanar_blend_sharpness(float p_sharpness);
708 float get_uv2_triplanar_blend_sharpness() const;
709
710 void set_billboard_mode(BillboardMode p_mode);
711 BillboardMode get_billboard_mode() const;
712
713 void set_particles_anim_h_frames(int p_frames);
714 int get_particles_anim_h_frames() const;
715 void set_particles_anim_v_frames(int p_frames);
716 int get_particles_anim_v_frames() const;
717
718 void set_particles_anim_loop(bool p_loop);
719 bool get_particles_anim_loop() const;
720
721 void set_grow_enabled(bool p_enable);
722 bool is_grow_enabled() const;
723
724 void set_grow(float p_grow);
725 float get_grow() const;
726
727 void set_alpha_scissor_threshold(float p_threshold);
728 float get_alpha_scissor_threshold() const;
729
730 void set_alpha_hash_scale(float p_scale);
731 float get_alpha_hash_scale() const;
732
733 void set_on_top_of_alpha();
734
735 void set_proximity_fade_enabled(bool p_enable);
736 bool is_proximity_fade_enabled() const;
737
738 void set_proximity_fade_distance(float p_distance);
739 float get_proximity_fade_distance() const;
740
741 void set_msdf_pixel_range(float p_range);
742 float get_msdf_pixel_range() const;
743
744 void set_msdf_outline_size(float p_size);
745 float get_msdf_outline_size() const;
746
747 void set_distance_fade(DistanceFadeMode p_mode);
748 DistanceFadeMode get_distance_fade() const;
749
750 void set_distance_fade_max_distance(float p_distance);
751 float get_distance_fade_max_distance() const;
752
753 void set_distance_fade_min_distance(float p_distance);
754 float get_distance_fade_min_distance() const;
755
756 void set_emission_operator(EmissionOperator p_op);
757 EmissionOperator get_emission_operator() const;
758
759 void set_metallic_texture_channel(TextureChannel p_channel);
760 TextureChannel get_metallic_texture_channel() const;
761 void set_roughness_texture_channel(TextureChannel p_channel);
762 TextureChannel get_roughness_texture_channel() const;
763 void set_ao_texture_channel(TextureChannel p_channel);
764 TextureChannel get_ao_texture_channel() const;
765 void set_refraction_texture_channel(TextureChannel p_channel);
766 TextureChannel get_refraction_texture_channel() const;
767
768 static void init_shaders();
769 static void finish_shaders();
770 static void flush_changes();
771
772 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, RID *r_shader_rid = nullptr);
773
774 virtual RID get_shader_rid() const override;
775
776 virtual Shader::Mode get_shader_mode() const override;
777
778 BaseMaterial3D(bool p_orm);
779 virtual ~BaseMaterial3D();
780};
781
782VARIANT_ENUM_CAST(BaseMaterial3D::TextureParam)
783VARIANT_ENUM_CAST(BaseMaterial3D::TextureFilter)
784VARIANT_ENUM_CAST(BaseMaterial3D::ShadingMode)
785VARIANT_ENUM_CAST(BaseMaterial3D::Transparency)
786VARIANT_ENUM_CAST(BaseMaterial3D::AlphaAntiAliasing)
787VARIANT_ENUM_CAST(BaseMaterial3D::DetailUV)
788VARIANT_ENUM_CAST(BaseMaterial3D::Feature)
789VARIANT_ENUM_CAST(BaseMaterial3D::BlendMode)
790VARIANT_ENUM_CAST(BaseMaterial3D::DepthDrawMode)
791VARIANT_ENUM_CAST(BaseMaterial3D::CullMode)
792VARIANT_ENUM_CAST(BaseMaterial3D::Flags)
793VARIANT_ENUM_CAST(BaseMaterial3D::DiffuseMode)
794VARIANT_ENUM_CAST(BaseMaterial3D::SpecularMode)
795VARIANT_ENUM_CAST(BaseMaterial3D::BillboardMode)
796VARIANT_ENUM_CAST(BaseMaterial3D::TextureChannel)
797VARIANT_ENUM_CAST(BaseMaterial3D::EmissionOperator)
798VARIANT_ENUM_CAST(BaseMaterial3D::DistanceFadeMode)
799
800class StandardMaterial3D : public BaseMaterial3D {
801 GDCLASS(StandardMaterial3D, BaseMaterial3D)
802protected:
803#ifndef DISABLE_DEPRECATED
804 // Kept for compatibility from 3.x to 4.0.
805 bool _set(const StringName &p_name, const Variant &p_value);
806#endif
807
808public:
809 StandardMaterial3D() :
810 BaseMaterial3D(false) {}
811};
812
813class ORMMaterial3D : public BaseMaterial3D {
814 GDCLASS(ORMMaterial3D, BaseMaterial3D)
815public:
816 ORMMaterial3D() :
817 BaseMaterial3D(true) {}
818};
819
820class PlaceholderMaterial : public Material {
821 GDCLASS(PlaceholderMaterial, Material)
822public:
823 virtual RID get_shader_rid() const override { return RID(); }
824 virtual Shader::Mode get_shader_mode() const override { return Shader::MODE_CANVAS_ITEM; }
825};
826
827//////////////////////
828
829#endif // MATERIAL_H
830