renderer_scene_environment_rd.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*************************************************************************/
  2. /* renderer_scene_environment_rd.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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. #include "servers/rendering/renderer_rd/renderer_scene_environment_rd.h"
  31. uint64_t RendererSceneEnvironmentRD::auto_exposure_counter = 2;
  32. void RendererSceneEnvironmentRD::set_ambient_light(const Color &p_color, RS::EnvironmentAmbientSource p_ambient, float p_energy, float p_sky_contribution, RS::EnvironmentReflectionSource p_reflection_source) {
  33. ambient_light = p_color;
  34. ambient_source = p_ambient;
  35. ambient_light_energy = p_energy;
  36. ambient_sky_contribution = p_sky_contribution;
  37. reflection_source = p_reflection_source;
  38. }
  39. void RendererSceneEnvironmentRD::set_tonemap(RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale) {
  40. exposure = p_exposure;
  41. tone_mapper = p_tone_mapper;
  42. if (!auto_exposure && p_auto_exposure) {
  43. auto_exposure_version = ++auto_exposure_counter;
  44. }
  45. auto_exposure = p_auto_exposure;
  46. white = p_white;
  47. min_luminance = p_min_luminance;
  48. max_luminance = p_max_luminance;
  49. auto_exp_speed = p_auto_exp_speed;
  50. auto_exp_scale = p_auto_exp_scale;
  51. }
  52. void RendererSceneEnvironmentRD::set_glow(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) {
  53. ERR_FAIL_COND_MSG(p_levels.size() != 7, "Size of array of glow levels must be 7");
  54. glow_enabled = p_enable;
  55. glow_levels = p_levels;
  56. glow_intensity = p_intensity;
  57. glow_strength = p_strength;
  58. glow_mix = p_mix;
  59. glow_bloom = p_bloom_threshold;
  60. glow_blend_mode = p_blend_mode;
  61. glow_hdr_bleed_threshold = p_hdr_bleed_threshold;
  62. glow_hdr_bleed_scale = p_hdr_bleed_scale;
  63. glow_hdr_luminance_cap = p_hdr_luminance_cap;
  64. }
  65. void RendererSceneEnvironmentRD::set_sdfgi(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) {
  66. sdfgi_enabled = p_enable;
  67. sdfgi_cascades = p_cascades;
  68. sdfgi_min_cell_size = p_min_cell_size;
  69. sdfgi_use_occlusion = p_use_occlusion;
  70. sdfgi_bounce_feedback = p_bounce_feedback;
  71. sdfgi_read_sky_light = p_read_sky;
  72. sdfgi_energy = p_energy;
  73. sdfgi_normal_bias = p_normal_bias;
  74. sdfgi_probe_bias = p_probe_bias;
  75. sdfgi_y_scale = p_y_scale;
  76. }
  77. void RendererSceneEnvironmentRD::set_fog(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) {
  78. fog_enabled = p_enable;
  79. fog_light_color = p_light_color;
  80. fog_light_energy = p_light_energy;
  81. fog_sun_scatter = p_sun_scatter;
  82. fog_density = p_density;
  83. fog_height = p_height;
  84. fog_height_density = p_height_density;
  85. fog_aerial_perspective = p_fog_aerial_perspective;
  86. }
  87. void RendererSceneEnvironmentRD::set_volumetric_fog(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) {
  88. volumetric_fog_enabled = p_enable;
  89. volumetric_fog_density = p_density;
  90. volumetric_fog_scattering = p_albedo;
  91. volumetric_fog_emission = p_emission;
  92. volumetric_fog_emission_energy = p_emission_energy;
  93. volumetric_fog_anisotropy = p_anisotropy,
  94. volumetric_fog_length = p_length;
  95. volumetric_fog_detail_spread = p_detail_spread;
  96. volumetric_fog_gi_inject = p_gi_inject;
  97. volumetric_fog_temporal_reprojection = p_temporal_reprojection;
  98. volumetric_fog_temporal_reprojection_amount = p_temporal_reprojection_amount;
  99. volumetric_fog_ambient_inject = p_ambient_inject;
  100. }
  101. void RendererSceneEnvironmentRD::set_ssr(bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance) {
  102. ssr_enabled = p_enable;
  103. ssr_max_steps = p_max_steps;
  104. ssr_fade_in = p_fade_int;
  105. ssr_fade_out = p_fade_out;
  106. ssr_depth_tolerance = p_depth_tolerance;
  107. }
  108. void RendererSceneEnvironmentRD::set_ssao(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) {
  109. ssao_enabled = p_enable;
  110. ssao_radius = p_radius;
  111. ssao_intensity = p_intensity;
  112. ssao_power = p_power;
  113. ssao_detail = p_detail;
  114. ssao_horizon = p_horizon;
  115. ssao_sharpness = p_sharpness;
  116. ssao_direct_light_affect = p_light_affect;
  117. ssao_ao_channel_affect = p_ao_channel_affect;
  118. }