| 1 | /**************************************************************************/ |
| 2 | /* environment_storage.cpp */ |
| 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 | #include "environment_storage.h" |
| 32 | |
| 33 | RID RendererEnvironmentStorage::environment_allocate() { |
| 34 | return environment_owner.allocate_rid(); |
| 35 | } |
| 36 | |
| 37 | void RendererEnvironmentStorage::environment_initialize(RID p_rid) { |
| 38 | environment_owner.initialize_rid(p_rid, Environment()); |
| 39 | } |
| 40 | |
| 41 | void RendererEnvironmentStorage::environment_free(RID p_rid) { |
| 42 | environment_owner.free(p_rid); |
| 43 | } |
| 44 | |
| 45 | // Background |
| 46 | |
| 47 | void RendererEnvironmentStorage::environment_set_background(RID p_env, RS::EnvironmentBG p_bg) { |
| 48 | Environment *env = environment_owner.get_or_null(p_env); |
| 49 | ERR_FAIL_COND(!env); |
| 50 | env->background = p_bg; |
| 51 | } |
| 52 | |
| 53 | void RendererEnvironmentStorage::environment_set_sky(RID p_env, RID p_sky) { |
| 54 | Environment *env = environment_owner.get_or_null(p_env); |
| 55 | ERR_FAIL_COND(!env); |
| 56 | env->sky = p_sky; |
| 57 | } |
| 58 | |
| 59 | void RendererEnvironmentStorage::environment_set_sky_custom_fov(RID p_env, float p_scale) { |
| 60 | Environment *env = environment_owner.get_or_null(p_env); |
| 61 | ERR_FAIL_COND(!env); |
| 62 | env->sky_custom_fov = p_scale; |
| 63 | } |
| 64 | |
| 65 | void RendererEnvironmentStorage::environment_set_sky_orientation(RID p_env, const Basis &p_orientation) { |
| 66 | Environment *env = environment_owner.get_or_null(p_env); |
| 67 | ERR_FAIL_COND(!env); |
| 68 | env->sky_orientation = p_orientation; |
| 69 | } |
| 70 | |
| 71 | void RendererEnvironmentStorage::environment_set_bg_color(RID p_env, const Color &p_color) { |
| 72 | Environment *env = environment_owner.get_or_null(p_env); |
| 73 | ERR_FAIL_COND(!env); |
| 74 | env->bg_color = p_color; |
| 75 | } |
| 76 | |
| 77 | void RendererEnvironmentStorage::environment_set_bg_energy(RID p_env, float p_multiplier, float p_intensity) { |
| 78 | Environment *env = environment_owner.get_or_null(p_env); |
| 79 | ERR_FAIL_COND(!env); |
| 80 | env->bg_energy_multiplier = p_multiplier; |
| 81 | env->bg_intensity = p_intensity; |
| 82 | } |
| 83 | |
| 84 | void RendererEnvironmentStorage::environment_set_canvas_max_layer(RID p_env, int p_max_layer) { |
| 85 | Environment *env = environment_owner.get_or_null(p_env); |
| 86 | ERR_FAIL_COND(!env); |
| 87 | env->canvas_max_layer = p_max_layer; |
| 88 | } |
| 89 | |
| 90 | void RendererEnvironmentStorage::environment_set_ambient_light(RID p_env, const Color &p_color, RS::EnvironmentAmbientSource p_ambient, float p_energy, float p_sky_contribution, RS::EnvironmentReflectionSource p_reflection_source) { |
| 91 | Environment *env = environment_owner.get_or_null(p_env); |
| 92 | ERR_FAIL_COND(!env); |
| 93 | env->ambient_light = p_color; |
| 94 | env->ambient_source = p_ambient; |
| 95 | env->ambient_light_energy = p_energy; |
| 96 | env->ambient_sky_contribution = p_sky_contribution; |
| 97 | env->reflection_source = p_reflection_source; |
| 98 | } |
| 99 | |
| 100 | RS::EnvironmentBG RendererEnvironmentStorage::environment_get_background(RID p_env) const { |
| 101 | Environment *env = environment_owner.get_or_null(p_env); |
| 102 | ERR_FAIL_COND_V(!env, RS::ENV_BG_CLEAR_COLOR); |
| 103 | return env->background; |
| 104 | } |
| 105 | |
| 106 | RID RendererEnvironmentStorage::environment_get_sky(RID p_env) const { |
| 107 | Environment *env = environment_owner.get_or_null(p_env); |
| 108 | ERR_FAIL_COND_V(!env, RID()); |
| 109 | return env->sky; |
| 110 | } |
| 111 | |
| 112 | float RendererEnvironmentStorage::environment_get_sky_custom_fov(RID p_env) const { |
| 113 | Environment *env = environment_owner.get_or_null(p_env); |
| 114 | ERR_FAIL_COND_V(!env, 0.0); |
| 115 | return env->sky_custom_fov; |
| 116 | } |
| 117 | |
| 118 | Basis RendererEnvironmentStorage::environment_get_sky_orientation(RID p_env) const { |
| 119 | Environment *env = environment_owner.get_or_null(p_env); |
| 120 | ERR_FAIL_COND_V(!env, Basis()); |
| 121 | return env->sky_orientation; |
| 122 | } |
| 123 | |
| 124 | Color RendererEnvironmentStorage::environment_get_bg_color(RID p_env) const { |
| 125 | Environment *env = environment_owner.get_or_null(p_env); |
| 126 | ERR_FAIL_COND_V(!env, Color()); |
| 127 | return env->bg_color; |
| 128 | } |
| 129 | |
| 130 | float RendererEnvironmentStorage::environment_get_bg_energy_multiplier(RID p_env) const { |
| 131 | Environment *env = environment_owner.get_or_null(p_env); |
| 132 | ERR_FAIL_COND_V(!env, 1.0); |
| 133 | return env->bg_energy_multiplier; |
| 134 | } |
| 135 | |
| 136 | float RendererEnvironmentStorage::environment_get_bg_intensity(RID p_env) const { |
| 137 | Environment *env = environment_owner.get_or_null(p_env); |
| 138 | ERR_FAIL_COND_V(!env, 1.0); |
| 139 | return env->bg_intensity; |
| 140 | } |
| 141 | |
| 142 | int RendererEnvironmentStorage::environment_get_canvas_max_layer(RID p_env) const { |
| 143 | Environment *env = environment_owner.get_or_null(p_env); |
| 144 | ERR_FAIL_COND_V(!env, 0); |
| 145 | return env->canvas_max_layer; |
| 146 | } |
| 147 | |
| 148 | RS::EnvironmentAmbientSource RendererEnvironmentStorage::environment_get_ambient_source(RID p_env) const { |
| 149 | Environment *env = environment_owner.get_or_null(p_env); |
| 150 | ERR_FAIL_COND_V(!env, RS::ENV_AMBIENT_SOURCE_BG); |
| 151 | return env->ambient_source; |
| 152 | } |
| 153 | |
| 154 | Color RendererEnvironmentStorage::environment_get_ambient_light(RID p_env) const { |
| 155 | Environment *env = environment_owner.get_or_null(p_env); |
| 156 | ERR_FAIL_COND_V(!env, Color()); |
| 157 | return env->ambient_light; |
| 158 | } |
| 159 | |
| 160 | float RendererEnvironmentStorage::environment_get_ambient_light_energy(RID p_env) const { |
| 161 | Environment *env = environment_owner.get_or_null(p_env); |
| 162 | ERR_FAIL_COND_V(!env, 1.0); |
| 163 | return env->ambient_light_energy; |
| 164 | } |
| 165 | |
| 166 | float RendererEnvironmentStorage::environment_get_ambient_sky_contribution(RID p_env) const { |
| 167 | Environment *env = environment_owner.get_or_null(p_env); |
| 168 | ERR_FAIL_COND_V(!env, 1.0); |
| 169 | return env->ambient_sky_contribution; |
| 170 | } |
| 171 | |
| 172 | RS::EnvironmentReflectionSource RendererEnvironmentStorage::environment_get_reflection_source(RID p_env) const { |
| 173 | Environment *env = environment_owner.get_or_null(p_env); |
| 174 | ERR_FAIL_COND_V(!env, RS::ENV_REFLECTION_SOURCE_BG); |
| 175 | return env->reflection_source; |
| 176 | } |
| 177 | |
| 178 | // Tonemap |
| 179 | |
| 180 | void RendererEnvironmentStorage::environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white) { |
| 181 | Environment *env = environment_owner.get_or_null(p_env); |
| 182 | ERR_FAIL_COND(!env); |
| 183 | env->exposure = p_exposure; |
| 184 | env->tone_mapper = p_tone_mapper; |
| 185 | env->white = p_white; |
| 186 | } |
| 187 | |
| 188 | RS::EnvironmentToneMapper RendererEnvironmentStorage::environment_get_tone_mapper(RID p_env) const { |
| 189 | Environment *env = environment_owner.get_or_null(p_env); |
| 190 | ERR_FAIL_COND_V(!env, RS::ENV_TONE_MAPPER_LINEAR); |
| 191 | return env->tone_mapper; |
| 192 | } |
| 193 | |
| 194 | float RendererEnvironmentStorage::environment_get_exposure(RID p_env) const { |
| 195 | Environment *env = environment_owner.get_or_null(p_env); |
| 196 | ERR_FAIL_COND_V(!env, 1.0); |
| 197 | return env->exposure; |
| 198 | } |
| 199 | |
| 200 | float RendererEnvironmentStorage::environment_get_white(RID p_env) const { |
| 201 | Environment *env = environment_owner.get_or_null(p_env); |
| 202 | ERR_FAIL_COND_V(!env, 1.0); |
| 203 | return env->white; |
| 204 | } |
| 205 | |
| 206 | // Fog |
| 207 | |
| 208 | void RendererEnvironmentStorage::environment_set_fog(RID p_env, bool p_enable, const Color &p_light_color, float p_light_energy, float p_sun_scatter, float p_density, float p_height, float p_height_density, float p_fog_aerial_perspective, float p_sky_affect) { |
| 209 | Environment *env = environment_owner.get_or_null(p_env); |
| 210 | ERR_FAIL_COND(!env); |
| 211 | env->fog_enabled = p_enable; |
| 212 | env->fog_light_color = p_light_color; |
| 213 | env->fog_light_energy = p_light_energy; |
| 214 | env->fog_sun_scatter = p_sun_scatter; |
| 215 | env->fog_density = p_density; |
| 216 | env->fog_height = p_height; |
| 217 | env->fog_height_density = p_height_density; |
| 218 | env->fog_aerial_perspective = p_fog_aerial_perspective; |
| 219 | env->fog_sky_affect = p_sky_affect; |
| 220 | } |
| 221 | |
| 222 | bool RendererEnvironmentStorage::environment_get_fog_enabled(RID p_env) const { |
| 223 | Environment *env = environment_owner.get_or_null(p_env); |
| 224 | ERR_FAIL_COND_V(!env, false); |
| 225 | return env->fog_enabled; |
| 226 | } |
| 227 | |
| 228 | Color RendererEnvironmentStorage::environment_get_fog_light_color(RID p_env) const { |
| 229 | Environment *env = environment_owner.get_or_null(p_env); |
| 230 | ERR_FAIL_COND_V(!env, Color(0.5, 0.6, 0.7)); |
| 231 | return env->fog_light_color; |
| 232 | } |
| 233 | |
| 234 | float RendererEnvironmentStorage::environment_get_fog_light_energy(RID p_env) const { |
| 235 | Environment *env = environment_owner.get_or_null(p_env); |
| 236 | ERR_FAIL_COND_V(!env, 1.0); |
| 237 | return env->fog_light_energy; |
| 238 | } |
| 239 | |
| 240 | float RendererEnvironmentStorage::environment_get_fog_sun_scatter(RID p_env) const { |
| 241 | Environment *env = environment_owner.get_or_null(p_env); |
| 242 | ERR_FAIL_COND_V(!env, 0.0); |
| 243 | return env->fog_sun_scatter; |
| 244 | } |
| 245 | |
| 246 | float RendererEnvironmentStorage::environment_get_fog_density(RID p_env) const { |
| 247 | Environment *env = environment_owner.get_or_null(p_env); |
| 248 | ERR_FAIL_COND_V(!env, 0.001); |
| 249 | return env->fog_density; |
| 250 | } |
| 251 | |
| 252 | float RendererEnvironmentStorage::environment_get_fog_height(RID p_env) const { |
| 253 | Environment *env = environment_owner.get_or_null(p_env); |
| 254 | ERR_FAIL_COND_V(!env, 0.0); |
| 255 | return env->fog_height; |
| 256 | } |
| 257 | |
| 258 | float RendererEnvironmentStorage::environment_get_fog_height_density(RID p_env) const { |
| 259 | Environment *env = environment_owner.get_or_null(p_env); |
| 260 | ERR_FAIL_COND_V(!env, 0.0); |
| 261 | return env->fog_height_density; |
| 262 | } |
| 263 | |
| 264 | float RendererEnvironmentStorage::environment_get_fog_aerial_perspective(RID p_env) const { |
| 265 | Environment *env = environment_owner.get_or_null(p_env); |
| 266 | ERR_FAIL_COND_V(!env, 0.0); |
| 267 | return env->fog_aerial_perspective; |
| 268 | } |
| 269 | |
| 270 | float RendererEnvironmentStorage::environment_get_fog_sky_affect(RID p_env) const { |
| 271 | Environment *env = environment_owner.get_or_null(p_env); |
| 272 | ERR_FAIL_COND_V(!env, 0.0); |
| 273 | return env->fog_sky_affect; |
| 274 | } |
| 275 | |
| 276 | // Volumetric Fog |
| 277 | |
| 278 | void RendererEnvironmentStorage::environment_set_volumetric_fog(RID p_env, bool p_enable, float p_density, const Color &p_albedo, const Color &p_emission, float p_emission_energy, float p_anisotropy, float p_length, float p_detail_spread, float p_gi_inject, bool p_temporal_reprojection, float p_temporal_reprojection_amount, float p_ambient_inject, float p_sky_affect) { |
| 279 | Environment *env = environment_owner.get_or_null(p_env); |
| 280 | ERR_FAIL_COND(!env); |
| 281 | #ifdef DEBUG_ENABLED |
| 282 | if (OS::get_singleton()->get_current_rendering_method() != "forward_plus" && p_enable) { |
| 283 | WARN_PRINT_ONCE_ED("Volumetric fog can only be enabled when using the Forward+ rendering backend." ); |
| 284 | } |
| 285 | #endif |
| 286 | env->volumetric_fog_enabled = p_enable; |
| 287 | env->volumetric_fog_density = p_density; |
| 288 | env->volumetric_fog_scattering = p_albedo; |
| 289 | env->volumetric_fog_emission = p_emission; |
| 290 | env->volumetric_fog_emission_energy = p_emission_energy; |
| 291 | env->volumetric_fog_anisotropy = p_anisotropy; |
| 292 | env->volumetric_fog_length = p_length; |
| 293 | env->volumetric_fog_detail_spread = p_detail_spread; |
| 294 | env->volumetric_fog_gi_inject = p_gi_inject; |
| 295 | env->volumetric_fog_temporal_reprojection = p_temporal_reprojection; |
| 296 | env->volumetric_fog_temporal_reprojection_amount = p_temporal_reprojection_amount; |
| 297 | env->volumetric_fog_ambient_inject = p_ambient_inject; |
| 298 | env->volumetric_fog_sky_affect = p_sky_affect; |
| 299 | } |
| 300 | |
| 301 | bool RendererEnvironmentStorage::environment_get_volumetric_fog_enabled(RID p_env) const { |
| 302 | Environment *env = environment_owner.get_or_null(p_env); |
| 303 | ERR_FAIL_COND_V(!env, false); |
| 304 | return env->volumetric_fog_enabled; |
| 305 | } |
| 306 | |
| 307 | float RendererEnvironmentStorage::environment_get_volumetric_fog_density(RID p_env) const { |
| 308 | Environment *env = environment_owner.get_or_null(p_env); |
| 309 | ERR_FAIL_COND_V(!env, 0.01); |
| 310 | return env->volumetric_fog_density; |
| 311 | } |
| 312 | |
| 313 | Color RendererEnvironmentStorage::environment_get_volumetric_fog_scattering(RID p_env) const { |
| 314 | Environment *env = environment_owner.get_or_null(p_env); |
| 315 | ERR_FAIL_COND_V(!env, Color(1, 1, 1)); |
| 316 | return env->volumetric_fog_scattering; |
| 317 | } |
| 318 | |
| 319 | Color RendererEnvironmentStorage::environment_get_volumetric_fog_emission(RID p_env) const { |
| 320 | Environment *env = environment_owner.get_or_null(p_env); |
| 321 | ERR_FAIL_COND_V(!env, Color(0, 0, 0)); |
| 322 | return env->volumetric_fog_emission; |
| 323 | } |
| 324 | |
| 325 | float RendererEnvironmentStorage::environment_get_volumetric_fog_emission_energy(RID p_env) const { |
| 326 | Environment *env = environment_owner.get_or_null(p_env); |
| 327 | ERR_FAIL_COND_V(!env, 0.0); |
| 328 | return env->volumetric_fog_emission_energy; |
| 329 | } |
| 330 | |
| 331 | float RendererEnvironmentStorage::environment_get_volumetric_fog_anisotropy(RID p_env) const { |
| 332 | Environment *env = environment_owner.get_or_null(p_env); |
| 333 | ERR_FAIL_COND_V(!env, 0.2); |
| 334 | return env->volumetric_fog_anisotropy; |
| 335 | } |
| 336 | |
| 337 | float RendererEnvironmentStorage::environment_get_volumetric_fog_length(RID p_env) const { |
| 338 | Environment *env = environment_owner.get_or_null(p_env); |
| 339 | ERR_FAIL_COND_V(!env, 64.0); |
| 340 | return env->volumetric_fog_length; |
| 341 | } |
| 342 | |
| 343 | float RendererEnvironmentStorage::environment_get_volumetric_fog_detail_spread(RID p_env) const { |
| 344 | Environment *env = environment_owner.get_or_null(p_env); |
| 345 | ERR_FAIL_COND_V(!env, 2.0); |
| 346 | return env->volumetric_fog_detail_spread; |
| 347 | } |
| 348 | |
| 349 | float RendererEnvironmentStorage::environment_get_volumetric_fog_gi_inject(RID p_env) const { |
| 350 | Environment *env = environment_owner.get_or_null(p_env); |
| 351 | ERR_FAIL_COND_V(!env, 0.0); |
| 352 | return env->volumetric_fog_gi_inject; |
| 353 | } |
| 354 | |
| 355 | float RendererEnvironmentStorage::environment_get_volumetric_fog_sky_affect(RID p_env) const { |
| 356 | Environment *env = environment_owner.get_or_null(p_env); |
| 357 | ERR_FAIL_COND_V(!env, 0.0); |
| 358 | return env->volumetric_fog_sky_affect; |
| 359 | } |
| 360 | |
| 361 | bool RendererEnvironmentStorage::environment_get_volumetric_fog_temporal_reprojection(RID p_env) const { |
| 362 | Environment *env = environment_owner.get_or_null(p_env); |
| 363 | ERR_FAIL_COND_V(!env, true); |
| 364 | return env->volumetric_fog_temporal_reprojection; |
| 365 | } |
| 366 | |
| 367 | float RendererEnvironmentStorage::environment_get_volumetric_fog_temporal_reprojection_amount(RID p_env) const { |
| 368 | Environment *env = environment_owner.get_or_null(p_env); |
| 369 | ERR_FAIL_COND_V(!env, 0.9); |
| 370 | return env->volumetric_fog_temporal_reprojection_amount; |
| 371 | } |
| 372 | |
| 373 | float RendererEnvironmentStorage::environment_get_volumetric_fog_ambient_inject(RID p_env) const { |
| 374 | Environment *env = environment_owner.get_or_null(p_env); |
| 375 | ERR_FAIL_COND_V(!env, 0.0); |
| 376 | return env->volumetric_fog_ambient_inject; |
| 377 | } |
| 378 | |
| 379 | // GLOW |
| 380 | |
| 381 | void RendererEnvironmentStorage::environment_set_glow(RID p_env, bool p_enable, Vector<float> p_levels, float p_intensity, float p_strength, float p_mix, float p_bloom_threshold, RS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap, float p_glow_map_strength, RID p_glow_map) { |
| 382 | Environment *env = environment_owner.get_or_null(p_env); |
| 383 | ERR_FAIL_COND(!env); |
| 384 | ERR_FAIL_COND_MSG(p_levels.size() != 7, "Size of array of glow levels must be 7" ); |
| 385 | #ifdef DEBUG_ENABLED |
| 386 | if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility" && p_enable) { |
| 387 | WARN_PRINT_ONCE_ED("Glow is not supported when using the GL Compatibility backend yet. Support will be added in a future release." ); |
| 388 | } |
| 389 | #endif |
| 390 | env->glow_enabled = p_enable; |
| 391 | env->glow_levels = p_levels; |
| 392 | env->glow_intensity = p_intensity; |
| 393 | env->glow_strength = p_strength; |
| 394 | env->glow_mix = p_mix; |
| 395 | env->glow_bloom = p_bloom_threshold; |
| 396 | env->glow_blend_mode = p_blend_mode; |
| 397 | env->glow_hdr_bleed_threshold = p_hdr_bleed_threshold; |
| 398 | env->glow_hdr_bleed_scale = p_hdr_bleed_scale; |
| 399 | env->glow_hdr_luminance_cap = p_hdr_luminance_cap; |
| 400 | env->glow_map_strength = p_glow_map_strength; |
| 401 | env->glow_map = p_glow_map; |
| 402 | } |
| 403 | |
| 404 | bool RendererEnvironmentStorage::environment_get_glow_enabled(RID p_env) const { |
| 405 | Environment *env = environment_owner.get_or_null(p_env); |
| 406 | ERR_FAIL_COND_V(!env, false); |
| 407 | return env->glow_enabled; |
| 408 | } |
| 409 | |
| 410 | Vector<float> RendererEnvironmentStorage::environment_get_glow_levels(RID p_env) const { |
| 411 | Environment *env = environment_owner.get_or_null(p_env); |
| 412 | ERR_FAIL_COND_V(!env, Vector<float>()); |
| 413 | return env->glow_levels; |
| 414 | } |
| 415 | |
| 416 | float RendererEnvironmentStorage::environment_get_glow_intensity(RID p_env) const { |
| 417 | Environment *env = environment_owner.get_or_null(p_env); |
| 418 | ERR_FAIL_COND_V(!env, 0.8); |
| 419 | return env->glow_intensity; |
| 420 | } |
| 421 | |
| 422 | float RendererEnvironmentStorage::environment_get_glow_strength(RID p_env) const { |
| 423 | Environment *env = environment_owner.get_or_null(p_env); |
| 424 | ERR_FAIL_COND_V(!env, 1.0); |
| 425 | return env->glow_strength; |
| 426 | } |
| 427 | |
| 428 | float RendererEnvironmentStorage::environment_get_glow_bloom(RID p_env) const { |
| 429 | Environment *env = environment_owner.get_or_null(p_env); |
| 430 | ERR_FAIL_COND_V(!env, 0.0); |
| 431 | return env->glow_bloom; |
| 432 | } |
| 433 | |
| 434 | float RendererEnvironmentStorage::environment_get_glow_mix(RID p_env) const { |
| 435 | Environment *env = environment_owner.get_or_null(p_env); |
| 436 | ERR_FAIL_COND_V(!env, 0.01); |
| 437 | return env->glow_mix; |
| 438 | } |
| 439 | |
| 440 | RS::EnvironmentGlowBlendMode RendererEnvironmentStorage::environment_get_glow_blend_mode(RID p_env) const { |
| 441 | Environment *env = environment_owner.get_or_null(p_env); |
| 442 | ERR_FAIL_COND_V(!env, RS::ENV_GLOW_BLEND_MODE_SOFTLIGHT); |
| 443 | return env->glow_blend_mode; |
| 444 | } |
| 445 | |
| 446 | float RendererEnvironmentStorage::environment_get_glow_hdr_bleed_threshold(RID p_env) const { |
| 447 | Environment *env = environment_owner.get_or_null(p_env); |
| 448 | ERR_FAIL_COND_V(!env, 1.0); |
| 449 | return env->glow_hdr_bleed_threshold; |
| 450 | } |
| 451 | |
| 452 | float RendererEnvironmentStorage::environment_get_glow_hdr_luminance_cap(RID p_env) const { |
| 453 | Environment *env = environment_owner.get_or_null(p_env); |
| 454 | ERR_FAIL_COND_V(!env, 12.0); |
| 455 | return env->glow_hdr_luminance_cap; |
| 456 | } |
| 457 | |
| 458 | float RendererEnvironmentStorage::environment_get_glow_hdr_bleed_scale(RID p_env) const { |
| 459 | Environment *env = environment_owner.get_or_null(p_env); |
| 460 | ERR_FAIL_COND_V(!env, 2.0); |
| 461 | return env->glow_hdr_bleed_scale; |
| 462 | } |
| 463 | |
| 464 | float RendererEnvironmentStorage::environment_get_glow_map_strength(RID p_env) const { |
| 465 | Environment *env = environment_owner.get_or_null(p_env); |
| 466 | ERR_FAIL_COND_V(!env, 0.0); |
| 467 | return env->glow_map_strength; |
| 468 | } |
| 469 | |
| 470 | RID RendererEnvironmentStorage::environment_get_glow_map(RID p_env) const { |
| 471 | Environment *env = environment_owner.get_or_null(p_env); |
| 472 | ERR_FAIL_COND_V(!env, RID()); |
| 473 | return env->glow_map; |
| 474 | } |
| 475 | |
| 476 | // SSR |
| 477 | |
| 478 | void RendererEnvironmentStorage::environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance) { |
| 479 | Environment *env = environment_owner.get_or_null(p_env); |
| 480 | ERR_FAIL_COND(!env); |
| 481 | #ifdef DEBUG_ENABLED |
| 482 | if (OS::get_singleton()->get_current_rendering_method() != "forward_plus" && p_enable) { |
| 483 | WARN_PRINT_ONCE_ED("Screen-space reflections (SSR) can only be enabled when using the Forward+ rendering backend." ); |
| 484 | } |
| 485 | #endif |
| 486 | env->ssr_enabled = p_enable; |
| 487 | env->ssr_max_steps = p_max_steps; |
| 488 | env->ssr_fade_in = p_fade_int; |
| 489 | env->ssr_fade_out = p_fade_out; |
| 490 | env->ssr_depth_tolerance = p_depth_tolerance; |
| 491 | } |
| 492 | |
| 493 | bool RendererEnvironmentStorage::environment_get_ssr_enabled(RID p_env) const { |
| 494 | Environment *env = environment_owner.get_or_null(p_env); |
| 495 | ERR_FAIL_COND_V(!env, false); |
| 496 | return env->ssr_enabled; |
| 497 | } |
| 498 | |
| 499 | int RendererEnvironmentStorage::environment_get_ssr_max_steps(RID p_env) const { |
| 500 | Environment *env = environment_owner.get_or_null(p_env); |
| 501 | ERR_FAIL_COND_V(!env, 64); |
| 502 | return env->ssr_max_steps; |
| 503 | } |
| 504 | |
| 505 | float RendererEnvironmentStorage::environment_get_ssr_fade_in(RID p_env) const { |
| 506 | Environment *env = environment_owner.get_or_null(p_env); |
| 507 | ERR_FAIL_COND_V(!env, 0.15); |
| 508 | return env->ssr_fade_in; |
| 509 | } |
| 510 | |
| 511 | float RendererEnvironmentStorage::environment_get_ssr_fade_out(RID p_env) const { |
| 512 | Environment *env = environment_owner.get_or_null(p_env); |
| 513 | ERR_FAIL_COND_V(!env, 2.0); |
| 514 | return env->ssr_fade_out; |
| 515 | } |
| 516 | |
| 517 | float RendererEnvironmentStorage::environment_get_ssr_depth_tolerance(RID p_env) const { |
| 518 | Environment *env = environment_owner.get_or_null(p_env); |
| 519 | ERR_FAIL_COND_V(!env, 0.2); |
| 520 | return env->ssr_depth_tolerance; |
| 521 | } |
| 522 | |
| 523 | // SSAO |
| 524 | |
| 525 | void RendererEnvironmentStorage::environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_power, float p_detail, float p_horizon, float p_sharpness, float p_light_affect, float p_ao_channel_affect) { |
| 526 | Environment *env = environment_owner.get_or_null(p_env); |
| 527 | ERR_FAIL_COND(!env); |
| 528 | #ifdef DEBUG_ENABLED |
| 529 | if (OS::get_singleton()->get_current_rendering_method() != "forward_plus" && p_enable) { |
| 530 | WARN_PRINT_ONCE_ED("Screen-space ambient occlusion (SSAO) can only be enabled when using the Forward+ rendering backend." ); |
| 531 | } |
| 532 | #endif |
| 533 | env->ssao_enabled = p_enable; |
| 534 | env->ssao_radius = p_radius; |
| 535 | env->ssao_intensity = p_intensity; |
| 536 | env->ssao_power = p_power; |
| 537 | env->ssao_detail = p_detail; |
| 538 | env->ssao_horizon = p_horizon; |
| 539 | env->ssao_sharpness = p_sharpness; |
| 540 | env->ssao_direct_light_affect = p_light_affect; |
| 541 | env->ssao_ao_channel_affect = p_ao_channel_affect; |
| 542 | } |
| 543 | |
| 544 | bool RendererEnvironmentStorage::environment_get_ssao_enabled(RID p_env) const { |
| 545 | Environment *env = environment_owner.get_or_null(p_env); |
| 546 | ERR_FAIL_COND_V(!env, false); |
| 547 | return env->ssao_enabled; |
| 548 | } |
| 549 | |
| 550 | float RendererEnvironmentStorage::environment_get_ssao_radius(RID p_env) const { |
| 551 | Environment *env = environment_owner.get_or_null(p_env); |
| 552 | ERR_FAIL_COND_V(!env, 1.0); |
| 553 | return env->ssao_radius; |
| 554 | } |
| 555 | |
| 556 | float RendererEnvironmentStorage::environment_get_ssao_intensity(RID p_env) const { |
| 557 | Environment *env = environment_owner.get_or_null(p_env); |
| 558 | ERR_FAIL_COND_V(!env, 2.0); |
| 559 | return env->ssao_intensity; |
| 560 | } |
| 561 | |
| 562 | float RendererEnvironmentStorage::environment_get_ssao_power(RID p_env) const { |
| 563 | Environment *env = environment_owner.get_or_null(p_env); |
| 564 | ERR_FAIL_COND_V(!env, 1.5); |
| 565 | return env->ssao_power; |
| 566 | } |
| 567 | |
| 568 | float RendererEnvironmentStorage::environment_get_ssao_detail(RID p_env) const { |
| 569 | Environment *env = environment_owner.get_or_null(p_env); |
| 570 | ERR_FAIL_COND_V(!env, 0.5); |
| 571 | return env->ssao_detail; |
| 572 | } |
| 573 | |
| 574 | float RendererEnvironmentStorage::environment_get_ssao_horizon(RID p_env) const { |
| 575 | Environment *env = environment_owner.get_or_null(p_env); |
| 576 | ERR_FAIL_COND_V(!env, 0.06); |
| 577 | return env->ssao_horizon; |
| 578 | } |
| 579 | |
| 580 | float RendererEnvironmentStorage::environment_get_ssao_sharpness(RID p_env) const { |
| 581 | Environment *env = environment_owner.get_or_null(p_env); |
| 582 | ERR_FAIL_COND_V(!env, 0.98); |
| 583 | return env->ssao_sharpness; |
| 584 | } |
| 585 | |
| 586 | float RendererEnvironmentStorage::environment_get_ssao_direct_light_affect(RID p_env) const { |
| 587 | Environment *env = environment_owner.get_or_null(p_env); |
| 588 | ERR_FAIL_COND_V(!env, 0.0); |
| 589 | return env->ssao_direct_light_affect; |
| 590 | } |
| 591 | |
| 592 | float RendererEnvironmentStorage::environment_get_ssao_ao_channel_affect(RID p_env) const { |
| 593 | Environment *env = environment_owner.get_or_null(p_env); |
| 594 | ERR_FAIL_COND_V(!env, 0.0); |
| 595 | return env->ssao_ao_channel_affect; |
| 596 | } |
| 597 | |
| 598 | // SSIL |
| 599 | |
| 600 | void RendererEnvironmentStorage::environment_set_ssil(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_sharpness, float p_normal_rejection) { |
| 601 | Environment *env = environment_owner.get_or_null(p_env); |
| 602 | ERR_FAIL_COND(!env); |
| 603 | #ifdef DEBUG_ENABLED |
| 604 | if (OS::get_singleton()->get_current_rendering_method() != "forward_plus" && p_enable) { |
| 605 | WARN_PRINT_ONCE_ED("Screen-space indirect lighting (SSIL) can only be enabled when using the Forward+ rendering backend." ); |
| 606 | } |
| 607 | #endif |
| 608 | env->ssil_enabled = p_enable; |
| 609 | env->ssil_radius = p_radius; |
| 610 | env->ssil_intensity = p_intensity; |
| 611 | env->ssil_sharpness = p_sharpness; |
| 612 | env->ssil_normal_rejection = p_normal_rejection; |
| 613 | } |
| 614 | |
| 615 | bool RendererEnvironmentStorage::environment_get_ssil_enabled(RID p_env) const { |
| 616 | Environment *env = environment_owner.get_or_null(p_env); |
| 617 | ERR_FAIL_COND_V(!env, false); |
| 618 | return env->ssil_enabled; |
| 619 | } |
| 620 | |
| 621 | float RendererEnvironmentStorage::environment_get_ssil_radius(RID p_env) const { |
| 622 | Environment *env = environment_owner.get_or_null(p_env); |
| 623 | ERR_FAIL_COND_V(!env, 5.0); |
| 624 | return env->ssil_radius; |
| 625 | } |
| 626 | |
| 627 | float RendererEnvironmentStorage::environment_get_ssil_intensity(RID p_env) const { |
| 628 | Environment *env = environment_owner.get_or_null(p_env); |
| 629 | ERR_FAIL_COND_V(!env, 1.0); |
| 630 | return env->ssil_intensity; |
| 631 | } |
| 632 | |
| 633 | float RendererEnvironmentStorage::environment_get_ssil_sharpness(RID p_env) const { |
| 634 | Environment *env = environment_owner.get_or_null(p_env); |
| 635 | ERR_FAIL_COND_V(!env, 0.98); |
| 636 | return env->ssil_sharpness; |
| 637 | } |
| 638 | |
| 639 | float RendererEnvironmentStorage::environment_get_ssil_normal_rejection(RID p_env) const { |
| 640 | Environment *env = environment_owner.get_or_null(p_env); |
| 641 | ERR_FAIL_COND_V(!env, 1.0); |
| 642 | return env->ssil_normal_rejection; |
| 643 | } |
| 644 | |
| 645 | // SDFGI |
| 646 | |
| 647 | void RendererEnvironmentStorage::environment_set_sdfgi(RID p_env, bool p_enable, int p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) { |
| 648 | Environment *env = environment_owner.get_or_null(p_env); |
| 649 | ERR_FAIL_COND(!env); |
| 650 | #ifdef DEBUG_ENABLED |
| 651 | if (OS::get_singleton()->get_current_rendering_method() != "forward_plus" && p_enable) { |
| 652 | WARN_PRINT_ONCE_ED("SDFGI can only be enabled when using the Forward+ rendering backend." ); |
| 653 | } |
| 654 | #endif |
| 655 | env->sdfgi_enabled = p_enable; |
| 656 | env->sdfgi_cascades = p_cascades; |
| 657 | env->sdfgi_min_cell_size = p_min_cell_size; |
| 658 | env->sdfgi_use_occlusion = p_use_occlusion; |
| 659 | env->sdfgi_bounce_feedback = p_bounce_feedback; |
| 660 | env->sdfgi_read_sky_light = p_read_sky; |
| 661 | env->sdfgi_energy = p_energy; |
| 662 | env->sdfgi_normal_bias = p_normal_bias; |
| 663 | env->sdfgi_probe_bias = p_probe_bias; |
| 664 | env->sdfgi_y_scale = p_y_scale; |
| 665 | } |
| 666 | |
| 667 | bool RendererEnvironmentStorage::environment_get_sdfgi_enabled(RID p_env) const { |
| 668 | Environment *env = environment_owner.get_or_null(p_env); |
| 669 | ERR_FAIL_COND_V(!env, false); |
| 670 | return env->sdfgi_enabled; |
| 671 | } |
| 672 | |
| 673 | int RendererEnvironmentStorage::environment_get_sdfgi_cascades(RID p_env) const { |
| 674 | Environment *env = environment_owner.get_or_null(p_env); |
| 675 | ERR_FAIL_COND_V(!env, 4); |
| 676 | return env->sdfgi_cascades; |
| 677 | } |
| 678 | |
| 679 | float RendererEnvironmentStorage::environment_get_sdfgi_min_cell_size(RID p_env) const { |
| 680 | Environment *env = environment_owner.get_or_null(p_env); |
| 681 | ERR_FAIL_COND_V(!env, 0.2); |
| 682 | return env->sdfgi_min_cell_size; |
| 683 | } |
| 684 | |
| 685 | bool RendererEnvironmentStorage::environment_get_sdfgi_use_occlusion(RID p_env) const { |
| 686 | Environment *env = environment_owner.get_or_null(p_env); |
| 687 | ERR_FAIL_COND_V(!env, false); |
| 688 | return env->sdfgi_use_occlusion; |
| 689 | } |
| 690 | |
| 691 | float RendererEnvironmentStorage::environment_get_sdfgi_bounce_feedback(RID p_env) const { |
| 692 | Environment *env = environment_owner.get_or_null(p_env); |
| 693 | ERR_FAIL_COND_V(!env, 0.5); |
| 694 | return env->sdfgi_bounce_feedback; |
| 695 | } |
| 696 | |
| 697 | bool RendererEnvironmentStorage::environment_get_sdfgi_read_sky_light(RID p_env) const { |
| 698 | Environment *env = environment_owner.get_or_null(p_env); |
| 699 | ERR_FAIL_COND_V(!env, true); |
| 700 | return env->sdfgi_read_sky_light; |
| 701 | } |
| 702 | |
| 703 | float RendererEnvironmentStorage::environment_get_sdfgi_energy(RID p_env) const { |
| 704 | Environment *env = environment_owner.get_or_null(p_env); |
| 705 | ERR_FAIL_COND_V(!env, 1.0); |
| 706 | return env->sdfgi_energy; |
| 707 | } |
| 708 | |
| 709 | float RendererEnvironmentStorage::environment_get_sdfgi_normal_bias(RID p_env) const { |
| 710 | Environment *env = environment_owner.get_or_null(p_env); |
| 711 | ERR_FAIL_COND_V(!env, 1.1); |
| 712 | return env->sdfgi_normal_bias; |
| 713 | } |
| 714 | |
| 715 | float RendererEnvironmentStorage::environment_get_sdfgi_probe_bias(RID p_env) const { |
| 716 | Environment *env = environment_owner.get_or_null(p_env); |
| 717 | ERR_FAIL_COND_V(!env, 1.1); |
| 718 | return env->sdfgi_probe_bias; |
| 719 | } |
| 720 | |
| 721 | RS::EnvironmentSDFGIYScale RendererEnvironmentStorage::environment_get_sdfgi_y_scale(RID p_env) const { |
| 722 | Environment *env = environment_owner.get_or_null(p_env); |
| 723 | ERR_FAIL_COND_V(!env, RS::ENV_SDFGI_Y_SCALE_75_PERCENT); |
| 724 | return env->sdfgi_y_scale; |
| 725 | } |
| 726 | |
| 727 | // Adjustments |
| 728 | |
| 729 | void RendererEnvironmentStorage::environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, bool p_use_1d_color_correction, RID p_color_correction) { |
| 730 | Environment *env = environment_owner.get_or_null(p_env); |
| 731 | ERR_FAIL_COND(!env); |
| 732 | #ifdef DEBUG_ENABLED |
| 733 | if (OS::get_singleton()->get_current_rendering_method() == "gl_compatibility" && p_enable) { |
| 734 | WARN_PRINT_ONCE_ED("Adjustments are not supported when using the GL Compatibility backend yet. Support will be added in a future release." ); |
| 735 | } |
| 736 | #endif |
| 737 | env->adjustments_enabled = p_enable; |
| 738 | env->adjustments_brightness = p_brightness; |
| 739 | env->adjustments_contrast = p_contrast; |
| 740 | env->adjustments_saturation = p_saturation; |
| 741 | env->use_1d_color_correction = p_use_1d_color_correction; |
| 742 | env->color_correction = p_color_correction; |
| 743 | } |
| 744 | |
| 745 | bool RendererEnvironmentStorage::environment_get_adjustments_enabled(RID p_env) const { |
| 746 | Environment *env = environment_owner.get_or_null(p_env); |
| 747 | ERR_FAIL_COND_V(!env, false); |
| 748 | return env->adjustments_enabled; |
| 749 | } |
| 750 | |
| 751 | float RendererEnvironmentStorage::environment_get_adjustments_brightness(RID p_env) const { |
| 752 | Environment *env = environment_owner.get_or_null(p_env); |
| 753 | ERR_FAIL_COND_V(!env, 1.0); |
| 754 | return env->adjustments_brightness; |
| 755 | } |
| 756 | |
| 757 | float RendererEnvironmentStorage::environment_get_adjustments_contrast(RID p_env) const { |
| 758 | Environment *env = environment_owner.get_or_null(p_env); |
| 759 | ERR_FAIL_COND_V(!env, 1.0); |
| 760 | return env->adjustments_contrast; |
| 761 | } |
| 762 | |
| 763 | float RendererEnvironmentStorage::environment_get_adjustments_saturation(RID p_env) const { |
| 764 | Environment *env = environment_owner.get_or_null(p_env); |
| 765 | ERR_FAIL_COND_V(!env, 1.0); |
| 766 | return env->adjustments_saturation; |
| 767 | } |
| 768 | |
| 769 | bool RendererEnvironmentStorage::environment_get_use_1d_color_correction(RID p_env) const { |
| 770 | Environment *env = environment_owner.get_or_null(p_env); |
| 771 | ERR_FAIL_COND_V(!env, false); |
| 772 | return env->use_1d_color_correction; |
| 773 | } |
| 774 | |
| 775 | RID RendererEnvironmentStorage::environment_get_color_correction(RID p_env) const { |
| 776 | Environment *env = environment_owner.get_or_null(p_env); |
| 777 | ERR_FAIL_COND_V(!env, RID()); |
| 778 | return env->color_correction; |
| 779 | } |
| 780 | |