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