Debian Codegraph @

scene/resources/environment.h

raw symbols SCIP
1 /**************************************************************************/
2 /* environment.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/io/resource.h"
34 #include "scene/resources/sky.h"
35 #include "scene/resources/texture.h"
36
37 class Environment : public Resource {
38 GDCLASS(Environment, Resource);
39
40 public:
41 enum BGMode {
42 BG_CLEAR_COLOR,
43 BG_COLOR,
44 BG_SKY,
45 BG_CANVAS,
46 BG_KEEP,
47 BG_CAMERA_FEED,
48 BG_MAX
49 };
50
51 enum AmbientSource {
52 AMBIENT_SOURCE_BG,
53 AMBIENT_SOURCE_DISABLED,
54 AMBIENT_SOURCE_COLOR,
55 AMBIENT_SOURCE_SKY,
56 };
57
58 enum ReflectionSource {
59 REFLECTION_SOURCE_BG,
60 REFLECTION_SOURCE_DISABLED,
61 REFLECTION_SOURCE_SKY,
62 };
63
64 enum ToneMapper {
65 TONE_MAPPER_LINEAR,
66 TONE_MAPPER_REINHARDT,
67 TONE_MAPPER_FILMIC,
68 TONE_MAPPER_ACES,
69 TONE_MAPPER_AGX,
70 };
71
72 enum SDFGIYScale {
73 SDFGI_Y_SCALE_50_PERCENT,
74 SDFGI_Y_SCALE_75_PERCENT,
75 SDFGI_Y_SCALE_100_PERCENT,
76 };
77
78 enum FogMode {
79 FOG_MODE_EXPONENTIAL,
80 FOG_MODE_DEPTH,
81 };
82
83 enum GlowBlendMode {
84 GLOW_BLEND_MODE_ADDITIVE,
85 GLOW_BLEND_MODE_SCREEN,
86 GLOW_BLEND_MODE_SOFTLIGHT,
87 GLOW_BLEND_MODE_REPLACE,
88 GLOW_BLEND_MODE_MIX,
89 };
90
91 private:
92 RID environment;
93
94 // Background
95 BGMode bg_mode = BG_CLEAR_COLOR;
96 Ref<Sky> bg_sky;
97 float bg_sky_custom_fov = 0.0;
98 Vector3 bg_sky_rotation;
99 Color bg_color;
100 int bg_canvas_max_layer = 0;
101 int bg_camera_feed_id = 1;
102 float bg_energy_multiplier = 1.0;
103 float bg_intensity = 30000.0; // Measured in nits or candela/m^2
104 void _update_bg_energy();
105
106 // Ambient light
107 Color ambient_color;
108 AmbientSource ambient_source = AMBIENT_SOURCE_BG;
109 float ambient_energy = 1.0;
110 float ambient_sky_contribution = 1.0;
111 ReflectionSource reflection_source = REFLECTION_SOURCE_BG;
112 void _update_ambient_light();
113
114 // Tonemap
115 ToneMapper tone_mapper = TONE_MAPPER_LINEAR;
116 float tonemap_exposure = 1.0;
117 float tonemap_white = 1.0;
118 float tonemap_agx_white = 16.29; // Default to Blender's AgX white.
119 float tonemap_agx_contrast = 1.25; // Default to approximately Blender's AgX contrast.
120 void _update_tonemap();
121
122 // SSR
123 bool ssr_enabled = false;
124 int ssr_max_steps = 64;
125 float ssr_fade_in = 0.15;
126 float ssr_fade_out = 2.0;
127 float ssr_depth_tolerance = 0.5;
128 void _update_ssr();
129
130 // SSAO
131 bool ssao_enabled = false;
132 float ssao_radius = 1.0;
133 float ssao_intensity = 2.0;
134 float ssao_power = 1.5;
135 float ssao_detail = 0.5;
136 float ssao_horizon = 0.06;
137 float ssao_sharpness = 0.98;
138 float ssao_direct_light_affect = 0.0;
139 float ssao_ao_channel_affect = 0.0;
140 void _update_ssao();
141
142 // SSIL
143 bool ssil_enabled = false;
144 float ssil_radius = 5.0;
145 float ssil_intensity = 1.0;
146 float ssil_sharpness = 0.98;
147 float ssil_normal_rejection = 1.0;
148
149 void _update_ssil();
150
151 // SDFGI
152 bool sdfgi_enabled = false;
153 int sdfgi_cascades = 4;
154 float sdfgi_min_cell_size = 0.2;
155 SDFGIYScale sdfgi_y_scale = SDFGI_Y_SCALE_75_PERCENT;
156 bool sdfgi_use_occlusion = false;
157 float sdfgi_bounce_feedback = 0.5;
158 bool sdfgi_read_sky_light = true;
159 float sdfgi_energy = 1.0;
160 float sdfgi_normal_bias = 1.1;
161 float sdfgi_probe_bias = 1.1;
162 void _update_sdfgi();
163
164 // Glow
165 bool glow_enabled = false;
166 Vector<float> glow_levels;
167 bool glow_normalize_levels = false;
168 float glow_intensity = 0.3;
169 float glow_strength = 1.0;
170 float glow_mix = 0.05;
171 float glow_bloom = 0.0;
172 GlowBlendMode glow_blend_mode = GLOW_BLEND_MODE_SCREEN;
173 float glow_hdr_bleed_threshold = 1.0;
174 float glow_hdr_bleed_scale = 2.0;
175 float glow_hdr_luminance_cap = 12.0;
176 float glow_map_strength = 0.8f;
177 Ref<Texture> glow_map;
178 void _update_glow();
179
180 // Fog
181 bool fog_enabled = false;
182 FogMode fog_mode = FOG_MODE_EXPONENTIAL;
183 Color fog_light_color = Color(0.518, 0.553, 0.608);
184 float fog_light_energy = 1.0;
185 float fog_sun_scatter = 0.0;
186 float fog_density = 0.01;
187 float fog_height = 0.0;
188 float fog_height_density = 0.0; //can be negative to invert effect
189 float fog_aerial_perspective = 0.0;
190 float fog_sky_affect = 1.0;
191
192 void _update_fog();
193
194 // Depth Fog
195 float fog_depth_curve = 1.0;
196 float fog_depth_begin = 10.0;
197 float fog_depth_end = 100.0;
198
199 void _update_fog_depth();
200
201 // Volumetric Fog
202 bool volumetric_fog_enabled = false;
203 float volumetric_fog_density = 0.05;
204 Color volumetric_fog_albedo = Color(1.0, 1.0, 1.0);
205 Color volumetric_fog_emission = Color(0.0, 0.0, 0.0);
206 float volumetric_fog_emission_energy = 1.0;
207 float volumetric_fog_anisotropy = 0.2;
208 float volumetric_fog_length = 64.0;
209 float volumetric_fog_detail_spread = 2.0;
210 float volumetric_fog_gi_inject = 1.0;
211 float volumetric_fog_ambient_inject = 0.0;
212 float volumetric_fog_sky_affect = 1.0;
213 bool volumetric_fog_temporal_reproject = true;
214 float volumetric_fog_temporal_reproject_amount = 0.9;
215 void _update_volumetric_fog();
216
217 // Adjustment
218 bool adjustment_enabled = false;
219 float adjustment_brightness = 1.0;
220 float adjustment_contrast = 1.0;
221 float adjustment_saturation = 1.0;
222 bool use_1d_color_correction = true;
223 Ref<Texture> adjustment_color_correction;
224 void _update_adjustment();
225
226 protected:
227 static void _bind_methods();
228 void _validate_property(PropertyInfo &p_property) const;
229 #ifndef DISABLE_DEPRECATED
230 // Kept for compatibility from 3.x to 4.0.
231 bool _set(const StringName &p_name, const Variant &p_value);
232 #endif
233
234 public:
235 virtual RID get_rid() const override;
236
237 // Background
238 void set_background(BGMode p_bg);
239 BGMode get_background() const;
240 void set_sky(const Ref<Sky> &p_sky);
241 Ref<Sky> get_sky() const;
242 void set_sky_custom_fov(float p_scale);
243 float get_sky_custom_fov() const;
244 void set_sky_rotation(const Vector3 &p_rotation);
245 Vector3 get_sky_rotation() const;
246 void set_bg_color(const Color &p_color);
247 Color get_bg_color() const;
248 void set_bg_energy_multiplier(float p_energy);
249 float get_bg_energy_multiplier() const;
250 void set_bg_intensity(float p_energy);
251 float get_bg_intensity() const;
252 void set_canvas_max_layer(int p_max_layer);
253 int get_canvas_max_layer() const;
254 void set_camera_feed_id(int p_id);
255 int get_camera_feed_id() const;
256
257 // Ambient light
258 void set_ambient_light_color(const Color &p_color);
259 Color get_ambient_light_color() const;
260 void set_ambient_source(AmbientSource p_source);
261 AmbientSource get_ambient_source() const;
262 void set_ambient_light_energy(float p_energy);
263 float get_ambient_light_energy() const;
264 void set_ambient_light_sky_contribution(float p_ratio);
265 float get_ambient_light_sky_contribution() const;
266 void set_reflection_source(ReflectionSource p_source);
267 ReflectionSource get_reflection_source() const;
268
269 // Tonemap
270 void set_tonemapper(ToneMapper p_tone_mapper);
271 ToneMapper get_tonemapper() const;
272 void set_tonemap_exposure(float p_exposure);
273 float get_tonemap_exposure() const;
274 void set_tonemap_white(float p_white);
275 float get_tonemap_white() const;
276 void set_tonemap_agx_white(float p_white);
277 float get_tonemap_agx_white() const;
278 void set_tonemap_agx_contrast(float p_agx_contrast);
279 float get_tonemap_agx_contrast() const;
280
281 // SSR
282 void set_ssr_enabled(bool p_enabled);
283 bool is_ssr_enabled() const;
284 void set_ssr_max_steps(int p_steps);
285 int get_ssr_max_steps() const;
286 void set_ssr_fade_in(float p_fade_in);
287 float get_ssr_fade_in() const;
288 void set_ssr_fade_out(float p_fade_out);
289 float get_ssr_fade_out() const;
290 void set_ssr_depth_tolerance(float p_depth_tolerance);
291 float get_ssr_depth_tolerance() const;
292
293 // SSAO
294 void set_ssao_enabled(bool p_enabled);
295 bool is_ssao_enabled() const;
296 void set_ssao_radius(float p_radius);
297 float get_ssao_radius() const;
298 void set_ssao_intensity(float p_intensity);
299 float get_ssao_intensity() const;
300 void set_ssao_power(float p_power);
301 float get_ssao_power() const;
302 void set_ssao_detail(float p_detail);
303 float get_ssao_detail() const;
304 void set_ssao_horizon(float p_horizon);
305 float get_ssao_horizon() const;
306 void set_ssao_sharpness(float p_sharpness);
307 float get_ssao_sharpness() const;
308 void set_ssao_direct_light_affect(float p_direct_light_affect);
309 float get_ssao_direct_light_affect() const;
310 void set_ssao_ao_channel_affect(float p_ao_channel_affect);
311 float get_ssao_ao_channel_affect() const;
312
313 // SSIL
314 void set_ssil_enabled(bool p_enabled);
315 bool is_ssil_enabled() const;
316 void set_ssil_radius(float p_radius);
317 float get_ssil_radius() const;
318 void set_ssil_intensity(float p_intensity);
319 float get_ssil_intensity() const;
320 void set_ssil_sharpness(float p_sharpness);
321 float get_ssil_sharpness() const;
322 void set_ssil_normal_rejection(float p_normal_rejection);
323 float get_ssil_normal_rejection() const;
324
325 // SDFGI
326 void set_sdfgi_enabled(bool p_enabled);
327 bool is_sdfgi_enabled() const;
328 void set_sdfgi_cascades(int p_cascades);
329 int get_sdfgi_cascades() const;
330 void set_sdfgi_min_cell_size(float p_size);
331 float get_sdfgi_min_cell_size() const;
332 void set_sdfgi_max_distance(float p_distance);
333 float get_sdfgi_max_distance() const;
334 void set_sdfgi_cascade0_distance(float p_distance);
335 float get_sdfgi_cascade0_distance() const;
336 void set_sdfgi_y_scale(SDFGIYScale p_y_scale);
337 SDFGIYScale get_sdfgi_y_scale() const;
338 void set_sdfgi_use_occlusion(bool p_enabled);
339 bool is_sdfgi_using_occlusion() const;
340 void set_sdfgi_bounce_feedback(float p_amount);
341 float get_sdfgi_bounce_feedback() const;
342 void set_sdfgi_read_sky_light(bool p_enabled);
343 bool is_sdfgi_reading_sky_light() const;
344 void set_sdfgi_energy(float p_energy);
345 float get_sdfgi_energy() const;
346 void set_sdfgi_normal_bias(float p_bias);
347 float get_sdfgi_normal_bias() const;
348 void set_sdfgi_probe_bias(float p_bias);
349 float get_sdfgi_probe_bias() const;
350
351 // Glow
352 void set_glow_enabled(bool p_enabled);
353 bool is_glow_enabled() const;
354 void set_glow_level(int p_level, float p_intensity);
355 float get_glow_level(int p_level) const;
356 void set_glow_normalized(bool p_normalized);
357 bool is_glow_normalized() const;
358 void set_glow_intensity(float p_intensity);
359 float get_glow_intensity() const;
360 void set_glow_strength(float p_strength);
361 float get_glow_strength() const;
362 void set_glow_mix(float p_mix);
363 float get_glow_mix() const;
364 void set_glow_bloom(float p_threshold);
365 float get_glow_bloom() const;
366 void set_glow_blend_mode(GlowBlendMode p_mode);
367 GlowBlendMode get_glow_blend_mode() const;
368 void set_glow_hdr_bleed_threshold(float p_threshold);
369 float get_glow_hdr_bleed_threshold() const;
370 void set_glow_hdr_bleed_scale(float p_scale);
371 float get_glow_hdr_bleed_scale() const;
372 void set_glow_hdr_luminance_cap(float p_amount);
373 float get_glow_hdr_luminance_cap() const;
374 void set_glow_map_strength(float p_strength);
375 float get_glow_map_strength() const;
376 void set_glow_map(Ref<Texture> p_glow_map);
377 Ref<Texture> get_glow_map() const;
378
379 // Fog
380
381 void set_fog_enabled(bool p_enabled);
382 bool is_fog_enabled() const;
383 void set_fog_mode(FogMode p_mode);
384 FogMode get_fog_mode() const;
385 void set_fog_light_color(const Color &p_light_color);
386 Color get_fog_light_color() const;
387 void set_fog_light_energy(float p_amount);
388 float get_fog_light_energy() const;
389 void set_fog_sun_scatter(float p_amount);
390 float get_fog_sun_scatter() const;
391
392 void set_fog_density(float p_amount);
393 float get_fog_density() const;
394 void set_fog_height(float p_amount);
395 float get_fog_height() const;
396 void set_fog_height_density(float p_amount);
397 float get_fog_height_density() const;
398 void set_fog_aerial_perspective(float p_aerial_perspective);
399 float get_fog_aerial_perspective() const;
400 void set_fog_sky_affect(float p_sky_affect);
401 float get_fog_sky_affect() const;
402
403 // Depth Fog
404 void set_fog_depth_curve(float p_curve);
405 float get_fog_depth_curve() const;
406 void set_fog_depth_begin(float p_begin);
407 float get_fog_depth_begin() const;
408 void set_fog_depth_end(float p_end);
409 float get_fog_depth_end() const;
410
411 // Volumetric Fog
412 void set_volumetric_fog_enabled(bool p_enable);
413 bool is_volumetric_fog_enabled() const;
414 void set_volumetric_fog_density(float p_density);
415 float get_volumetric_fog_density() const;
416 void set_volumetric_fog_albedo(Color p_color);
417 Color get_volumetric_fog_albedo() const;
418 void set_volumetric_fog_emission(Color p_color);
419 Color get_volumetric_fog_emission() const;
420 void set_volumetric_fog_emission_energy(float p_begin);
421 float get_volumetric_fog_emission_energy() const;
422 void set_volumetric_fog_anisotropy(float p_anisotropy);
423 float get_volumetric_fog_anisotropy() const;
424 void set_volumetric_fog_length(float p_length);
425 float get_volumetric_fog_length() const;
426 void set_volumetric_fog_detail_spread(float p_detail_spread);
427 float get_volumetric_fog_detail_spread() const;
428 void set_volumetric_fog_gi_inject(float p_gi_inject);
429 float get_volumetric_fog_gi_inject() const;
430 void set_volumetric_fog_ambient_inject(float p_ambient_inject);
431 float get_volumetric_fog_ambient_inject() const;
432 void set_volumetric_fog_sky_affect(float p_sky_affect);
433 float get_volumetric_fog_sky_affect() const;
434 void set_volumetric_fog_temporal_reprojection_enabled(bool p_enable);
435 bool is_volumetric_fog_temporal_reprojection_enabled() const;
436 void set_volumetric_fog_temporal_reprojection_amount(float p_amount);
437 float get_volumetric_fog_temporal_reprojection_amount() const;
438
439 // Adjustment
440 void set_adjustment_enabled(bool p_enabled);
441 bool is_adjustment_enabled() const;
442 void set_adjustment_brightness(float p_brightness);
443 float get_adjustment_brightness() const;
444 void set_adjustment_contrast(float p_contrast);
445 float get_adjustment_contrast() const;
446 void set_adjustment_saturation(float p_saturation);
447 float get_adjustment_saturation() const;
448 void set_adjustment_color_correction(Ref<Texture> p_color_correction);
449 Ref<Texture> get_adjustment_color_correction() const;
450
451 Environment();
452 ~Environment();
453 };
454
455 VARIANT_ENUM_CAST(Environment::BGMode)
456 VARIANT_ENUM_CAST(Environment::AmbientSource)
457 VARIANT_ENUM_CAST(Environment::ReflectionSource)
458 VARIANT_ENUM_CAST(Environment::ToneMapper)
459 VARIANT_ENUM_CAST(Environment::SDFGIYScale)
460 VARIANT_ENUM_CAST(Environment::GlowBlendMode)
461 VARIANT_ENUM_CAST(Environment::FogMode)