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#ifndef RENDER_SCENE_DATA_RD_H
32#define RENDER_SCENE_DATA_RD_H
33
34#include "render_scene_buffers_rd.h"
35#include "servers/rendering/renderer_scene_render.h"
36#include "servers/rendering/rendering_device.h"
37
38// This is a container for data related to rendering a single frame of a viewport where we load this data into a UBO
39// that can be used by the main scene shader but also by various effects.
40
41class RenderSceneDataRD {
42public:
43 bool calculate_motion_vectors = false;
44
45 Transform3D cam_transform;
46 Projection cam_projection;
47 Vector2 taa_jitter;
48 uint32_t camera_visible_layers;
49 bool cam_orthogonal = false;
50
51 // For stereo rendering
52 uint32_t view_count = 1;
53 Vector3 view_eye_offset[RendererSceneRender::MAX_RENDER_VIEWS];
54 Projection view_projection[RendererSceneRender::MAX_RENDER_VIEWS];
55
56 Transform3D prev_cam_transform;
57 Projection prev_cam_projection;
58 Vector2 prev_taa_jitter;
59 Projection prev_view_projection[RendererSceneRender::MAX_RENDER_VIEWS];
60
61 float z_near = 0.0;
62 float z_far = 0.0;
63
64 float lod_distance_multiplier = 0.0;
65 float screen_mesh_lod_threshold = 0.0;
66
67 uint32_t directional_light_count = 0;
68 float dual_paraboloid_side = 0.0;
69 float opaque_prepass_threshold = 0.0;
70 bool material_uv2_mode = false;
71 float emissive_exposure_normalization = 0.0;
72
73 Size2 shadow_atlas_pixel_size;
74 Size2 directional_shadow_pixel_size;
75
76 float time;
77 float time_step;
78
79 RID create_uniform_buffer();
80 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_flip_y, bool p_pancake_shadows, const Size2i &p_screen_size, const Color &p_default_bg_color, float p_luminance_multiplier, bool p_opaque_render_buffers);
81 RID get_uniform_buffer();
82
83private:
84 RID uniform_buffer; // loaded into this uniform buffer (supplied externally)
85
86 // This struct is loaded into Set 1 - Binding 0, populated at start of rendering a frame, must match with shader code
87 struct UBO {
88 float projection_matrix[16];
89 float inv_projection_matrix[16];
90 float inv_view_matrix[16];
91 float view_matrix[16];
92
93 float projection_matrix_view[RendererSceneRender::MAX_RENDER_VIEWS][16];
94 float inv_projection_matrix_view[RendererSceneRender::MAX_RENDER_VIEWS][16];
95 float eye_offset[RendererSceneRender::MAX_RENDER_VIEWS][4];
96
97 float viewport_size[2];
98 float screen_pixel_size[2];
99
100 float directional_penumbra_shadow_kernel[128]; //32 vec4s
101 float directional_soft_shadow_kernel[128];
102 float penumbra_shadow_kernel[128];
103 float soft_shadow_kernel[128];
104
105 float radiance_inverse_xform[12];
106
107 float ambient_light_color_energy[4];
108
109 float ambient_color_sky_mix;
110 uint32_t use_ambient_light;
111 uint32_t use_ambient_cubemap;
112 uint32_t use_reflection_cubemap;
113
114 float shadow_atlas_pixel_size[2];
115 float directional_shadow_pixel_size[2];
116
117 uint32_t directional_light_count;
118 float dual_paraboloid_side;
119 float z_far;
120 float z_near;
121
122 uint32_t roughness_limiter_enabled;
123 float roughness_limiter_amount;
124 float roughness_limiter_limit;
125 float opaque_prepass_threshold;
126
127 // Fog
128 uint32_t fog_enabled;
129 float fog_density;
130 float fog_height;
131 float fog_height_density;
132
133 float fog_light_color[3];
134 float fog_sun_scatter;
135
136 float fog_aerial_perspective;
137 float time;
138 float reflection_multiplier;
139 uint32_t material_uv2_mode;
140
141 float taa_jitter[2];
142 float emissive_exposure_normalization; // Needed to normalize emissive when using physical units.
143 float IBL_exposure_normalization; // Adjusts for baked exposure.
144
145 uint32_t pancake_shadows;
146 uint32_t camera_visible_layers;
147 uint32_t pad2;
148 uint32_t pad3;
149 };
150
151 struct UBODATA {
152 UBO ubo;
153 UBO prev_ubo;
154 };
155};
156
157#endif // RENDER_SCENE_DATA_RD_H
158