Debian Codegraph @

servers/rendering/renderer_rd/storage_rd/render_scene_data_rd.h

raw symbols SCIP
1 /**************************************************************************/
2 /* render_scene_data_rd.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 "servers/rendering/renderer_scene_render.h"
34 #include "servers/rendering/storage/render_scene_data.h"
35
36 // This is a container for data related to rendering a single frame of a viewport where we load this data into a UBO
37 // that can be used by the main scene shader but also by various effects.
38
39 class RenderSceneDataRD : public RenderSceneData {
40 GDCLASS(RenderSceneDataRD, RenderSceneData);
41
42 public:
43 bool calculate_motion_vectors = false;
44
45 Transform3D cam_transform;
46 Projection cam_projection;
47 Vector2 taa_jitter;
48 float taa_frame_count = 0.0f;
49 uint32_t camera_visible_layers;
50 bool cam_orthogonal = false;
51 bool cam_frustum = false;
52 bool flip_y = false;
53
54 // For billboards to cast correct shadows.
55 Transform3D main_cam_transform;
56
57 // For stereo rendering
58 uint32_t view_count = 1;
59 Vector3 view_eye_offset[RendererSceneRender::MAX_RENDER_VIEWS];
60 Projection view_projection[RendererSceneRender::MAX_RENDER_VIEWS];
61
62 Transform3D prev_cam_transform;
63 Projection prev_cam_projection;
64 Vector2 prev_taa_jitter;
65 Projection prev_view_projection[RendererSceneRender::MAX_RENDER_VIEWS];
66
67 float z_near = 0.0;
68 float z_far = 0.0;
69
70 float lod_distance_multiplier = 0.0;
71 float screen_mesh_lod_threshold = 0.0;
72
73 uint32_t directional_light_count = 0;
74 float dual_paraboloid_side = 0.0;
75 float opaque_prepass_threshold = 0.0;
76 bool material_uv2_mode = false;
77 float emissive_exposure_normalization = 0.0;
78 bool shadow_pass = false;
79
80 Size2 shadow_atlas_pixel_size;
81 Size2 directional_shadow_pixel_size;
82
83 float radiance_pixel_size;
84 float radiance_border_size;
85 Size2 reflection_atlas_border_size;
86
87 float time;
88 float time_step;
89
90 virtual Transform3D get_cam_transform() const override;
91 virtual Projection get_cam_projection() const override;
92
93 virtual uint32_t get_view_count() const override;
94 virtual Vector3 get_view_eye_offset(uint32_t p_view) const override;
95 virtual Projection get_view_projection(uint32_t p_view) const override;
96
97 RID create_uniform_buffer();
98 void update_ubo(RID p_uniform_buffer, RS::ViewportDebugDraw p_debug_mode, RID p_env, RID p_reflection_probe_instance, RID p_camera_attributes, bool p_pancake_shadows, const Size2i &p_screen_size, const Size2 &p_viewport_size, const Color &p_default_bg_color, float p_luminance_multiplier, bool p_opaque_render_buffers, bool p_apply_alpha_multiplier);
99 virtual RID get_uniform_buffer() const override;
100
101 static uint32_t get_uniform_buffer_size_bytes() { return sizeof(UBODATA); }
102
103 private:
104 RID uniform_buffer; // loaded into this uniform buffer (supplied externally)
105
106 enum SceneDataFlags {
107 SCENE_DATA_FLAGS_USE_AMBIENT_LIGHT = 1 << 0,
108 SCENE_DATA_FLAGS_USE_AMBIENT_CUBEMAP = 1 << 1,
109 SCENE_DATA_FLAGS_USE_REFLECTION_CUBEMAP = 1 << 2,
110 SCENE_DATA_FLAGS_USE_ROUGHNESS_LIMITER = 1 << 3,
111 SCENE_DATA_FLAGS_USE_FOG = 1 << 4,
112 SCENE_DATA_FLAGS_USE_UV2_MATERIAL = 1 << 5,
113 SCENE_DATA_FLAGS_USE_PANCAKE_SHADOWS = 1 << 6,
114 SCENE_DATA_FLAGS_IN_SHADOW_PASS = 1 << 7, // Only used by Forward+ renderer.
115 SCENE_DATA_FLAGS_MAX
116 };
117
118 // This struct is loaded into Set 1 - Binding 0, populated at start of rendering a frame, must match with shader code
119 struct UBO {
120 float projection_matrix[16];
121 float inv_projection_matrix[16];
122 float inv_view_matrix[12];
123 float view_matrix[12];
124
125 #ifdef REAL_T_IS_DOUBLE
126 float inv_view_precision[4];
127 #endif
128
129 float projection_matrix_view[RendererSceneRender::MAX_RENDER_VIEWS][16];
130 float inv_projection_matrix_view[RendererSceneRender::MAX_RENDER_VIEWS][16];
131 float eye_offset[RendererSceneRender::MAX_RENDER_VIEWS][4];
132
133 float main_cam_inv_view_matrix[16];
134
135 float viewport_size[2];
136 float screen_pixel_size[2];
137
138 float directional_penumbra_shadow_kernel[128]; //32 vec4s
139 float directional_soft_shadow_kernel[128];
140 float penumbra_shadow_kernel[128];
141 float soft_shadow_kernel[128];
142
143 float shadow_atlas_pixel_size[2];
144 float directional_shadow_pixel_size[2];
145
146 float radiance_pixel_size;
147 float radiance_border_size;
148 float reflection_atlas_border_size[2];
149
150 uint32_t directional_light_count;
151 float dual_paraboloid_side;
152 float z_far;
153 float z_near;
154
155 float roughness_limiter_amount;
156 float roughness_limiter_limit;
157 float opaque_prepass_threshold;
158 uint32_t flags;
159
160 float radiance_inverse_xform[12];
161
162 float ambient_light_color_energy[4];
163
164 float ambient_color_sky_mix;
165 float fog_density;
166 float fog_height;
167 float fog_height_density;
168
169 float fog_depth_curve;
170 float fog_depth_begin;
171 float fog_depth_end;
172 float fog_sun_scatter;
173
174 float fog_light_color[3];
175 float fog_aerial_perspective;
176
177 float time;
178 float taa_frame_count; // Used to add break up samples over multiple frames. Value is an integer from 0 to taa_phase_count -1.
179 float taa_jitter[2];
180
181 float emissive_exposure_normalization; // Needed to normalize emissive when using physical units.
182 float IBL_exposure_normalization; // Adjusts for baked exposure.
183 uint32_t camera_visible_layers;
184 float pass_alpha_multiplier;
185 };
186
187 struct UBODATA {
188 UBO ubo;
189 UBO prev_ubo;
190 };
191 };