Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/servers/rendering/renderer_rd/renderer_scene_render_rd.h
11354 views
1
/**************************************************************************/
2
/* renderer_scene_render_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_compositor.h"
34
#include "servers/rendering/renderer_rd/effects/bokeh_dof.h"
35
#include "servers/rendering/renderer_rd/effects/copy_effects.h"
36
#include "servers/rendering/renderer_rd/effects/debug_effects.h"
37
#include "servers/rendering/renderer_rd/effects/fsr.h"
38
#include "servers/rendering/renderer_rd/effects/luminance.h"
39
#ifdef METAL_ENABLED
40
#include "servers/rendering/renderer_rd/effects/metal_fx.h"
41
#endif
42
#include "servers/rendering/renderer_rd/effects/resolve.h"
43
#include "servers/rendering/renderer_rd/effects/smaa.h"
44
#include "servers/rendering/renderer_rd/effects/tone_mapper.h"
45
#include "servers/rendering/renderer_rd/effects/vrs.h"
46
#include "servers/rendering/renderer_rd/environment/gi.h"
47
#include "servers/rendering/renderer_rd/environment/sky.h"
48
#include "servers/rendering/renderer_rd/storage_rd/light_storage.h"
49
#include "servers/rendering/renderer_rd/storage_rd/render_data_rd.h"
50
#include "servers/rendering/renderer_rd/storage_rd/render_scene_buffers_rd.h"
51
#include "servers/rendering/renderer_scene_render.h"
52
#include "servers/rendering/rendering_device.h"
53
#include "servers/rendering/rendering_method.h"
54
#include "servers/rendering/rendering_shader_library.h"
55
56
class RendererSceneRenderRD : public RendererSceneRender, public RenderingShaderLibrary {
57
friend RendererRD::SkyRD;
58
friend RendererRD::GI;
59
60
protected:
61
RendererRD::ForwardIDStorage *forward_id_storage = nullptr;
62
RendererRD::BokehDOF *bokeh_dof = nullptr;
63
RendererRD::CopyEffects *copy_effects = nullptr;
64
RendererRD::DebugEffects *debug_effects = nullptr;
65
RendererRD::Luminance *luminance = nullptr;
66
RendererRD::SMAA *smaa = nullptr;
67
RendererRD::ToneMapper *tone_mapper = nullptr;
68
RendererRD::FSR *fsr = nullptr;
69
RendererRD::VRS *vrs = nullptr;
70
RendererRD::Resolve *resolve_effects = nullptr;
71
#ifdef METAL_ENABLED
72
RendererRD::MFXSpatialEffect *mfx_spatial = nullptr;
73
#endif
74
double time = 0.0;
75
double time_step = 0.0;
76
77
/* ENVIRONMENT */
78
79
bool glow_bicubic_upscale = false;
80
81
bool use_physical_light_units = false;
82
83
////////////////////////////////
84
85
virtual RendererRD::ForwardIDStorage *create_forward_id_storage() { return memnew(RendererRD::ForwardIDStorage); }
86
87
void _update_vrs(Ref<RenderSceneBuffersRD> p_render_buffers);
88
89
virtual void setup_render_buffer_data(Ref<RenderSceneBuffersRD> p_render_buffers) = 0;
90
91
virtual void _render_scene(RenderDataRD *p_render_data, const Color &p_default_color) = 0;
92
virtual void _render_buffers_debug_draw(const RenderDataRD *p_render_data);
93
94
virtual void _render_material(const Transform3D &p_cam_transform, const Projection &p_cam_projection, bool p_cam_orthogonal, const PagedArray<RenderGeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region, float p_exposure_normalization) = 0;
95
virtual void _render_uv2(const PagedArray<RenderGeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) = 0;
96
virtual void _render_sdfgi(Ref<RenderSceneBuffersRD> p_render_buffers, const Vector3i &p_from, const Vector3i &p_size, const AABB &p_bounds, const PagedArray<RenderGeometryInstance *> &p_instances, const RID &p_albedo_texture, const RID &p_emission_texture, const RID &p_emission_aniso_texture, const RID &p_geom_facing_texture, float p_exposure_normalization) = 0;
97
virtual void _render_particle_collider_heightfield(RID p_fb, const Transform3D &p_cam_transform, const Projection &p_cam_projection, const PagedArray<RenderGeometryInstance *> &p_instances) = 0;
98
99
void _debug_sdfgi_probes(Ref<RenderSceneBuffersRD> p_render_buffers, RID p_framebuffer, uint32_t p_view_count, const Projection *p_camera_with_transforms);
100
101
virtual RID _render_buffers_get_normal_texture(Ref<RenderSceneBuffersRD> p_render_buffers) = 0;
102
virtual RID _render_buffers_get_velocity_texture(Ref<RenderSceneBuffersRD> p_render_buffers) = 0;
103
104
bool _needs_post_prepass_render(RenderDataRD *p_render_data, bool p_use_gi);
105
void _post_prepass_render(RenderDataRD *p_render_data, bool p_use_gi);
106
107
bool _compositor_effects_has_flag(const RenderDataRD *p_render_data, RS::CompositorEffectFlags p_flag, RS::CompositorEffectCallbackType p_callback_type = RS::COMPOSITOR_EFFECT_CALLBACK_TYPE_ANY);
108
bool _has_compositor_effect(RS::CompositorEffectCallbackType p_callback_type, const RenderDataRD *p_render_data);
109
void _process_compositor_effects(RS::CompositorEffectCallbackType p_callback_type, const RenderDataRD *p_render_data);
110
void _render_buffers_ensure_screen_texture(const RenderDataRD *p_render_data);
111
void _render_buffers_copy_screen_texture(const RenderDataRD *p_render_data);
112
void _render_buffers_ensure_depth_texture(const RenderDataRD *p_render_data);
113
void _render_buffers_copy_depth_texture(const RenderDataRD *p_render_data, bool p_use_msaa = false);
114
void _render_buffers_post_process_and_tonemap(const RenderDataRD *p_render_data, bool p_use_msaa = false);
115
void _post_process_subpass(RID p_source_texture, RID p_framebuffer, const RenderDataRD *p_render_data);
116
void _disable_clear_request(const RenderDataRD *p_render_data);
117
118
_FORCE_INLINE_ bool _is_8bit_data_format(RD::DataFormat p_data_format) {
119
return p_data_format >= RD::DATA_FORMAT_R8_UNORM && p_data_format <= RD::DATA_FORMAT_A8B8G8R8_SRGB_PACK32;
120
}
121
122
_FORCE_INLINE_ bool _is_10bit_data_format(RD::DataFormat p_data_format) {
123
return p_data_format >= RD::DATA_FORMAT_A2R10G10B10_UNORM_PACK32 && p_data_format <= RD::DATA_FORMAT_A2B10G10R10_SINT_PACK32;
124
}
125
126
// needed for a single argument calls (material and uv2)
127
PagedArrayPool<RenderGeometryInstance *> cull_argument_pool;
128
PagedArray<RenderGeometryInstance *> cull_argument; //need this to exist
129
130
RendererRD::SkyRD sky;
131
RendererRD::GI gi;
132
133
virtual void _update_shader_quality_settings() {}
134
static bool _debug_draw_can_use_effects(RS::ViewportDebugDraw p_debug_draw);
135
136
private:
137
RS::ViewportDebugDraw debug_draw = RS::VIEWPORT_DEBUG_DRAW_DISABLED;
138
static RendererSceneRenderRD *singleton;
139
140
/* Shadow atlas */
141
RS::ShadowQuality shadows_quality = RS::SHADOW_QUALITY_MAX; //So it always updates when first set
142
RS::ShadowQuality directional_shadow_quality = RS::SHADOW_QUALITY_MAX;
143
float shadows_quality_radius = 1.0;
144
float directional_shadow_quality_radius = 1.0;
145
146
float *directional_penumbra_shadow_kernel = nullptr;
147
float *directional_soft_shadow_kernel = nullptr;
148
float *penumbra_shadow_kernel = nullptr;
149
float *soft_shadow_kernel = nullptr;
150
bool lightmap_filter_bicubic = false;
151
int directional_penumbra_shadow_samples = 0;
152
int directional_soft_shadow_samples = 0;
153
int penumbra_shadow_samples = 0;
154
int soft_shadow_samples = 0;
155
RS::DecalFilter decals_filter = RS::DECAL_FILTER_LINEAR_MIPMAPS;
156
RS::LightProjectorFilter light_projectors_filter = RS::LIGHT_PROJECTOR_FILTER_LINEAR_MIPMAPS;
157
158
/* RENDER BUFFERS */
159
160
/* GI */
161
bool screen_space_roughness_limiter = false;
162
float screen_space_roughness_limiter_amount = 0.25;
163
float screen_space_roughness_limiter_limit = 0.18;
164
165
/* Light data */
166
167
uint64_t scene_pass = 0;
168
169
uint32_t max_cluster_elements = 512;
170
171
/* Volumetric Fog */
172
173
uint32_t volumetric_fog_size = 128;
174
uint32_t volumetric_fog_depth = 128;
175
bool volumetric_fog_filter_active = true;
176
177
public:
178
static RendererSceneRenderRD *get_singleton() { return singleton; }
179
180
/* LIGHTING */
181
182
virtual void setup_added_reflection_probe(const Transform3D &p_transform, const Vector3 &p_half_size) {}
183
virtual void setup_added_light(const RS::LightType p_type, const Transform3D &p_transform, float p_radius, float p_spot_aperture) {}
184
virtual void setup_added_decal(const Transform3D &p_transform, const Vector3 &p_half_size) {}
185
186
/* GI */
187
188
RendererRD::GI *get_gi() { return &gi; }
189
190
/* SKY */
191
192
RendererRD::SkyRD *get_sky() { return &sky; }
193
194
/* SKY API */
195
196
virtual RID sky_allocate() override;
197
virtual void sky_initialize(RID p_rid) override;
198
199
virtual void sky_set_radiance_size(RID p_sky, int p_radiance_size) override;
200
virtual void sky_set_mode(RID p_sky, RS::SkyMode p_mode) override;
201
virtual void sky_set_material(RID p_sky, RID p_material) override;
202
virtual Ref<Image> sky_bake_panorama(RID p_sky, float p_energy, bool p_bake_irradiance, const Size2i &p_size) override;
203
204
/* ENVIRONMENT API */
205
206
virtual void environment_glow_set_use_bicubic_upscale(bool p_enable) override;
207
208
virtual void environment_set_volumetric_fog_volume_size(int p_size, int p_depth) override;
209
virtual void environment_set_volumetric_fog_filter_active(bool p_enable) override;
210
211
virtual void environment_set_sdfgi_ray_count(RS::EnvironmentSDFGIRayCount p_ray_count) override;
212
virtual void environment_set_sdfgi_frames_to_converge(RS::EnvironmentSDFGIFramesToConverge p_frames) override;
213
virtual void environment_set_sdfgi_frames_to_update_light(RS::EnvironmentSDFGIFramesToUpdateLight p_update) override;
214
215
virtual Ref<Image> environment_bake_panorama(RID p_env, bool p_bake_irradiance, const Size2i &p_size) override;
216
217
_FORCE_INLINE_ bool is_using_physical_light_units() {
218
return use_physical_light_units;
219
}
220
221
/* REFLECTION PROBE */
222
223
virtual RID reflection_probe_create_framebuffer(RID p_color, RID p_depth);
224
225
/* FOG VOLUMES */
226
227
uint32_t get_volumetric_fog_size() const { return volumetric_fog_size; }
228
uint32_t get_volumetric_fog_depth() const { return volumetric_fog_depth; }
229
bool get_volumetric_fog_filter_active() const { return volumetric_fog_filter_active; }
230
231
virtual RID fog_volume_instance_create(RID p_fog_volume) override;
232
virtual void fog_volume_instance_set_transform(RID p_fog_volume_instance, const Transform3D &p_transform) override;
233
virtual void fog_volume_instance_set_active(RID p_fog_volume_instance, bool p_active) override;
234
virtual RID fog_volume_instance_get_volume(RID p_fog_volume_instance) const override;
235
virtual Vector3 fog_volume_instance_get_position(RID p_fog_volume_instance) const override;
236
237
/* gi light probes */
238
239
virtual RID voxel_gi_instance_create(RID p_base) override;
240
virtual void voxel_gi_instance_set_transform_to_data(RID p_probe, const Transform3D &p_xform) override;
241
virtual bool voxel_gi_needs_update(RID p_probe) const override;
242
virtual void voxel_gi_update(RID p_probe, bool p_update_light_instances, const Vector<RID> &p_light_instances, const PagedArray<RenderGeometryInstance *> &p_dynamic_objects) override;
243
virtual void voxel_gi_set_quality(RS::VoxelGIQuality p_quality) override { gi.voxel_gi_quality = p_quality; }
244
245
/* render buffers */
246
247
virtual float _render_buffers_get_luminance_multiplier();
248
virtual RD::DataFormat _render_buffers_get_color_format();
249
virtual bool _render_buffers_can_be_storage();
250
virtual Ref<RenderSceneBuffers> render_buffers_create() override;
251
virtual void gi_set_use_half_resolution(bool p_enable) override;
252
253
RID render_buffers_get_default_voxel_gi_buffer();
254
255
virtual void base_uniforms_changed() = 0;
256
257
virtual void render_scene(const Ref<RenderSceneBuffers> &p_render_buffers, const CameraData *p_camera_data, const CameraData *p_prev_camera_data, const PagedArray<RenderGeometryInstance *> &p_instances, const PagedArray<RID> &p_lights, const PagedArray<RID> &p_reflection_probes, const PagedArray<RID> &p_voxel_gi_instances, const PagedArray<RID> &p_decals, const PagedArray<RID> &p_lightmaps, const PagedArray<RID> &p_fog_volumes, RID p_environment, RID p_camera_attributes, RID p_compositor, RID p_shadow_atlas, RID p_occluder_debug_tex, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass, float p_screen_mesh_lod_threshold, const RenderShadowData *p_render_shadows, int p_render_shadow_count, const RenderSDFGIData *p_render_sdfgi_regions, int p_render_sdfgi_region_count, const RenderSDFGIUpdateData *p_sdfgi_update_data = nullptr, RenderingMethod::RenderInfo *r_render_info = nullptr) override;
258
259
virtual void render_material(const Transform3D &p_cam_transform, const Projection &p_cam_projection, bool p_cam_orthogonal, const PagedArray<RenderGeometryInstance *> &p_instances, RID p_framebuffer, const Rect2i &p_region) override;
260
261
virtual void render_particle_collider_heightfield(RID p_collider, const Transform3D &p_transform, const PagedArray<RenderGeometryInstance *> &p_instances) override;
262
263
virtual void set_scene_pass(uint64_t p_pass) override {
264
scene_pass = p_pass;
265
}
266
_FORCE_INLINE_ uint64_t get_scene_pass() {
267
return scene_pass;
268
}
269
270
virtual void screen_space_roughness_limiter_set_active(bool p_enable, float p_amount, float p_limit) override;
271
virtual bool screen_space_roughness_limiter_is_active() const override;
272
virtual float screen_space_roughness_limiter_get_amount() const;
273
virtual float screen_space_roughness_limiter_get_limit() const;
274
275
virtual void positional_soft_shadow_filter_set_quality(RS::ShadowQuality p_quality) override;
276
virtual void directional_soft_shadow_filter_set_quality(RS::ShadowQuality p_quality) override;
277
278
virtual void decals_set_filter(RS::DecalFilter p_filter) override;
279
virtual void light_projectors_set_filter(RS::LightProjectorFilter p_filter) override;
280
virtual void lightmaps_set_bicubic_filter(bool p_enable) override;
281
282
_FORCE_INLINE_ RS::ShadowQuality shadows_quality_get() const {
283
return shadows_quality;
284
}
285
_FORCE_INLINE_ RS::ShadowQuality directional_shadow_quality_get() const {
286
return directional_shadow_quality;
287
}
288
_FORCE_INLINE_ float shadows_quality_radius_get() const {
289
return shadows_quality_radius;
290
}
291
_FORCE_INLINE_ float directional_shadow_quality_radius_get() const {
292
return directional_shadow_quality_radius;
293
}
294
295
_FORCE_INLINE_ float *directional_penumbra_shadow_kernel_get() {
296
return directional_penumbra_shadow_kernel;
297
}
298
_FORCE_INLINE_ float *directional_soft_shadow_kernel_get() {
299
return directional_soft_shadow_kernel;
300
}
301
_FORCE_INLINE_ float *penumbra_shadow_kernel_get() {
302
return penumbra_shadow_kernel;
303
}
304
_FORCE_INLINE_ float *soft_shadow_kernel_get() {
305
return soft_shadow_kernel;
306
}
307
308
_FORCE_INLINE_ int directional_penumbra_shadow_samples_get() const {
309
return directional_penumbra_shadow_samples;
310
}
311
_FORCE_INLINE_ bool lightmap_filter_bicubic_get() const {
312
return lightmap_filter_bicubic;
313
}
314
_FORCE_INLINE_ int directional_soft_shadow_samples_get() const {
315
return directional_soft_shadow_samples;
316
}
317
_FORCE_INLINE_ int penumbra_shadow_samples_get() const {
318
return penumbra_shadow_samples;
319
}
320
_FORCE_INLINE_ int soft_shadow_samples_get() const {
321
return soft_shadow_samples;
322
}
323
324
_FORCE_INLINE_ RS::LightProjectorFilter light_projectors_get_filter() const {
325
return light_projectors_filter;
326
}
327
_FORCE_INLINE_ RS::DecalFilter decals_get_filter() const {
328
return decals_filter;
329
}
330
331
int get_roughness_layers() const;
332
bool is_using_radiance_cubemap_array() const;
333
334
virtual TypedArray<Image> bake_render_uv2(RID p_base, const TypedArray<RID> &p_material_overrides, const Size2i &p_image_size) override;
335
336
virtual bool free(RID p_rid) override;
337
338
virtual void update() override;
339
340
virtual void set_debug_draw_mode(RS::ViewportDebugDraw p_debug_draw) override;
341
_FORCE_INLINE_ RS::ViewportDebugDraw get_debug_draw_mode() const {
342
return debug_draw;
343
}
344
345
virtual void set_time(double p_time, double p_step) override;
346
347
virtual void sdfgi_set_debug_probe_select(const Vector3 &p_position, const Vector3 &p_dir) override;
348
349
virtual bool is_vrs_supported() const;
350
virtual bool is_dynamic_gi_supported() const;
351
virtual bool is_volumetric_supported() const;
352
virtual uint32_t get_max_elements() const;
353
354
void init();
355
356
RendererSceneRenderRD();
357
~RendererSceneRenderRD();
358
};
359
360