Debian Codegraph @

servers/rendering/storage/environment_storage.h

raw symbols SCIP
1 /**************************************************************************/
2 /* environment_storage.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/templates/rid_owner.h"
34 #include "servers/rendering/rendering_server.h"
35
36 class RendererEnvironmentStorage {
37 public:
38 union TonemapParameters {
39 // Shader vec4:
40 float tonemapper_params[4];
41
42 // Reinhard:
43 struct {
44 float white_squared;
45 };
46
47 // Filmic and ACES:
48 struct {
49 float white_tonemapped;
50 };
51
52 // AgX:
53 struct {
54 float awp_contrast;
55 float awp_toe_a;
56 float awp_slope;
57 float awp_w;
58 };
59 };
60
61 private:
62 static RendererEnvironmentStorage *singleton;
63
64 // Environment
65 struct Environment {
66 // Note, we capture and store all environment parameters received from Godot here.
67 // Not all renderers support all effects and should just ignore the bits they don't support.
68
69 // Background
70 RS::EnvironmentBG background = RS::ENV_BG_CLEAR_COLOR;
71 RID sky;
72 float sky_custom_fov = 0.0;
73 Basis sky_orientation;
74 Color bg_color;
75 float bg_energy_multiplier = 1.0;
76 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.
77 int canvas_max_layer = 0;
78 RS::EnvironmentAmbientSource ambient_source = RS::ENV_AMBIENT_SOURCE_BG;
79 Color ambient_light;
80 float ambient_light_energy = 1.0;
81 float ambient_sky_contribution = 1.0;
82 RS::EnvironmentReflectionSource reflection_source = RS::ENV_REFLECTION_SOURCE_BG;
83 int camera_feed_id = 0;
84
85 // Tonemap
86 RS::EnvironmentToneMapper tone_mapper;
87 float exposure = 1.0;
88 float white = 1.0;
89 float tonemap_agx_contrast = 1.25; // Default to approximately Blender's AgX contrast
90
91 // Fog
92 bool fog_enabled = false;
93 RS::EnvironmentFogMode fog_mode = RS::EnvironmentFogMode::ENV_FOG_MODE_EXPONENTIAL;
94 Color fog_light_color = Color(0.518, 0.553, 0.608);
95 float fog_light_energy = 1.0;
96 float fog_sun_scatter = 0.0;
97 float fog_density = 0.01;
98 float fog_sky_affect = 1.0;
99 float fog_height = 0.0;
100 float fog_height_density = 0.0; //can be negative to invert effect
101 float fog_aerial_perspective = 0.0;
102
103 // Depth Fog
104 float fog_depth_curve = 1.0;
105 float fog_depth_begin = 10.0;
106 float fog_depth_end = 100.0;
107
108 // Volumetric Fog
109 bool volumetric_fog_enabled = false;
110 float volumetric_fog_density = 0.01;
111 Color volumetric_fog_scattering = Color(1, 1, 1);
112 Color volumetric_fog_emission = Color(0, 0, 0);
113 float volumetric_fog_emission_energy = 0.0;
114 float volumetric_fog_anisotropy = 0.2;
115 float volumetric_fog_length = 64.0;
116 float volumetric_fog_detail_spread = 2.0;
117 float volumetric_fog_gi_inject = 1.0;
118 float volumetric_fog_ambient_inject = 0.0;
119 float volumetric_fog_sky_affect = 1.0;
120 bool volumetric_fog_temporal_reprojection = true;
121 float volumetric_fog_temporal_reprojection_amount = 0.9;
122
123 // Glow
124 bool glow_enabled = false;
125 Vector<float> glow_levels;
126 float glow_intensity = 0.3;
127 float glow_strength = 1.0;
128 float glow_bloom = 0.0;
129 float glow_mix = 0.01;
130 RS::EnvironmentGlowBlendMode glow_blend_mode = RS::ENV_GLOW_BLEND_MODE_SCREEN;
131 float glow_hdr_bleed_threshold = 1.0;
132 float glow_hdr_luminance_cap = 12.0;
133 float glow_hdr_bleed_scale = 2.0;
134 float glow_map_strength = 0.0f; // 1.0f in GLES3 ??
135 RID glow_map;
136
137 // SSR
138 bool ssr_enabled = false;
139 int ssr_max_steps = 64;
140 float ssr_fade_in = 0.15;
141 float ssr_fade_out = 2.0;
142 float ssr_depth_tolerance = 0.5;
143
144 // SSAO
145 bool ssao_enabled = false;
146 float ssao_radius = 1.0;
147 float ssao_intensity = 2.0;
148 float ssao_power = 1.5;
149 float ssao_detail = 0.5;
150 float ssao_horizon = 0.06;
151 float ssao_sharpness = 0.98;
152 float ssao_direct_light_affect = 0.0;
153 float ssao_ao_channel_affect = 0.0;
154
155 // SSIL
156 bool ssil_enabled = false;
157 float ssil_radius = 5.0;
158 float ssil_intensity = 1.0;
159 float ssil_sharpness = 0.98;
160 float ssil_normal_rejection = 1.0;
161
162 // SDFGI
163 bool sdfgi_enabled = false;
164 int sdfgi_cascades = 4;
165 float sdfgi_min_cell_size = 0.2;
166 bool sdfgi_use_occlusion = false;
167 float sdfgi_bounce_feedback = 0.5;
168 bool sdfgi_read_sky_light = true;
169 float sdfgi_energy = 1.0;
170 float sdfgi_normal_bias = 1.1;
171 float sdfgi_probe_bias = 1.1;
172 RS::EnvironmentSDFGIYScale sdfgi_y_scale = RS::ENV_SDFGI_Y_SCALE_75_PERCENT;
173
174 // Adjustments
175 bool adjustments_enabled = false;
176 float adjustments_brightness = 1.0f;
177 float adjustments_contrast = 1.0f;
178 float adjustments_saturation = 1.0f;
179 bool use_1d_color_correction = false;
180 RID color_correction;
181 };
182
183 mutable RID_Owner<Environment, true> environment_owner;
184
185 public:
186 static RendererEnvironmentStorage *get_singleton() { return singleton; }
187
188 RendererEnvironmentStorage();
189 virtual ~RendererEnvironmentStorage();
190
191 // Environment
192 RID environment_allocate();
193 void environment_initialize(RID p_rid);
194 void environment_free(RID p_rid);
195
196 bool is_environment(RID p_environment) const {
197 return environment_owner.owns(p_environment);
198 }
199
200 // Background
201 void environment_set_background(RID p_env, RS::EnvironmentBG p_bg);
202 void environment_set_sky(RID p_env, RID p_sky);
203 void environment_set_sky_custom_fov(RID p_env, float p_scale);
204 void environment_set_sky_orientation(RID p_env, const Basis &p_orientation);
205 void environment_set_bg_color(RID p_env, const Color &p_color);
206 void environment_set_bg_energy(RID p_env, float p_multiplier, float p_exposure_value);
207 void environment_set_canvas_max_layer(RID p_env, int p_max_layer);
208 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);
209 void environment_set_camera_feed_id(RID p_env, int p_camera_feed_id);
210 int environment_get_camera_feed_id(RID p_env) const;
211
212 RS::EnvironmentBG environment_get_background(RID p_env) const;
213 RID environment_get_sky(RID p_env) const;
214 float environment_get_sky_custom_fov(RID p_env) const;
215 Basis environment_get_sky_orientation(RID p_env) const;
216 Color environment_get_bg_color(RID p_env) const;
217 float environment_get_bg_energy_multiplier(RID p_env) const;
218 float environment_get_bg_intensity(RID p_env) const;
219 int environment_get_canvas_max_layer(RID p_env) const;
220 RS::EnvironmentAmbientSource environment_get_ambient_source(RID p_env) const;
221 Color environment_get_ambient_light(RID p_env) const;
222 float environment_get_ambient_light_energy(RID p_env) const;
223 float environment_get_ambient_sky_contribution(RID p_env) const;
224 RS::EnvironmentReflectionSource environment_get_reflection_source(RID p_env) const;
225
226 // Tonemap
227 void environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white);
228 RS::EnvironmentToneMapper environment_get_tone_mapper(RID p_env) const;
229 float environment_get_exposure(RID p_env) const;
230 float environment_get_white(RID p_env, bool p_limit_agx_white) const;
231 void environment_set_tonemap_agx_contrast(RID p_env, float p_agx_contrast);
232 float environment_get_tonemap_agx_contrast(RID p_env) const;
233 TonemapParameters environment_get_tonemap_parameters(RID p_env, bool p_limit_agx_white) const;
234
235 // Fog
236 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, float p_sky_affect, RS::EnvironmentFogMode p_mode);
237 bool environment_get_fog_enabled(RID p_env) const;
238 RS::EnvironmentFogMode environment_get_fog_mode(RID p_env) const;
239 Color environment_get_fog_light_color(RID p_env) const;
240 float environment_get_fog_light_energy(RID p_env) const;
241 float environment_get_fog_sun_scatter(RID p_env) const;
242 float environment_get_fog_density(RID p_env) const;
243 float environment_get_fog_sky_affect(RID p_env) const;
244 float environment_get_fog_height(RID p_env) const;
245 float environment_get_fog_height_density(RID p_env) const;
246 float environment_get_fog_aerial_perspective(RID p_env) const;
247
248 // Depth Fog
249 void environment_set_fog_depth(RID p_env, float p_curve, float p_begin, float p_end);
250 float environment_get_fog_depth_curve(RID p_env) const;
251 float environment_get_fog_depth_begin(RID p_env) const;
252 float environment_get_fog_depth_end(RID p_env) const;
253
254 // Volumetric Fog
255 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, float p_sky_affect);
256 bool environment_get_volumetric_fog_enabled(RID p_env) const;
257 float environment_get_volumetric_fog_density(RID p_env) const;
258 Color environment_get_volumetric_fog_scattering(RID p_env) const;
259 Color environment_get_volumetric_fog_emission(RID p_env) const;
260 float environment_get_volumetric_fog_emission_energy(RID p_env) const;
261 float environment_get_volumetric_fog_anisotropy(RID p_env) const;
262 float environment_get_volumetric_fog_length(RID p_env) const;
263 float environment_get_volumetric_fog_detail_spread(RID p_env) const;
264 float environment_get_volumetric_fog_gi_inject(RID p_env) const;
265 float environment_get_volumetric_fog_sky_affect(RID p_env) const;
266 bool environment_get_volumetric_fog_temporal_reprojection(RID p_env) const;
267 float environment_get_volumetric_fog_temporal_reprojection_amount(RID p_env) const;
268 float environment_get_volumetric_fog_ambient_inject(RID p_env) const;
269
270 // GLOW
271 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);
272 bool environment_get_glow_enabled(RID p_env) const;
273 Vector<float> environment_get_glow_levels(RID p_env) const;
274 float environment_get_glow_intensity(RID p_env) const;
275 float environment_get_glow_strength(RID p_env) const;
276 float environment_get_glow_bloom(RID p_env) const;
277 float environment_get_glow_mix(RID p_env) const;
278 RS::EnvironmentGlowBlendMode environment_get_glow_blend_mode(RID p_env) const;
279 float environment_get_glow_hdr_bleed_threshold(RID p_env) const;
280 float environment_get_glow_hdr_luminance_cap(RID p_env) const;
281 float environment_get_glow_hdr_bleed_scale(RID p_env) const;
282 float environment_get_glow_map_strength(RID p_env) const;
283 RID environment_get_glow_map(RID p_env) const;
284
285 // SSR
286 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);
287 bool environment_get_ssr_enabled(RID p_env) const;
288 int environment_get_ssr_max_steps(RID p_env) const;
289 float environment_get_ssr_fade_in(RID p_env) const;
290 float environment_get_ssr_fade_out(RID p_env) const;
291 float environment_get_ssr_depth_tolerance(RID p_env) const;
292
293 // SSAO
294 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);
295 bool environment_get_ssao_enabled(RID p_env) const;
296 float environment_get_ssao_radius(RID p_env) const;
297 float environment_get_ssao_intensity(RID p_env) const;
298 float environment_get_ssao_power(RID p_env) const;
299 float environment_get_ssao_detail(RID p_env) const;
300 float environment_get_ssao_horizon(RID p_env) const;
301 float environment_get_ssao_sharpness(RID p_env) const;
302 float environment_get_ssao_direct_light_affect(RID p_env) const;
303 float environment_get_ssao_ao_channel_affect(RID p_env) const;
304
305 // SSIL
306 void environment_set_ssil(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_sharpness, float p_normal_rejection);
307 bool environment_get_ssil_enabled(RID p_env) const;
308 float environment_get_ssil_radius(RID p_env) const;
309 float environment_get_ssil_intensity(RID p_env) const;
310 float environment_get_ssil_sharpness(RID p_env) const;
311 float environment_get_ssil_normal_rejection(RID p_env) const;
312
313 // SDFGI
314 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);
315 bool environment_get_sdfgi_enabled(RID p_env) const;
316 int environment_get_sdfgi_cascades(RID p_env) const;
317 float environment_get_sdfgi_min_cell_size(RID p_env) const;
318 bool environment_get_sdfgi_use_occlusion(RID p_env) const;
319 float environment_get_sdfgi_bounce_feedback(RID p_env) const;
320 bool environment_get_sdfgi_read_sky_light(RID p_env) const;
321 float environment_get_sdfgi_energy(RID p_env) const;
322 float environment_get_sdfgi_normal_bias(RID p_env) const;
323 float environment_get_sdfgi_probe_bias(RID p_env) const;
324 RS::EnvironmentSDFGIYScale environment_get_sdfgi_y_scale(RID p_env) const;
325
326 // Adjustment
327 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);
328 bool environment_get_adjustments_enabled(RID p_env) const;
329 float environment_get_adjustments_brightness(RID p_env) const;
330 float environment_get_adjustments_contrast(RID p_env) const;
331 float environment_get_adjustments_saturation(RID p_env) const;
332 bool environment_get_use_1d_color_correction(RID p_env) const;
333 RID environment_get_color_correction(RID p_env) const;
334 };