Debian Codegraph @

scene/resources/3d/sky_material.h

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