decal.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**************************************************************************/
  2. /* decal.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. #pragma once
  31. #include "scene/3d/visual_instance_3d.h"
  32. class Decal : public VisualInstance3D {
  33. GDCLASS(Decal, VisualInstance3D);
  34. public:
  35. enum DecalTexture {
  36. TEXTURE_ALBEDO,
  37. TEXTURE_NORMAL,
  38. TEXTURE_ORM,
  39. TEXTURE_EMISSION,
  40. TEXTURE_MAX
  41. };
  42. private:
  43. RID decal;
  44. Vector3 size = Vector3(2, 2, 2);
  45. Ref<Texture2D> textures[TEXTURE_MAX];
  46. real_t emission_energy = 1.0;
  47. real_t albedo_mix = 1.0;
  48. Color modulate = Color(1, 1, 1, 1);
  49. uint32_t cull_mask = (1 << 20) - 1;
  50. real_t normal_fade = 0.0;
  51. real_t upper_fade = 0.3;
  52. real_t lower_fade = 0.3;
  53. bool distance_fade_enabled = false;
  54. real_t distance_fade_begin = 40.0;
  55. real_t distance_fade_length = 10.0;
  56. protected:
  57. static void _bind_methods();
  58. void _validate_property(PropertyInfo &p_property) const;
  59. #ifndef DISABLE_DEPRECATED
  60. bool _set(const StringName &p_name, const Variant &p_value);
  61. bool _get(const StringName &p_name, Variant &r_property) const;
  62. #endif // DISABLE_DEPRECATED
  63. public:
  64. virtual PackedStringArray get_configuration_warnings() const override;
  65. void set_size(const Vector3 &p_size);
  66. Vector3 get_size() const;
  67. void set_texture(DecalTexture p_type, const Ref<Texture2D> &p_texture);
  68. Ref<Texture2D> get_texture(DecalTexture p_type) const;
  69. void set_emission_energy(real_t p_energy);
  70. real_t get_emission_energy() const;
  71. void set_albedo_mix(real_t p_mix);
  72. real_t get_albedo_mix() const;
  73. void set_modulate(Color p_modulate);
  74. Color get_modulate() const;
  75. void set_upper_fade(real_t p_energy);
  76. real_t get_upper_fade() const;
  77. void set_lower_fade(real_t p_fade);
  78. real_t get_lower_fade() const;
  79. void set_normal_fade(real_t p_fade);
  80. real_t get_normal_fade() const;
  81. void set_enable_distance_fade(bool p_enable);
  82. bool is_distance_fade_enabled() const;
  83. void set_distance_fade_begin(real_t p_distance);
  84. real_t get_distance_fade_begin() const;
  85. void set_distance_fade_length(real_t p_length);
  86. real_t get_distance_fade_length() const;
  87. void set_cull_mask(uint32_t p_layers);
  88. uint32_t get_cull_mask() const;
  89. virtual AABB get_aabb() const override;
  90. Decal();
  91. ~Decal();
  92. };
  93. VARIANT_ENUM_CAST(Decal::DecalTexture);