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