environment_storage.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /*************************************************************************/
  2. /* environment_storage.h */
  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. #ifndef ENVIRONMENT_STORAGE_H
  31. #define ENVIRONMENT_STORAGE_H
  32. #include "core/templates/rid_owner.h"
  33. #include "servers/rendering_server.h"
  34. class RendererEnvironmentStorage {
  35. private:
  36. struct Environment {
  37. // Note, we capture and store all environment parameters received from Godot here.
  38. // Not all renderers support all effects and should just ignore the bits they don't support.
  39. // Background
  40. RS::EnvironmentBG background = RS::ENV_BG_CLEAR_COLOR;
  41. RID sky;
  42. float sky_custom_fov = 0.0;
  43. Basis sky_orientation;
  44. Color bg_color;
  45. float bg_energy_multiplier = 1.0;
  46. float bg_intensity = 1.0; // Measured in nits or candela/m^2. Default to 1.0 so this doesn't impact rendering when Physical Light Units disabled.
  47. int canvas_max_layer = 0;
  48. RS::EnvironmentAmbientSource ambient_source = RS::ENV_AMBIENT_SOURCE_BG;
  49. Color ambient_light;
  50. float ambient_light_energy = 1.0;
  51. float ambient_sky_contribution = 1.0;
  52. RS::EnvironmentReflectionSource reflection_source = RS::ENV_REFLECTION_SOURCE_BG;
  53. // Tonemap
  54. RS::EnvironmentToneMapper tone_mapper;
  55. float exposure = 1.0;
  56. float white = 1.0;
  57. // Fog
  58. bool fog_enabled = false;
  59. Color fog_light_color = Color(0.518, 0.553, 0.608);
  60. float fog_light_energy = 1.0;
  61. float fog_sun_scatter = 0.0;
  62. float fog_density = 0.01;
  63. float fog_height = 0.0;
  64. float fog_height_density = 0.0; //can be negative to invert effect
  65. float fog_aerial_perspective = 0.0;
  66. // Volumetric Fog
  67. bool volumetric_fog_enabled = false;
  68. float volumetric_fog_density = 0.01;
  69. Color volumetric_fog_scattering = Color(1, 1, 1);
  70. Color volumetric_fog_emission = Color(0, 0, 0);
  71. float volumetric_fog_emission_energy = 0.0;
  72. float volumetric_fog_anisotropy = 0.2;
  73. float volumetric_fog_length = 64.0;
  74. float volumetric_fog_detail_spread = 2.0;
  75. float volumetric_fog_gi_inject = 1.0;
  76. float volumetric_fog_ambient_inject = 0.0;
  77. bool volumetric_fog_temporal_reprojection = true;
  78. float volumetric_fog_temporal_reprojection_amount = 0.9;
  79. // Glow
  80. bool glow_enabled = false;
  81. Vector<float> glow_levels;
  82. float glow_intensity = 0.8;
  83. float glow_strength = 1.0;
  84. float glow_bloom = 0.0;
  85. float glow_mix = 0.01;
  86. RS::EnvironmentGlowBlendMode glow_blend_mode = RS::ENV_GLOW_BLEND_MODE_SOFTLIGHT;
  87. float glow_hdr_bleed_threshold = 1.0;
  88. float glow_hdr_luminance_cap = 12.0;
  89. float glow_hdr_bleed_scale = 2.0;
  90. float glow_map_strength = 0.0f; // 1.0f in GLES3 ??
  91. RID glow_map = RID();
  92. // SSR
  93. bool ssr_enabled = false;
  94. int ssr_max_steps = 64;
  95. float ssr_fade_in = 0.15;
  96. float ssr_fade_out = 2.0;
  97. float ssr_depth_tolerance = 0.2;
  98. // SSAO
  99. bool ssao_enabled = false;
  100. float ssao_radius = 1.0;
  101. float ssao_intensity = 2.0;
  102. float ssao_power = 1.5;
  103. float ssao_detail = 0.5;
  104. float ssao_horizon = 0.06;
  105. float ssao_sharpness = 0.98;
  106. float ssao_direct_light_affect = 0.0;
  107. float ssao_ao_channel_affect = 0.0;
  108. // SSIL
  109. bool ssil_enabled = false;
  110. float ssil_radius = 5.0;
  111. float ssil_intensity = 1.0;
  112. float ssil_sharpness = 0.98;
  113. float ssil_normal_rejection = 1.0;
  114. // SDFGI
  115. bool sdfgi_enabled = false;
  116. int sdfgi_cascades = 4;
  117. float sdfgi_min_cell_size = 0.2;
  118. bool sdfgi_use_occlusion = false;
  119. float sdfgi_bounce_feedback = 0.5;
  120. bool sdfgi_read_sky_light = true;
  121. float sdfgi_energy = 1.0;
  122. float sdfgi_normal_bias = 1.1;
  123. float sdfgi_probe_bias = 1.1;
  124. RS::EnvironmentSDFGIYScale sdfgi_y_scale = RS::ENV_SDFGI_Y_SCALE_75_PERCENT;
  125. // Adjustments
  126. bool adjustments_enabled = false;
  127. float adjustments_brightness = 1.0f;
  128. float adjustments_contrast = 1.0f;
  129. float adjustments_saturation = 1.0f;
  130. bool use_1d_color_correction = false;
  131. RID color_correction = RID();
  132. };
  133. mutable RID_Owner<Environment, true> environment_owner;
  134. public:
  135. RID environment_allocate();
  136. void environment_initialize(RID p_rid);
  137. void environment_free(RID p_rid);
  138. bool is_environment(RID p_environment) const {
  139. return environment_owner.owns(p_environment);
  140. }
  141. // Background
  142. void environment_set_background(RID p_env, RS::EnvironmentBG p_bg);
  143. void environment_set_sky(RID p_env, RID p_sky);
  144. void environment_set_sky_custom_fov(RID p_env, float p_scale);
  145. void environment_set_sky_orientation(RID p_env, const Basis &p_orientation);
  146. void environment_set_bg_color(RID p_env, const Color &p_color);
  147. void environment_set_bg_energy(RID p_env, float p_multiplier, float p_exposure_value);
  148. void environment_set_canvas_max_layer(RID p_env, int p_max_layer);
  149. void environment_set_ambient_light(RID p_env, const Color &p_color, RS::EnvironmentAmbientSource p_ambient = RS::ENV_AMBIENT_SOURCE_BG, float p_energy = 1.0, float p_sky_contribution = 0.0, RS::EnvironmentReflectionSource p_reflection_source = RS::ENV_REFLECTION_SOURCE_BG);
  150. // FIXME: Disabled during Vulkan refactoring, should be ported.
  151. #if 0
  152. void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id);
  153. #endif
  154. RS::EnvironmentBG environment_get_background(RID p_env) const;
  155. RID environment_get_sky(RID p_env) const;
  156. float environment_get_sky_custom_fov(RID p_env) const;
  157. Basis environment_get_sky_orientation(RID p_env) const;
  158. Color environment_get_bg_color(RID p_env) const;
  159. float environment_get_bg_energy_multiplier(RID p_env) const;
  160. float environment_get_bg_intensity(RID p_env) const;
  161. int environment_get_canvas_max_layer(RID p_env) const;
  162. RS::EnvironmentAmbientSource environment_get_ambient_source(RID p_env) const;
  163. Color environment_get_ambient_light(RID p_env) const;
  164. float environment_get_ambient_light_energy(RID p_env) const;
  165. float environment_get_ambient_sky_contribution(RID p_env) const;
  166. RS::EnvironmentReflectionSource environment_get_reflection_source(RID p_env) const;
  167. // Tonemap
  168. void environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white);
  169. RS::EnvironmentToneMapper environment_get_tone_mapper(RID p_env) const;
  170. float environment_get_exposure(RID p_env) const;
  171. float environment_get_white(RID p_env) const;
  172. // Fog
  173. void 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_aerial_perspective);
  174. bool environment_get_fog_enabled(RID p_env) const;
  175. Color environment_get_fog_light_color(RID p_env) const;
  176. float environment_get_fog_light_energy(RID p_env) const;
  177. float environment_get_fog_sun_scatter(RID p_env) const;
  178. float environment_get_fog_density(RID p_env) const;
  179. float environment_get_fog_height(RID p_env) const;
  180. float environment_get_fog_height_density(RID p_env) const;
  181. float environment_get_fog_aerial_perspective(RID p_env) const;
  182. // Volumetric Fog
  183. void 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);
  184. bool environment_get_volumetric_fog_enabled(RID p_env) const;
  185. float environment_get_volumetric_fog_density(RID p_env) const;
  186. Color environment_get_volumetric_fog_scattering(RID p_env) const;
  187. Color environment_get_volumetric_fog_emission(RID p_env) const;
  188. float environment_get_volumetric_fog_emission_energy(RID p_env) const;
  189. float environment_get_volumetric_fog_anisotropy(RID p_env) const;
  190. float environment_get_volumetric_fog_length(RID p_env) const;
  191. float environment_get_volumetric_fog_detail_spread(RID p_env) const;
  192. float environment_get_volumetric_fog_gi_inject(RID p_env) const;
  193. bool environment_get_volumetric_fog_temporal_reprojection(RID p_env) const;
  194. float environment_get_volumetric_fog_temporal_reprojection_amount(RID p_env) const;
  195. float environment_get_volumetric_fog_ambient_inject(RID p_env) const;
  196. // GLOW
  197. void 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);
  198. bool environment_get_glow_enabled(RID p_env) const;
  199. Vector<float> environment_get_glow_levels(RID p_env) const;
  200. float environment_get_glow_intensity(RID p_env) const;
  201. float environment_get_glow_strength(RID p_env) const;
  202. float environment_get_glow_bloom(RID p_env) const;
  203. float environment_get_glow_mix(RID p_env) const;
  204. RS::EnvironmentGlowBlendMode environment_get_glow_blend_mode(RID p_env) const;
  205. float environment_get_glow_hdr_bleed_threshold(RID p_env) const;
  206. float environment_get_glow_hdr_luminance_cap(RID p_env) const;
  207. float environment_get_glow_hdr_bleed_scale(RID p_env) const;
  208. float environment_get_glow_map_strength(RID p_env) const;
  209. RID environment_get_glow_map(RID p_env) const;
  210. // SSR
  211. void 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);
  212. bool environment_get_ssr_enabled(RID p_env) const;
  213. int environment_get_ssr_max_steps(RID p_env) const;
  214. float environment_get_ssr_fade_in(RID p_env) const;
  215. float environment_get_ssr_fade_out(RID p_env) const;
  216. float environment_get_ssr_depth_tolerance(RID p_env) const;
  217. // SSAO
  218. void 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);
  219. bool environment_get_ssao_enabled(RID p_env) const;
  220. float environment_get_ssao_radius(RID p_env) const;
  221. float environment_get_ssao_intensity(RID p_env) const;
  222. float environment_get_ssao_power(RID p_env) const;
  223. float environment_get_ssao_detail(RID p_env) const;
  224. float environment_get_ssao_horizon(RID p_env) const;
  225. float environment_get_ssao_sharpness(RID p_env) const;
  226. float environment_get_ssao_direct_light_affect(RID p_env) const;
  227. float environment_get_ssao_ao_channel_affect(RID p_env) const;
  228. // SSIL
  229. void environment_set_ssil(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_sharpness, float p_normal_rejection);
  230. bool environment_get_ssil_enabled(RID p_env) const;
  231. float environment_get_ssil_radius(RID p_env) const;
  232. float environment_get_ssil_intensity(RID p_env) const;
  233. float environment_get_ssil_sharpness(RID p_env) const;
  234. float environment_get_ssil_normal_rejection(RID p_env) const;
  235. // SDFGI
  236. void 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);
  237. bool environment_get_sdfgi_enabled(RID p_env) const;
  238. int environment_get_sdfgi_cascades(RID p_env) const;
  239. float environment_get_sdfgi_min_cell_size(RID p_env) const;
  240. bool environment_get_sdfgi_use_occlusion(RID p_env) const;
  241. float environment_get_sdfgi_bounce_feedback(RID p_env) const;
  242. bool environment_get_sdfgi_read_sky_light(RID p_env) const;
  243. float environment_get_sdfgi_energy(RID p_env) const;
  244. float environment_get_sdfgi_normal_bias(RID p_env) const;
  245. float environment_get_sdfgi_probe_bias(RID p_env) const;
  246. RS::EnvironmentSDFGIYScale environment_get_sdfgi_y_scale(RID p_env) const;
  247. // Adjustment
  248. void 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);
  249. bool environment_get_adjustments_enabled(RID p_env) const;
  250. float environment_get_adjustments_brightness(RID p_env) const;
  251. float environment_get_adjustments_contrast(RID p_env) const;
  252. float environment_get_adjustments_saturation(RID p_env) const;
  253. bool environment_get_use_1d_color_correction(RID p_env) const;
  254. RID environment_get_color_correction(RID p_env) const;
  255. };
  256. #endif // ENVIRONMENT_STORAGE_H