Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/resources/environment.h
9902 views
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
void _update_tonemap();
119
120
// SSR
121
bool ssr_enabled = false;
122
int ssr_max_steps = 64;
123
float ssr_fade_in = 0.15;
124
float ssr_fade_out = 2.0;
125
float ssr_depth_tolerance = 0.2;
126
void _update_ssr();
127
128
// SSAO
129
bool ssao_enabled = false;
130
float ssao_radius = 1.0;
131
float ssao_intensity = 2.0;
132
float ssao_power = 1.5;
133
float ssao_detail = 0.5;
134
float ssao_horizon = 0.06;
135
float ssao_sharpness = 0.98;
136
float ssao_direct_light_affect = 0.0;
137
float ssao_ao_channel_affect = 0.0;
138
void _update_ssao();
139
140
// SSIL
141
bool ssil_enabled = false;
142
float ssil_radius = 5.0;
143
float ssil_intensity = 1.0;
144
float ssil_sharpness = 0.98;
145
float ssil_normal_rejection = 1.0;
146
147
void _update_ssil();
148
149
// SDFGI
150
bool sdfgi_enabled = false;
151
int sdfgi_cascades = 4;
152
float sdfgi_min_cell_size = 0.2;
153
SDFGIYScale sdfgi_y_scale = SDFGI_Y_SCALE_75_PERCENT;
154
bool sdfgi_use_occlusion = false;
155
float sdfgi_bounce_feedback = 0.5;
156
bool sdfgi_read_sky_light = true;
157
float sdfgi_energy = 1.0;
158
float sdfgi_normal_bias = 1.1;
159
float sdfgi_probe_bias = 1.1;
160
void _update_sdfgi();
161
162
// Glow
163
bool glow_enabled = false;
164
Vector<float> glow_levels;
165
bool glow_normalize_levels = false;
166
float glow_intensity = 0.8;
167
float glow_strength = 1.0;
168
float glow_mix = 0.05;
169
float glow_bloom = 0.0;
170
GlowBlendMode glow_blend_mode = GLOW_BLEND_MODE_SOFTLIGHT;
171
float glow_hdr_bleed_threshold = 1.0;
172
float glow_hdr_bleed_scale = 2.0;
173
float glow_hdr_luminance_cap = 12.0;
174
float glow_map_strength = 0.8f;
175
Ref<Texture> glow_map;
176
void _update_glow();
177
178
// Fog
179
bool fog_enabled = false;
180
FogMode fog_mode = FOG_MODE_EXPONENTIAL;
181
Color fog_light_color = Color(0.518, 0.553, 0.608);
182
float fog_light_energy = 1.0;
183
float fog_sun_scatter = 0.0;
184
float fog_density = 0.01;
185
float fog_height = 0.0;
186
float fog_height_density = 0.0; //can be negative to invert effect
187
float fog_aerial_perspective = 0.0;
188
float fog_sky_affect = 1.0;
189
190
void _update_fog();
191
192
// Depth Fog
193
float fog_depth_curve = 1.0;
194
float fog_depth_begin = 10.0;
195
float fog_depth_end = 100.0;
196
197
void _update_fog_depth();
198
199
// Volumetric Fog
200
bool volumetric_fog_enabled = false;
201
float volumetric_fog_density = 0.05;
202
Color volumetric_fog_albedo = Color(1.0, 1.0, 1.0);
203
Color volumetric_fog_emission = Color(0.0, 0.0, 0.0);
204
float volumetric_fog_emission_energy = 1.0;
205
float volumetric_fog_anisotropy = 0.2;
206
float volumetric_fog_length = 64.0;
207
float volumetric_fog_detail_spread = 2.0;
208
float volumetric_fog_gi_inject = 1.0;
209
float volumetric_fog_ambient_inject = 0.0;
210
float volumetric_fog_sky_affect = 1.0;
211
bool volumetric_fog_temporal_reproject = true;
212
float volumetric_fog_temporal_reproject_amount = 0.9;
213
void _update_volumetric_fog();
214
215
// Adjustment
216
bool adjustment_enabled = false;
217
float adjustment_brightness = 1.0;
218
float adjustment_contrast = 1.0;
219
float adjustment_saturation = 1.0;
220
bool use_1d_color_correction = true;
221
Ref<Texture> adjustment_color_correction;
222
void _update_adjustment();
223
224
protected:
225
static void _bind_methods();
226
void _validate_property(PropertyInfo &p_property) const;
227
#ifndef DISABLE_DEPRECATED
228
// Kept for compatibility from 3.x to 4.0.
229
bool _set(const StringName &p_name, const Variant &p_value);
230
#endif
231
232
public:
233
virtual RID get_rid() const override;
234
235
// Background
236
void set_background(BGMode p_bg);
237
BGMode get_background() const;
238
void set_sky(const Ref<Sky> &p_sky);
239
Ref<Sky> get_sky() const;
240
void set_sky_custom_fov(float p_scale);
241
float get_sky_custom_fov() const;
242
void set_sky_rotation(const Vector3 &p_rotation);
243
Vector3 get_sky_rotation() const;
244
void set_bg_color(const Color &p_color);
245
Color get_bg_color() const;
246
void set_bg_energy_multiplier(float p_energy);
247
float get_bg_energy_multiplier() const;
248
void set_bg_intensity(float p_energy);
249
float get_bg_intensity() const;
250
void set_canvas_max_layer(int p_max_layer);
251
int get_canvas_max_layer() const;
252
void set_camera_feed_id(int p_id);
253
int get_camera_feed_id() const;
254
255
// Ambient light
256
void set_ambient_light_color(const Color &p_color);
257
Color get_ambient_light_color() const;
258
void set_ambient_source(AmbientSource p_source);
259
AmbientSource get_ambient_source() const;
260
void set_ambient_light_energy(float p_energy);
261
float get_ambient_light_energy() const;
262
void set_ambient_light_sky_contribution(float p_ratio);
263
float get_ambient_light_sky_contribution() const;
264
void set_reflection_source(ReflectionSource p_source);
265
ReflectionSource get_reflection_source() const;
266
267
// Tonemap
268
void set_tonemapper(ToneMapper p_tone_mapper);
269
ToneMapper get_tonemapper() const;
270
void set_tonemap_exposure(float p_exposure);
271
float get_tonemap_exposure() const;
272
void set_tonemap_white(float p_white);
273
float get_tonemap_white() const;
274
275
// SSR
276
void set_ssr_enabled(bool p_enabled);
277
bool is_ssr_enabled() const;
278
void set_ssr_max_steps(int p_steps);
279
int get_ssr_max_steps() const;
280
void set_ssr_fade_in(float p_fade_in);
281
float get_ssr_fade_in() const;
282
void set_ssr_fade_out(float p_fade_out);
283
float get_ssr_fade_out() const;
284
void set_ssr_depth_tolerance(float p_depth_tolerance);
285
float get_ssr_depth_tolerance() const;
286
287
// SSAO
288
void set_ssao_enabled(bool p_enabled);
289
bool is_ssao_enabled() const;
290
void set_ssao_radius(float p_radius);
291
float get_ssao_radius() const;
292
void set_ssao_intensity(float p_intensity);
293
float get_ssao_intensity() const;
294
void set_ssao_power(float p_power);
295
float get_ssao_power() const;
296
void set_ssao_detail(float p_detail);
297
float get_ssao_detail() const;
298
void set_ssao_horizon(float p_horizon);
299
float get_ssao_horizon() const;
300
void set_ssao_sharpness(float p_sharpness);
301
float get_ssao_sharpness() const;
302
void set_ssao_direct_light_affect(float p_direct_light_affect);
303
float get_ssao_direct_light_affect() const;
304
void set_ssao_ao_channel_affect(float p_ao_channel_affect);
305
float get_ssao_ao_channel_affect() const;
306
307
// SSIL
308
void set_ssil_enabled(bool p_enabled);
309
bool is_ssil_enabled() const;
310
void set_ssil_radius(float p_radius);
311
float get_ssil_radius() const;
312
void set_ssil_intensity(float p_intensity);
313
float get_ssil_intensity() const;
314
void set_ssil_sharpness(float p_sharpness);
315
float get_ssil_sharpness() const;
316
void set_ssil_normal_rejection(float p_normal_rejection);
317
float get_ssil_normal_rejection() const;
318
319
// SDFGI
320
void set_sdfgi_enabled(bool p_enabled);
321
bool is_sdfgi_enabled() const;
322
void set_sdfgi_cascades(int p_cascades);
323
int get_sdfgi_cascades() const;
324
void set_sdfgi_min_cell_size(float p_size);
325
float get_sdfgi_min_cell_size() const;
326
void set_sdfgi_max_distance(float p_distance);
327
float get_sdfgi_max_distance() const;
328
void set_sdfgi_cascade0_distance(float p_distance);
329
float get_sdfgi_cascade0_distance() const;
330
void set_sdfgi_y_scale(SDFGIYScale p_y_scale);
331
SDFGIYScale get_sdfgi_y_scale() const;
332
void set_sdfgi_use_occlusion(bool p_enabled);
333
bool is_sdfgi_using_occlusion() const;
334
void set_sdfgi_bounce_feedback(float p_amount);
335
float get_sdfgi_bounce_feedback() const;
336
void set_sdfgi_read_sky_light(bool p_enabled);
337
bool is_sdfgi_reading_sky_light() const;
338
void set_sdfgi_energy(float p_energy);
339
float get_sdfgi_energy() const;
340
void set_sdfgi_normal_bias(float p_bias);
341
float get_sdfgi_normal_bias() const;
342
void set_sdfgi_probe_bias(float p_bias);
343
float get_sdfgi_probe_bias() const;
344
345
// Glow
346
void set_glow_enabled(bool p_enabled);
347
bool is_glow_enabled() const;
348
void set_glow_level(int p_level, float p_intensity);
349
float get_glow_level(int p_level) const;
350
void set_glow_normalized(bool p_normalized);
351
bool is_glow_normalized() const;
352
void set_glow_intensity(float p_intensity);
353
float get_glow_intensity() const;
354
void set_glow_strength(float p_strength);
355
float get_glow_strength() const;
356
void set_glow_mix(float p_mix);
357
float get_glow_mix() const;
358
void set_glow_bloom(float p_threshold);
359
float get_glow_bloom() const;
360
void set_glow_blend_mode(GlowBlendMode p_mode);
361
GlowBlendMode get_glow_blend_mode() const;
362
void set_glow_hdr_bleed_threshold(float p_threshold);
363
float get_glow_hdr_bleed_threshold() const;
364
void set_glow_hdr_bleed_scale(float p_scale);
365
float get_glow_hdr_bleed_scale() const;
366
void set_glow_hdr_luminance_cap(float p_amount);
367
float get_glow_hdr_luminance_cap() const;
368
void set_glow_map_strength(float p_strength);
369
float get_glow_map_strength() const;
370
void set_glow_map(Ref<Texture> p_glow_map);
371
Ref<Texture> get_glow_map() const;
372
373
// Fog
374
375
void set_fog_enabled(bool p_enabled);
376
bool is_fog_enabled() const;
377
void set_fog_mode(FogMode p_mode);
378
FogMode get_fog_mode() const;
379
void set_fog_light_color(const Color &p_light_color);
380
Color get_fog_light_color() const;
381
void set_fog_light_energy(float p_amount);
382
float get_fog_light_energy() const;
383
void set_fog_sun_scatter(float p_amount);
384
float get_fog_sun_scatter() const;
385
386
void set_fog_density(float p_amount);
387
float get_fog_density() const;
388
void set_fog_height(float p_amount);
389
float get_fog_height() const;
390
void set_fog_height_density(float p_amount);
391
float get_fog_height_density() const;
392
void set_fog_aerial_perspective(float p_aerial_perspective);
393
float get_fog_aerial_perspective() const;
394
void set_fog_sky_affect(float p_sky_affect);
395
float get_fog_sky_affect() const;
396
397
// Depth Fog
398
void set_fog_depth_curve(float p_curve);
399
float get_fog_depth_curve() const;
400
void set_fog_depth_begin(float p_begin);
401
float get_fog_depth_begin() const;
402
void set_fog_depth_end(float p_end);
403
float get_fog_depth_end() const;
404
405
// Volumetric Fog
406
void set_volumetric_fog_enabled(bool p_enable);
407
bool is_volumetric_fog_enabled() const;
408
void set_volumetric_fog_density(float p_density);
409
float get_volumetric_fog_density() const;
410
void set_volumetric_fog_albedo(Color p_color);
411
Color get_volumetric_fog_albedo() const;
412
void set_volumetric_fog_emission(Color p_color);
413
Color get_volumetric_fog_emission() const;
414
void set_volumetric_fog_emission_energy(float p_begin);
415
float get_volumetric_fog_emission_energy() const;
416
void set_volumetric_fog_anisotropy(float p_anisotropy);
417
float get_volumetric_fog_anisotropy() const;
418
void set_volumetric_fog_length(float p_length);
419
float get_volumetric_fog_length() const;
420
void set_volumetric_fog_detail_spread(float p_detail_spread);
421
float get_volumetric_fog_detail_spread() const;
422
void set_volumetric_fog_gi_inject(float p_gi_inject);
423
float get_volumetric_fog_gi_inject() const;
424
void set_volumetric_fog_ambient_inject(float p_ambient_inject);
425
float get_volumetric_fog_ambient_inject() const;
426
void set_volumetric_fog_sky_affect(float p_sky_affect);
427
float get_volumetric_fog_sky_affect() const;
428
void set_volumetric_fog_temporal_reprojection_enabled(bool p_enable);
429
bool is_volumetric_fog_temporal_reprojection_enabled() const;
430
void set_volumetric_fog_temporal_reprojection_amount(float p_amount);
431
float get_volumetric_fog_temporal_reprojection_amount() const;
432
433
// Adjustment
434
void set_adjustment_enabled(bool p_enabled);
435
bool is_adjustment_enabled() const;
436
void set_adjustment_brightness(float p_brightness);
437
float get_adjustment_brightness() const;
438
void set_adjustment_contrast(float p_contrast);
439
float get_adjustment_contrast() const;
440
void set_adjustment_saturation(float p_saturation);
441
float get_adjustment_saturation() const;
442
void set_adjustment_color_correction(Ref<Texture> p_color_correction);
443
Ref<Texture> get_adjustment_color_correction() const;
444
445
Environment();
446
~Environment();
447
};
448
449
VARIANT_ENUM_CAST(Environment::BGMode)
450
VARIANT_ENUM_CAST(Environment::AmbientSource)
451
VARIANT_ENUM_CAST(Environment::ReflectionSource)
452
VARIANT_ENUM_CAST(Environment::ToneMapper)
453
VARIANT_ENUM_CAST(Environment::SDFGIYScale)
454
VARIANT_ENUM_CAST(Environment::GlowBlendMode)
455
VARIANT_ENUM_CAST(Environment::FogMode)
456
457