| 1 | /**************************************************************************/ |
| 2 | /* sky_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 SKY_MATERIAL_H |
| 32 | #define SKY_MATERIAL_H |
| 33 | |
| 34 | #include "core/templates/rid.h" |
| 35 | #include "scene/resources/material.h" |
| 36 | |
| 37 | class ProceduralSkyMaterial : public Material { |
| 38 | GDCLASS(ProceduralSkyMaterial, Material); |
| 39 | |
| 40 | private: |
| 41 | Color sky_top_color; |
| 42 | Color sky_horizon_color; |
| 43 | float sky_curve = 0.0f; |
| 44 | float sky_energy_multiplier = 0.0f; |
| 45 | Ref<Texture2D> sky_cover; |
| 46 | Color sky_cover_modulate; |
| 47 | |
| 48 | Color ground_bottom_color; |
| 49 | Color ground_horizon_color; |
| 50 | float ground_curve = 0.0f; |
| 51 | float ground_energy_multiplier = 0.0f; |
| 52 | |
| 53 | float sun_angle_max = 0.0f; |
| 54 | float sun_curve = 0.0f; |
| 55 | bool use_debanding = true; |
| 56 | |
| 57 | static Mutex shader_mutex; |
| 58 | static RID shader_cache[2]; |
| 59 | static void _update_shader(); |
| 60 | mutable bool shader_set = false; |
| 61 | |
| 62 | protected: |
| 63 | static void _bind_methods(); |
| 64 | void _validate_property(PropertyInfo &property) const; |
| 65 | |
| 66 | public: |
| 67 | void set_sky_top_color(const Color &p_sky_top); |
| 68 | Color get_sky_top_color() const; |
| 69 | |
| 70 | void set_sky_horizon_color(const Color &p_sky_horizon); |
| 71 | Color get_sky_horizon_color() const; |
| 72 | |
| 73 | void set_sky_curve(float p_curve); |
| 74 | float get_sky_curve() const; |
| 75 | |
| 76 | void set_sky_energy_multiplier(float p_multiplier); |
| 77 | float get_sky_energy_multiplier() const; |
| 78 | |
| 79 | void set_sky_cover(const Ref<Texture2D> &p_sky_cover); |
| 80 | Ref<Texture2D> get_sky_cover() const; |
| 81 | |
| 82 | void set_sky_cover_modulate(const Color &p_sky_cover_modulate); |
| 83 | Color get_sky_cover_modulate() const; |
| 84 | |
| 85 | void set_ground_bottom_color(const Color &p_ground_bottom); |
| 86 | Color get_ground_bottom_color() const; |
| 87 | |
| 88 | void set_ground_horizon_color(const Color &p_ground_horizon); |
| 89 | Color get_ground_horizon_color() const; |
| 90 | |
| 91 | void set_ground_curve(float p_curve); |
| 92 | float get_ground_curve() const; |
| 93 | |
| 94 | void set_ground_energy_multiplier(float p_energy); |
| 95 | float get_ground_energy_multiplier() const; |
| 96 | |
| 97 | void set_sun_angle_max(float p_angle); |
| 98 | float get_sun_angle_max() const; |
| 99 | |
| 100 | void set_sun_curve(float p_curve); |
| 101 | float get_sun_curve() const; |
| 102 | |
| 103 | void set_use_debanding(bool p_use_debanding); |
| 104 | bool get_use_debanding() const; |
| 105 | |
| 106 | virtual Shader::Mode get_shader_mode() const override; |
| 107 | virtual RID get_shader_rid() const override; |
| 108 | virtual RID get_rid() const override; |
| 109 | |
| 110 | static void cleanup_shader(); |
| 111 | |
| 112 | ProceduralSkyMaterial(); |
| 113 | ~ProceduralSkyMaterial(); |
| 114 | }; |
| 115 | |
| 116 | ////////////////////////////////////////////////////// |
| 117 | /* PanoramaSkyMaterial */ |
| 118 | |
| 119 | class PanoramaSkyMaterial : public Material { |
| 120 | GDCLASS(PanoramaSkyMaterial, Material); |
| 121 | |
| 122 | private: |
| 123 | Ref<Texture2D> panorama; |
| 124 | |
| 125 | static Mutex shader_mutex; |
| 126 | static RID shader_cache[2]; |
| 127 | static void _update_shader(); |
| 128 | mutable bool shader_set = false; |
| 129 | |
| 130 | bool filter = true; |
| 131 | |
| 132 | protected: |
| 133 | static void _bind_methods(); |
| 134 | |
| 135 | public: |
| 136 | void set_panorama(const Ref<Texture2D> &p_panorama); |
| 137 | Ref<Texture2D> get_panorama() const; |
| 138 | |
| 139 | void set_filtering_enabled(bool p_enabled); |
| 140 | bool is_filtering_enabled() const; |
| 141 | |
| 142 | void set_energy_multiplier(float p_multiplier); |
| 143 | float get_energy_multiplier() const; |
| 144 | |
| 145 | virtual Shader::Mode get_shader_mode() const override; |
| 146 | virtual RID get_shader_rid() const override; |
| 147 | virtual RID get_rid() const override; |
| 148 | |
| 149 | static void cleanup_shader(); |
| 150 | |
| 151 | PanoramaSkyMaterial(); |
| 152 | ~PanoramaSkyMaterial(); |
| 153 | }; |
| 154 | |
| 155 | ////////////////////////////////////////////////////// |
| 156 | /* PanoramaSkyMaterial */ |
| 157 | |
| 158 | class PhysicalSkyMaterial : public Material { |
| 159 | GDCLASS(PhysicalSkyMaterial, Material); |
| 160 | |
| 161 | private: |
| 162 | static Mutex shader_mutex; |
| 163 | static RID shader_cache[2]; |
| 164 | |
| 165 | float rayleigh = 0.0f; |
| 166 | Color rayleigh_color; |
| 167 | float mie = 0.0f; |
| 168 | float mie_eccentricity = 0.0f; |
| 169 | Color mie_color; |
| 170 | float turbidity = 0.0f; |
| 171 | float sun_disk_scale = 0.0f; |
| 172 | Color ground_color; |
| 173 | float energy_multiplier = 1.0f; |
| 174 | bool use_debanding = true; |
| 175 | Ref<Texture2D> night_sky; |
| 176 | static void _update_shader(); |
| 177 | mutable bool shader_set = false; |
| 178 | |
| 179 | protected: |
| 180 | static void _bind_methods(); |
| 181 | void _validate_property(PropertyInfo &property) const; |
| 182 | |
| 183 | public: |
| 184 | void set_rayleigh_coefficient(float p_rayleigh); |
| 185 | float get_rayleigh_coefficient() const; |
| 186 | |
| 187 | void set_rayleigh_color(Color p_rayleigh_color); |
| 188 | Color get_rayleigh_color() const; |
| 189 | |
| 190 | void set_turbidity(float p_turbidity); |
| 191 | float get_turbidity() const; |
| 192 | |
| 193 | void set_mie_coefficient(float p_mie); |
| 194 | float get_mie_coefficient() const; |
| 195 | |
| 196 | void set_mie_eccentricity(float p_eccentricity); |
| 197 | float get_mie_eccentricity() const; |
| 198 | |
| 199 | void set_mie_color(Color p_mie_color); |
| 200 | Color get_mie_color() const; |
| 201 | |
| 202 | void set_sun_disk_scale(float p_sun_disk_scale); |
| 203 | float get_sun_disk_scale() const; |
| 204 | |
| 205 | void set_ground_color(Color p_ground_color); |
| 206 | Color get_ground_color() const; |
| 207 | |
| 208 | void set_energy_multiplier(float p_multiplier); |
| 209 | float get_energy_multiplier() const; |
| 210 | |
| 211 | void set_exposure_value(float p_exposure); |
| 212 | float get_exposure_value() const; |
| 213 | |
| 214 | void set_use_debanding(bool p_use_debanding); |
| 215 | bool get_use_debanding() const; |
| 216 | |
| 217 | void set_night_sky(const Ref<Texture2D> &p_night_sky); |
| 218 | Ref<Texture2D> get_night_sky() const; |
| 219 | |
| 220 | virtual Shader::Mode get_shader_mode() const override; |
| 221 | virtual RID get_shader_rid() const override; |
| 222 | |
| 223 | static void cleanup_shader(); |
| 224 | virtual RID get_rid() const override; |
| 225 | |
| 226 | PhysicalSkyMaterial(); |
| 227 | ~PhysicalSkyMaterial(); |
| 228 | }; |
| 229 | |
| 230 | #endif // SKY_MATERIAL_H |
| 231 | |