Parcourir la source

Merge pull request #61221 from BastiaanOlij/split_gi_effects

Rémi Verschelde il y a 3 ans
Parent
commit
051fb86fb0
52 fichiers modifiés avec 1770 ajouts et 1044 suppressions
  1. 1 0
      drivers/gles3/SCsub
  2. 5 0
      drivers/gles3/environment/SCsub
  3. 140 0
      drivers/gles3/environment/gi.cpp
  4. 99 0
      drivers/gles3/environment/gi.h
  5. 3 0
      drivers/gles3/rasterizer_gles3.cpp
  6. 3 0
      drivers/gles3/rasterizer_gles3.h
  7. 0 100
      drivers/gles3/rasterizer_storage_gles3.cpp
  8. 0 41
      drivers/gles3/rasterizer_storage_gles3.h
  9. 6 0
      drivers/vulkan/rendering_device_vulkan.cpp
  10. 85 0
      servers/rendering/dummy/environment/gi.h
  11. 3 0
      servers/rendering/dummy/rasterizer_dummy.h
  12. 0 41
      servers/rendering/dummy/rasterizer_storage_dummy.h
  13. 85 0
      servers/rendering/environment/renderer_gi.h
  14. 2 0
      servers/rendering/renderer_compositor.h
  15. 1 0
      servers/rendering/renderer_rd/SCsub
  16. 130 0
      servers/rendering/renderer_rd/effects/resolve.cpp
  17. 74 0
      servers/rendering/renderer_rd/effects/resolve.h
  18. 0 56
      servers/rendering/renderer_rd/effects_rd.cpp
  19. 0 24
      servers/rendering/renderer_rd/effects_rd.h
  20. 5 0
      servers/rendering/renderer_rd/environment/SCsub
  21. 569 175
      servers/rendering/renderer_rd/environment/gi.cpp
  22. 168 33
      servers/rendering/renderer_rd/environment/gi.h
  23. 175 29
      servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp
  24. 13 2
      servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h
  25. 9 3
      servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp
  26. 4 0
      servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h
  27. 2 1
      servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp
  28. 9 5
      servers/rendering/renderer_rd/renderer_compositor_rd.h
  29. 34 35
      servers/rendering/renderer_rd/renderer_scene_render_rd.cpp
  30. 11 10
      servers/rendering/renderer_rd/renderer_scene_render_rd.h
  31. 6 338
      servers/rendering/renderer_rd/renderer_storage_rd.cpp
  32. 1 85
      servers/rendering/renderer_rd/renderer_storage_rd.h
  33. 1 0
      servers/rendering/renderer_rd/shaders/SCsub
  34. 0 0
      servers/rendering/renderer_rd/shaders/effects/resolve.glsl
  35. 17 0
      servers/rendering/renderer_rd/shaders/environment/SCsub
  36. 33 11
      servers/rendering/renderer_rd/shaders/environment/gi.glsl
  37. 7 3
      servers/rendering/renderer_rd/shaders/environment/sdfgi_debug.glsl
  38. 42 6
      servers/rendering/renderer_rd/shaders/environment/sdfgi_debug_probes.glsl
  39. 0 0
      servers/rendering/renderer_rd/shaders/environment/sdfgi_direct_light.glsl
  40. 0 0
      servers/rendering/renderer_rd/shaders/environment/sdfgi_integrate.glsl
  41. 0 0
      servers/rendering/renderer_rd/shaders/environment/sdfgi_preprocess.glsl
  42. 0 0
      servers/rendering/renderer_rd/shaders/environment/voxel_gi.glsl
  43. 0 0
      servers/rendering/renderer_rd/shaders/environment/voxel_gi_debug.glsl
  44. 0 0
      servers/rendering/renderer_rd/shaders/environment/voxel_gi_sdf.glsl
  45. 13 0
      servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl
  46. 7 1
      servers/rendering/renderer_rd/shaders/scene_forward_clustered_inc.glsl
  47. 1 1
      servers/rendering/renderer_scene_cull.cpp
  48. 0 42
      servers/rendering/renderer_storage.h
  49. 1 0
      servers/rendering/rendering_server_default.cpp
  50. 2 2
      servers/rendering/rendering_server_default.h
  51. 1 0
      servers/rendering/rendering_server_globals.cpp
  52. 2 0
      servers/rendering/rendering_server_globals.h

+ 1 - 0
drivers/gles3/SCsub

@@ -7,3 +7,4 @@ env.add_source_files(env.drivers_sources, "*.cpp")
 SConscript("shaders/SCsub")
 SConscript("storage/SCsub")
 SConscript("effects/SCsub")
+SConscript("environment/SCsub")

+ 5 - 0
drivers/gles3/environment/SCsub

@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+
+Import("env")
+
+env.add_source_files(env.drivers_sources, "*.cpp")

+ 140 - 0
drivers/gles3/environment/gi.cpp

@@ -0,0 +1,140 @@
+/*************************************************************************/
+/*  gi.cpp                                                               */
+/*************************************************************************/
+/*                       This file is part of:                           */
+/*                           GODOT ENGINE                                */
+/*                      https://godotengine.org                          */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.                 */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).   */
+/*                                                                       */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the       */
+/* "Software"), to deal in the Software without restriction, including   */
+/* without limitation the rights to use, copy, modify, merge, publish,   */
+/* distribute, sublicense, and/or sell copies of the Software, and to    */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions:                                             */
+/*                                                                       */
+/* The above copyright notice and this permission notice shall be        */
+/* included in all copies or substantial portions of the Software.       */
+/*                                                                       */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
+/*************************************************************************/
+
+#ifdef GLES3_ENABLED
+
+#include "gi.h"
+
+using namespace GLES3;
+
+/* VOXEL GI API */
+
+RID GI::voxel_gi_allocate() {
+	return RID();
+}
+
+void GI::voxel_gi_free(RID p_rid) {
+}
+
+void GI::voxel_gi_initialize(RID p_rid) {
+}
+
+void GI::voxel_gi_allocate_data(RID p_voxel_gi, const Transform3D &p_to_cell_xform, const AABB &p_aabb, const Vector3i &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts) {
+}
+
+AABB GI::voxel_gi_get_bounds(RID p_voxel_gi) const {
+	return AABB();
+}
+
+Vector3i GI::voxel_gi_get_octree_size(RID p_voxel_gi) const {
+	return Vector3i();
+}
+
+Vector<uint8_t> GI::voxel_gi_get_octree_cells(RID p_voxel_gi) const {
+	return Vector<uint8_t>();
+}
+
+Vector<uint8_t> GI::voxel_gi_get_data_cells(RID p_voxel_gi) const {
+	return Vector<uint8_t>();
+}
+
+Vector<uint8_t> GI::voxel_gi_get_distance_field(RID p_voxel_gi) const {
+	return Vector<uint8_t>();
+}
+
+Vector<int> GI::voxel_gi_get_level_counts(RID p_voxel_gi) const {
+	return Vector<int>();
+}
+
+Transform3D GI::voxel_gi_get_to_cell_xform(RID p_voxel_gi) const {
+	return Transform3D();
+}
+
+void GI::voxel_gi_set_dynamic_range(RID p_voxel_gi, float p_range) {
+}
+
+float GI::voxel_gi_get_dynamic_range(RID p_voxel_gi) const {
+	return 0;
+}
+
+void GI::voxel_gi_set_propagation(RID p_voxel_gi, float p_range) {
+}
+
+float GI::voxel_gi_get_propagation(RID p_voxel_gi) const {
+	return 0;
+}
+
+void GI::voxel_gi_set_energy(RID p_voxel_gi, float p_range) {
+}
+
+float GI::voxel_gi_get_energy(RID p_voxel_gi) const {
+	return 0.0;
+}
+
+void GI::voxel_gi_set_bias(RID p_voxel_gi, float p_range) {
+}
+
+float GI::voxel_gi_get_bias(RID p_voxel_gi) const {
+	return 0.0;
+}
+
+void GI::voxel_gi_set_normal_bias(RID p_voxel_gi, float p_range) {
+}
+
+float GI::voxel_gi_get_normal_bias(RID p_voxel_gi) const {
+	return 0.0;
+}
+
+void GI::voxel_gi_set_interior(RID p_voxel_gi, bool p_enable) {
+}
+
+bool GI::voxel_gi_is_interior(RID p_voxel_gi) const {
+	return false;
+}
+
+void GI::voxel_gi_set_use_two_bounces(RID p_voxel_gi, bool p_enable) {
+}
+
+bool GI::voxel_gi_is_using_two_bounces(RID p_voxel_gi) const {
+	return false;
+}
+
+void GI::voxel_gi_set_anisotropy_strength(RID p_voxel_gi, float p_strength) {
+}
+
+float GI::voxel_gi_get_anisotropy_strength(RID p_voxel_gi) const {
+	return 0;
+}
+
+uint32_t GI::voxel_gi_get_version(RID p_voxel_gi) const {
+	return 0;
+}
+
+#endif // GLES3_ENABLED

+ 99 - 0
drivers/gles3/environment/gi.h

@@ -0,0 +1,99 @@
+/*************************************************************************/
+/*  gi.h                                                                 */
+/*************************************************************************/
+/*                       This file is part of:                           */
+/*                           GODOT ENGINE                                */
+/*                      https://godotengine.org                          */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.                 */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).   */
+/*                                                                       */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the       */
+/* "Software"), to deal in the Software without restriction, including   */
+/* without limitation the rights to use, copy, modify, merge, publish,   */
+/* distribute, sublicense, and/or sell copies of the Software, and to    */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions:                                             */
+/*                                                                       */
+/* The above copyright notice and this permission notice shall be        */
+/* included in all copies or substantial portions of the Software.       */
+/*                                                                       */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
+/*************************************************************************/
+
+#ifndef GI_GLES3_H
+#define GI_GLES3_H
+
+#ifdef GLES3_ENABLED
+
+#include "core/templates/local_vector.h"
+#include "core/templates/rid_owner.h"
+#include "core/templates/self_list.h"
+#include "servers/rendering/environment/renderer_gi.h"
+
+#include "platform_config.h"
+#ifndef OPENGL_INCLUDE_H
+#include <GLES3/gl3.h>
+#else
+#include OPENGL_INCLUDE_H
+#endif
+
+namespace GLES3 {
+
+class GI : public RendererGI {
+public:
+	/* VOXEL GI API */
+
+	virtual RID voxel_gi_allocate() override;
+	virtual void voxel_gi_free(RID p_rid) override;
+	virtual void voxel_gi_initialize(RID p_rid) override;
+	virtual void voxel_gi_allocate_data(RID p_voxel_gi, const Transform3D &p_to_cell_xform, const AABB &p_aabb, const Vector3i &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts) override;
+
+	virtual AABB voxel_gi_get_bounds(RID p_voxel_gi) const override;
+	virtual Vector3i voxel_gi_get_octree_size(RID p_voxel_gi) const override;
+	virtual Vector<uint8_t> voxel_gi_get_octree_cells(RID p_voxel_gi) const override;
+	virtual Vector<uint8_t> voxel_gi_get_data_cells(RID p_voxel_gi) const override;
+	virtual Vector<uint8_t> voxel_gi_get_distance_field(RID p_voxel_gi) const override;
+
+	virtual Vector<int> voxel_gi_get_level_counts(RID p_voxel_gi) const override;
+	virtual Transform3D voxel_gi_get_to_cell_xform(RID p_voxel_gi) const override;
+
+	virtual void voxel_gi_set_dynamic_range(RID p_voxel_gi, float p_range) override;
+	virtual float voxel_gi_get_dynamic_range(RID p_voxel_gi) const override;
+
+	virtual void voxel_gi_set_propagation(RID p_voxel_gi, float p_range) override;
+	virtual float voxel_gi_get_propagation(RID p_voxel_gi) const override;
+
+	virtual void voxel_gi_set_energy(RID p_voxel_gi, float p_range) override;
+	virtual float voxel_gi_get_energy(RID p_voxel_gi) const override;
+
+	virtual void voxel_gi_set_bias(RID p_voxel_gi, float p_range) override;
+	virtual float voxel_gi_get_bias(RID p_voxel_gi) const override;
+
+	virtual void voxel_gi_set_normal_bias(RID p_voxel_gi, float p_range) override;
+	virtual float voxel_gi_get_normal_bias(RID p_voxel_gi) const override;
+
+	virtual void voxel_gi_set_interior(RID p_voxel_gi, bool p_enable) override;
+	virtual bool voxel_gi_is_interior(RID p_voxel_gi) const override;
+
+	virtual void voxel_gi_set_use_two_bounces(RID p_voxel_gi, bool p_enable) override;
+	virtual bool voxel_gi_is_using_two_bounces(RID p_voxel_gi) const override;
+
+	virtual void voxel_gi_set_anisotropy_strength(RID p_voxel_gi, float p_strength) override;
+	virtual float voxel_gi_get_anisotropy_strength(RID p_voxel_gi) const override;
+
+	virtual uint32_t voxel_gi_get_version(RID p_voxel_gi) const override;
+};
+
+}; // namespace GLES3
+
+#endif // GLES3_ENABLED
+
+#endif // !GI_GLES3_H

+ 3 - 0
drivers/gles3/rasterizer_gles3.cpp

@@ -198,6 +198,8 @@ void RasterizerGLES3::finalize() {
 	memdelete(scene);
 	memdelete(canvas);
 	memdelete(storage);
+	memdelete(gi);
+	memdelete(copy_effects);
 	memdelete(light_storage);
 	memdelete(particles_storage);
 	memdelete(mesh_storage);
@@ -269,6 +271,7 @@ RasterizerGLES3::RasterizerGLES3() {
 	particles_storage = memnew(GLES3::ParticlesStorage);
 	light_storage = memnew(GLES3::LightStorage);
 	copy_effects = memnew(GLES3::CopyEffects);
+	gi = memnew(GLES3::GI);
 	storage = memnew(RasterizerStorageGLES3);
 	canvas = memnew(RasterizerCanvasGLES3(storage));
 	scene = memnew(RasterizerSceneGLES3(storage));

+ 3 - 0
drivers/gles3/rasterizer_gles3.h

@@ -34,6 +34,7 @@
 #ifdef GLES3_ENABLED
 
 #include "effects/copy_effects.h"
+#include "environment/gi.h"
 #include "rasterizer_canvas_gles3.h"
 #include "rasterizer_scene_gles3.h"
 #include "rasterizer_storage_gles3.h"
@@ -59,6 +60,7 @@ protected:
 	GLES3::MeshStorage *mesh_storage = nullptr;
 	GLES3::ParticlesStorage *particles_storage = nullptr;
 	GLES3::LightStorage *light_storage = nullptr;
+	GLES3::GI *gi = nullptr;
 	GLES3::CopyEffects *copy_effects = nullptr;
 	RasterizerStorageGLES3 *storage = nullptr;
 	RasterizerCanvasGLES3 *canvas = nullptr;
@@ -72,6 +74,7 @@ public:
 	RendererMeshStorage *get_mesh_storage() { return mesh_storage; }
 	RendererParticlesStorage *get_particles_storage() { return particles_storage; }
 	RendererTextureStorage *get_texture_storage() { return texture_storage; }
+	RendererGI *get_gi() { return gi; }
 	RendererStorage *get_storage() { return storage; }
 	RendererCanvasRender *get_canvas() { return canvas; }
 	RendererSceneRender *get_scene() { return scene; }

+ 0 - 100
drivers/gles3/rasterizer_storage_gles3.cpp

@@ -79,106 +79,6 @@ Vector<uint8_t> RasterizerStorageGLES3::buffer_get_data(GLenum p_target, GLuint
 	return ret;
 }
 
-/* VOXEL GI API */
-
-RID RasterizerStorageGLES3::voxel_gi_allocate() {
-	return RID();
-}
-
-void RasterizerStorageGLES3::voxel_gi_initialize(RID p_rid) {
-}
-
-void RasterizerStorageGLES3::voxel_gi_allocate_data(RID p_voxel_gi, const Transform3D &p_to_cell_xform, const AABB &p_aabb, const Vector3i &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts) {
-}
-
-AABB RasterizerStorageGLES3::voxel_gi_get_bounds(RID p_voxel_gi) const {
-	return AABB();
-}
-
-Vector3i RasterizerStorageGLES3::voxel_gi_get_octree_size(RID p_voxel_gi) const {
-	return Vector3i();
-}
-
-Vector<uint8_t> RasterizerStorageGLES3::voxel_gi_get_octree_cells(RID p_voxel_gi) const {
-	return Vector<uint8_t>();
-}
-
-Vector<uint8_t> RasterizerStorageGLES3::voxel_gi_get_data_cells(RID p_voxel_gi) const {
-	return Vector<uint8_t>();
-}
-
-Vector<uint8_t> RasterizerStorageGLES3::voxel_gi_get_distance_field(RID p_voxel_gi) const {
-	return Vector<uint8_t>();
-}
-
-Vector<int> RasterizerStorageGLES3::voxel_gi_get_level_counts(RID p_voxel_gi) const {
-	return Vector<int>();
-}
-
-Transform3D RasterizerStorageGLES3::voxel_gi_get_to_cell_xform(RID p_voxel_gi) const {
-	return Transform3D();
-}
-
-void RasterizerStorageGLES3::voxel_gi_set_dynamic_range(RID p_voxel_gi, float p_range) {
-}
-
-float RasterizerStorageGLES3::voxel_gi_get_dynamic_range(RID p_voxel_gi) const {
-	return 0;
-}
-
-void RasterizerStorageGLES3::voxel_gi_set_propagation(RID p_voxel_gi, float p_range) {
-}
-
-float RasterizerStorageGLES3::voxel_gi_get_propagation(RID p_voxel_gi) const {
-	return 0;
-}
-
-void RasterizerStorageGLES3::voxel_gi_set_energy(RID p_voxel_gi, float p_range) {
-}
-
-float RasterizerStorageGLES3::voxel_gi_get_energy(RID p_voxel_gi) const {
-	return 0.0;
-}
-
-void RasterizerStorageGLES3::voxel_gi_set_bias(RID p_voxel_gi, float p_range) {
-}
-
-float RasterizerStorageGLES3::voxel_gi_get_bias(RID p_voxel_gi) const {
-	return 0.0;
-}
-
-void RasterizerStorageGLES3::voxel_gi_set_normal_bias(RID p_voxel_gi, float p_range) {
-}
-
-float RasterizerStorageGLES3::voxel_gi_get_normal_bias(RID p_voxel_gi) const {
-	return 0.0;
-}
-
-void RasterizerStorageGLES3::voxel_gi_set_interior(RID p_voxel_gi, bool p_enable) {
-}
-
-bool RasterizerStorageGLES3::voxel_gi_is_interior(RID p_voxel_gi) const {
-	return false;
-}
-
-void RasterizerStorageGLES3::voxel_gi_set_use_two_bounces(RID p_voxel_gi, bool p_enable) {
-}
-
-bool RasterizerStorageGLES3::voxel_gi_is_using_two_bounces(RID p_voxel_gi) const {
-	return false;
-}
-
-void RasterizerStorageGLES3::voxel_gi_set_anisotropy_strength(RID p_voxel_gi, float p_strength) {
-}
-
-float RasterizerStorageGLES3::voxel_gi_get_anisotropy_strength(RID p_voxel_gi) const {
-	return 0;
-}
-
-uint32_t RasterizerStorageGLES3::voxel_gi_get_version(RID p_voxel_gi) {
-	return 0;
-}
-
 /* OCCLUDER */
 
 void RasterizerStorageGLES3::occluder_set_mesh(RID p_occluder, const PackedVector3Array &p_vertices, const PackedInt32Array &p_indices) {

+ 0 - 41
drivers/gles3/rasterizer_storage_gles3.h

@@ -154,47 +154,6 @@ public:
 public:
 	virtual void base_update_dependency(RID p_base, DependencyTracker *p_instance) override;
 
-	/* VOXEL GI API */
-
-	RID voxel_gi_allocate() override;
-	void voxel_gi_initialize(RID p_rid) override;
-	void voxel_gi_allocate_data(RID p_voxel_gi, const Transform3D &p_to_cell_xform, const AABB &p_aabb, const Vector3i &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts) override;
-
-	AABB voxel_gi_get_bounds(RID p_voxel_gi) const override;
-	Vector3i voxel_gi_get_octree_size(RID p_voxel_gi) const override;
-	Vector<uint8_t> voxel_gi_get_octree_cells(RID p_voxel_gi) const override;
-	Vector<uint8_t> voxel_gi_get_data_cells(RID p_voxel_gi) const override;
-	Vector<uint8_t> voxel_gi_get_distance_field(RID p_voxel_gi) const override;
-
-	Vector<int> voxel_gi_get_level_counts(RID p_voxel_gi) const override;
-	Transform3D voxel_gi_get_to_cell_xform(RID p_voxel_gi) const override;
-
-	void voxel_gi_set_dynamic_range(RID p_voxel_gi, float p_range) override;
-	float voxel_gi_get_dynamic_range(RID p_voxel_gi) const override;
-
-	void voxel_gi_set_propagation(RID p_voxel_gi, float p_range) override;
-	float voxel_gi_get_propagation(RID p_voxel_gi) const override;
-
-	void voxel_gi_set_energy(RID p_voxel_gi, float p_range) override;
-	float voxel_gi_get_energy(RID p_voxel_gi) const override;
-
-	void voxel_gi_set_bias(RID p_voxel_gi, float p_range) override;
-	float voxel_gi_get_bias(RID p_voxel_gi) const override;
-
-	void voxel_gi_set_normal_bias(RID p_voxel_gi, float p_range) override;
-	float voxel_gi_get_normal_bias(RID p_voxel_gi) const override;
-
-	void voxel_gi_set_interior(RID p_voxel_gi, bool p_enable) override;
-	bool voxel_gi_is_interior(RID p_voxel_gi) const override;
-
-	void voxel_gi_set_use_two_bounces(RID p_voxel_gi, bool p_enable) override;
-	bool voxel_gi_is_using_two_bounces(RID p_voxel_gi) const override;
-
-	void voxel_gi_set_anisotropy_strength(RID p_voxel_gi, float p_strength) override;
-	float voxel_gi_get_anisotropy_strength(RID p_voxel_gi) const override;
-
-	uint32_t voxel_gi_get_version(RID p_voxel_gi) override;
-
 	/* OCCLUDER */
 
 	void occluder_set_mesh(RID p_occluder, const PackedVector3Array &p_vertices, const PackedInt32Array &p_indices);

+ 6 - 0
drivers/vulkan/rendering_device_vulkan.cpp

@@ -2314,6 +2314,12 @@ RID RenderingDeviceVulkan::texture_create_shared_from_slice(const TextureView &p
 		image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY;
 	}
 
+	if (p_slice_type == TEXTURE_SLICE_2D) {
+		texture.type = TEXTURE_TYPE_2D;
+	} else if (p_slice_type == TEXTURE_SLICE_3D) {
+		texture.type = TEXTURE_TYPE_3D;
+	}
+
 	if (p_view.format_override == DATA_FORMAT_MAX || p_view.format_override == texture.format) {
 		image_view_create_info.format = vulkan_formats[texture.format];
 	} else {

+ 85 - 0
servers/rendering/dummy/environment/gi.h

@@ -0,0 +1,85 @@
+/*************************************************************************/
+/*  gi.h                                                                 */
+/*************************************************************************/
+/*                       This file is part of:                           */
+/*                           GODOT ENGINE                                */
+/*                      https://godotengine.org                          */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.                 */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).   */
+/*                                                                       */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the       */
+/* "Software"), to deal in the Software without restriction, including   */
+/* without limitation the rights to use, copy, modify, merge, publish,   */
+/* distribute, sublicense, and/or sell copies of the Software, and to    */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions:                                             */
+/*                                                                       */
+/* The above copyright notice and this permission notice shall be        */
+/* included in all copies or substantial portions of the Software.       */
+/*                                                                       */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
+/*************************************************************************/
+
+#ifndef GI_DUMMY_H
+#define GI_DUMMY_H
+
+#include "servers/rendering/environment/renderer_gi.h"
+
+namespace RendererDummy {
+
+class GI : public RendererGI {
+public:
+	/* VOXEL GI API */
+
+	virtual RID voxel_gi_allocate() override { return RID(); }
+	virtual void voxel_gi_free(RID p_rid) override {}
+	virtual void voxel_gi_initialize(RID p_rid) override {}
+	virtual void voxel_gi_allocate_data(RID p_voxel_gi, const Transform3D &p_to_cell_xform, const AABB &p_aabb, const Vector3i &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts) override {}
+
+	virtual AABB voxel_gi_get_bounds(RID p_voxel_gi) const override { return AABB(); }
+	virtual Vector3i voxel_gi_get_octree_size(RID p_voxel_gi) const override { return Vector3i(); }
+	virtual Vector<uint8_t> voxel_gi_get_octree_cells(RID p_voxel_gi) const override { return Vector<uint8_t>(); }
+	virtual Vector<uint8_t> voxel_gi_get_data_cells(RID p_voxel_gi) const override { return Vector<uint8_t>(); }
+	virtual Vector<uint8_t> voxel_gi_get_distance_field(RID p_voxel_gi) const override { return Vector<uint8_t>(); }
+
+	virtual Vector<int> voxel_gi_get_level_counts(RID p_voxel_gi) const override { return Vector<int>(); }
+	virtual Transform3D voxel_gi_get_to_cell_xform(RID p_voxel_gi) const override { return Transform3D(); }
+
+	virtual void voxel_gi_set_dynamic_range(RID p_voxel_gi, float p_range) override {}
+	virtual float voxel_gi_get_dynamic_range(RID p_voxel_gi) const override { return 0; }
+
+	virtual void voxel_gi_set_propagation(RID p_voxel_gi, float p_range) override {}
+	virtual float voxel_gi_get_propagation(RID p_voxel_gi) const override { return 0; }
+
+	virtual void voxel_gi_set_energy(RID p_voxel_gi, float p_range) override {}
+	virtual float voxel_gi_get_energy(RID p_voxel_gi) const override { return 0.0; }
+
+	virtual void voxel_gi_set_bias(RID p_voxel_gi, float p_range) override {}
+	virtual float voxel_gi_get_bias(RID p_voxel_gi) const override { return 0.0; }
+
+	virtual void voxel_gi_set_normal_bias(RID p_voxel_gi, float p_range) override {}
+	virtual float voxel_gi_get_normal_bias(RID p_voxel_gi) const override { return 0.0; }
+
+	virtual void voxel_gi_set_interior(RID p_voxel_gi, bool p_enable) override {}
+	virtual bool voxel_gi_is_interior(RID p_voxel_gi) const override { return false; }
+
+	virtual void voxel_gi_set_use_two_bounces(RID p_voxel_gi, bool p_enable) override {}
+	virtual bool voxel_gi_is_using_two_bounces(RID p_voxel_gi) const override { return false; }
+
+	virtual void voxel_gi_set_anisotropy_strength(RID p_voxel_gi, float p_strength) override {}
+	virtual float voxel_gi_get_anisotropy_strength(RID p_voxel_gi) const override { return 0; }
+
+	virtual uint32_t voxel_gi_get_version(RID p_voxel_gi) const override { return 0; }
+};
+
+} // namespace RendererDummy
+
+#endif // !GI_DUMMY_H

+ 3 - 0
servers/rendering/dummy/rasterizer_dummy.h

@@ -34,6 +34,7 @@
 #include "core/templates/rid_owner.h"
 #include "core/templates/self_list.h"
 #include "scene/resources/mesh.h"
+#include "servers/rendering/dummy/environment/gi.h"
 #include "servers/rendering/dummy/rasterizer_canvas_dummy.h"
 #include "servers/rendering/dummy/rasterizer_scene_dummy.h"
 #include "servers/rendering/dummy/rasterizer_storage_dummy.h"
@@ -57,6 +58,7 @@ protected:
 	RendererDummy::MeshStorage mesh_storage;
 	RendererDummy::ParticlesStorage particles_storage;
 	RendererDummy::TextureStorage texture_storage;
+	RendererDummy::GI gi;
 	RasterizerStorageDummy storage;
 	RasterizerSceneDummy scene;
 
@@ -66,6 +68,7 @@ public:
 	RendererMeshStorage *get_mesh_storage() override { return &mesh_storage; };
 	RendererParticlesStorage *get_particles_storage() override { return &particles_storage; };
 	RendererTextureStorage *get_texture_storage() override { return &texture_storage; };
+	RendererGI *get_gi() override { return &gi; };
 	RendererStorage *get_storage() override { return &storage; }
 	RendererCanvasRender *get_canvas() override { return &canvas; }
 	RendererSceneRender *get_scene() override { return &scene; }

+ 0 - 41
servers/rendering/dummy/rasterizer_storage_dummy.h

@@ -38,47 +38,6 @@ class RasterizerStorageDummy : public RendererStorage {
 public:
 	void base_update_dependency(RID p_base, DependencyTracker *p_instance) override {}
 
-	/* VOXEL GI API */
-
-	RID voxel_gi_allocate() override { return RID(); }
-	void voxel_gi_initialize(RID p_rid) override {}
-	void voxel_gi_allocate_data(RID p_voxel_gi, const Transform3D &p_to_cell_xform, const AABB &p_aabb, const Vector3i &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts) override {}
-
-	AABB voxel_gi_get_bounds(RID p_voxel_gi) const override { return AABB(); }
-	Vector3i voxel_gi_get_octree_size(RID p_voxel_gi) const override { return Vector3i(); }
-	Vector<uint8_t> voxel_gi_get_octree_cells(RID p_voxel_gi) const override { return Vector<uint8_t>(); }
-	Vector<uint8_t> voxel_gi_get_data_cells(RID p_voxel_gi) const override { return Vector<uint8_t>(); }
-	Vector<uint8_t> voxel_gi_get_distance_field(RID p_voxel_gi) const override { return Vector<uint8_t>(); }
-
-	Vector<int> voxel_gi_get_level_counts(RID p_voxel_gi) const override { return Vector<int>(); }
-	Transform3D voxel_gi_get_to_cell_xform(RID p_voxel_gi) const override { return Transform3D(); }
-
-	void voxel_gi_set_dynamic_range(RID p_voxel_gi, float p_range) override {}
-	float voxel_gi_get_dynamic_range(RID p_voxel_gi) const override { return 0; }
-
-	void voxel_gi_set_propagation(RID p_voxel_gi, float p_range) override {}
-	float voxel_gi_get_propagation(RID p_voxel_gi) const override { return 0; }
-
-	void voxel_gi_set_energy(RID p_voxel_gi, float p_range) override {}
-	float voxel_gi_get_energy(RID p_voxel_gi) const override { return 0.0; }
-
-	void voxel_gi_set_bias(RID p_voxel_gi, float p_range) override {}
-	float voxel_gi_get_bias(RID p_voxel_gi) const override { return 0.0; }
-
-	void voxel_gi_set_normal_bias(RID p_voxel_gi, float p_range) override {}
-	float voxel_gi_get_normal_bias(RID p_voxel_gi) const override { return 0.0; }
-
-	void voxel_gi_set_interior(RID p_voxel_gi, bool p_enable) override {}
-	bool voxel_gi_is_interior(RID p_voxel_gi) const override { return false; }
-
-	void voxel_gi_set_use_two_bounces(RID p_voxel_gi, bool p_enable) override {}
-	bool voxel_gi_is_using_two_bounces(RID p_voxel_gi) const override { return false; }
-
-	void voxel_gi_set_anisotropy_strength(RID p_voxel_gi, float p_strength) override {}
-	float voxel_gi_get_anisotropy_strength(RID p_voxel_gi) const override { return 0; }
-
-	uint32_t voxel_gi_get_version(RID p_voxel_gi) override { return 0; }
-
 	/* OCCLUDER */
 
 	void occluder_set_mesh(RID p_occluder, const PackedVector3Array &p_vertices, const PackedInt32Array &p_indices) {}

+ 85 - 0
servers/rendering/environment/renderer_gi.h

@@ -0,0 +1,85 @@
+/*************************************************************************/
+/*  renderer_gi.h                                                        */
+/*************************************************************************/
+/*                       This file is part of:                           */
+/*                           GODOT ENGINE                                */
+/*                      https://godotengine.org                          */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.                 */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).   */
+/*                                                                       */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the       */
+/* "Software"), to deal in the Software without restriction, including   */
+/* without limitation the rights to use, copy, modify, merge, publish,   */
+/* distribute, sublicense, and/or sell copies of the Software, and to    */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions:                                             */
+/*                                                                       */
+/* The above copyright notice and this permission notice shall be        */
+/* included in all copies or substantial portions of the Software.       */
+/*                                                                       */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
+/*************************************************************************/
+
+#ifndef RENDERER_GI_H
+#define RENDERER_GI_H
+
+#include "servers/rendering/renderer_storage.h"
+#include "servers/rendering_server.h"
+
+class RendererGI {
+public:
+	virtual ~RendererGI() {}
+
+	/* VOXEL GI API */
+
+	virtual RID voxel_gi_allocate() = 0;
+	virtual void voxel_gi_free(RID p_rid) = 0;
+	virtual void voxel_gi_initialize(RID p_rid) = 0;
+
+	virtual void voxel_gi_allocate_data(RID p_voxel_gi, const Transform3D &p_to_cell_xform, const AABB &p_aabb, const Vector3i &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts) = 0;
+
+	virtual AABB voxel_gi_get_bounds(RID p_voxel_gi) const = 0;
+	virtual Vector3i voxel_gi_get_octree_size(RID p_voxel_gi) const = 0;
+	virtual Vector<uint8_t> voxel_gi_get_octree_cells(RID p_voxel_gi) const = 0;
+	virtual Vector<uint8_t> voxel_gi_get_data_cells(RID p_voxel_gi) const = 0;
+	virtual Vector<uint8_t> voxel_gi_get_distance_field(RID p_voxel_gi) const = 0;
+
+	virtual Vector<int> voxel_gi_get_level_counts(RID p_voxel_gi) const = 0;
+	virtual Transform3D voxel_gi_get_to_cell_xform(RID p_voxel_gi) const = 0;
+
+	virtual void voxel_gi_set_dynamic_range(RID p_voxel_gi, float p_range) = 0;
+	virtual float voxel_gi_get_dynamic_range(RID p_voxel_gi) const = 0;
+
+	virtual void voxel_gi_set_propagation(RID p_voxel_gi, float p_range) = 0;
+	virtual float voxel_gi_get_propagation(RID p_voxel_gi) const = 0;
+
+	virtual void voxel_gi_set_energy(RID p_voxel_gi, float p_energy) = 0;
+	virtual float voxel_gi_get_energy(RID p_voxel_gi) const = 0;
+
+	virtual void voxel_gi_set_bias(RID p_voxel_gi, float p_bias) = 0;
+	virtual float voxel_gi_get_bias(RID p_voxel_gi) const = 0;
+
+	virtual void voxel_gi_set_normal_bias(RID p_voxel_gi, float p_range) = 0;
+	virtual float voxel_gi_get_normal_bias(RID p_voxel_gi) const = 0;
+
+	virtual void voxel_gi_set_interior(RID p_voxel_gi, bool p_enable) = 0;
+	virtual bool voxel_gi_is_interior(RID p_voxel_gi) const = 0;
+
+	virtual void voxel_gi_set_use_two_bounces(RID p_voxel_gi, bool p_enable) = 0;
+	virtual bool voxel_gi_is_using_two_bounces(RID p_voxel_gi) const = 0;
+
+	virtual void voxel_gi_set_anisotropy_strength(RID p_voxel_gi, float p_strength) = 0;
+	virtual float voxel_gi_get_anisotropy_strength(RID p_voxel_gi) const = 0;
+
+	virtual uint32_t voxel_gi_get_version(RID p_probe) const = 0;
+};
+
+#endif // !RENDERER_GI_H

+ 2 - 0
servers/rendering/renderer_compositor.h

@@ -31,6 +31,7 @@
 #ifndef RENDERING_SERVER_COMPOSITOR_H
 #define RENDERING_SERVER_COMPOSITOR_H
 
+#include "servers/rendering/environment/renderer_gi.h"
 #include "servers/rendering/renderer_canvas_render.h"
 #include "servers/rendering/renderer_scene.h"
 #include "servers/rendering/renderer_storage.h"
@@ -81,6 +82,7 @@ public:
 	virtual RendererMeshStorage *get_mesh_storage() = 0;
 	virtual RendererParticlesStorage *get_particles_storage() = 0;
 	virtual RendererTextureStorage *get_texture_storage() = 0;
+	virtual RendererGI *get_gi() = 0;
 	virtual RendererStorage *get_storage() = 0;
 	virtual RendererCanvasRender *get_canvas() = 0;
 	virtual RendererSceneRender *get_scene() = 0;

+ 1 - 0
servers/rendering/renderer_rd/SCsub

@@ -5,6 +5,7 @@ Import("env")
 env.add_source_files(env.servers_sources, "*.cpp")
 
 SConscript("effects/SCsub")
+SConscript("environment/SCsub")
 SConscript("forward_clustered/SCsub")
 SConscript("forward_mobile/SCsub")
 SConscript("shaders/SCsub")

+ 130 - 0
servers/rendering/renderer_rd/effects/resolve.cpp

@@ -0,0 +1,130 @@
+/*************************************************************************/
+/*  resolve.cpp                                                          */
+/*************************************************************************/
+/*                       This file is part of:                           */
+/*                           GODOT ENGINE                                */
+/*                      https://godotengine.org                          */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.                 */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).   */
+/*                                                                       */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the       */
+/* "Software"), to deal in the Software without restriction, including   */
+/* without limitation the rights to use, copy, modify, merge, publish,   */
+/* distribute, sublicense, and/or sell copies of the Software, and to    */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions:                                             */
+/*                                                                       */
+/* The above copyright notice and this permission notice shall be        */
+/* included in all copies or substantial portions of the Software.       */
+/*                                                                       */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
+/*************************************************************************/
+
+#include "resolve.h"
+#include "servers/rendering/renderer_rd/renderer_compositor_rd.h"
+#include "servers/rendering/renderer_rd/storage_rd/material_storage.h"
+#include "servers/rendering/renderer_rd/uniform_set_cache_rd.h"
+
+using namespace RendererRD;
+
+Resolve::Resolve() {
+	Vector<String> resolve_modes;
+	resolve_modes.push_back("\n#define MODE_RESOLVE_GI\n");
+	resolve_modes.push_back("\n#define MODE_RESOLVE_GI\n#define VOXEL_GI_RESOLVE\n");
+	resolve_modes.push_back("\n#define MODE_RESOLVE_DEPTH\n");
+
+	resolve.shader.initialize(resolve_modes);
+
+	resolve.shader_version = resolve.shader.version_create();
+
+	for (int i = 0; i < RESOLVE_MODE_MAX; i++) {
+		resolve.pipelines[i] = RD::get_singleton()->compute_pipeline_create(resolve.shader.version_get_shader(resolve.shader_version, i));
+	}
+}
+
+Resolve::~Resolve() {
+	resolve.shader.version_free(resolve.shader_version);
+}
+
+void Resolve::resolve_gi(RID p_source_depth, RID p_source_normal_roughness, RID p_source_voxel_gi, RID p_dest_depth, RID p_dest_normal_roughness, RID p_dest_voxel_gi, Vector2i p_screen_size, int p_samples, uint32_t p_barrier) {
+	UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
+	ERR_FAIL_NULL(uniform_set_cache);
+	MaterialStorage *material_storage = MaterialStorage::get_singleton();
+	ERR_FAIL_NULL(material_storage);
+
+	ResolvePushConstant push_constant;
+	push_constant.screen_size[0] = p_screen_size.x;
+	push_constant.screen_size[1] = p_screen_size.y;
+	push_constant.samples = p_samples;
+
+	// setup our uniforms
+	RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
+
+	RD::Uniform u_source_depth(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_depth }));
+	RD::Uniform u_source_normal_roughness(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 1, Vector<RID>({ default_sampler, p_source_normal_roughness }));
+	RD::Uniform u_dest_depth(RD::UNIFORM_TYPE_IMAGE, 0, Vector<RID>({ p_dest_depth }));
+	RD::Uniform u_dest_normal_roughness(RD::UNIFORM_TYPE_IMAGE, 1, Vector<RID>({ p_dest_normal_roughness }));
+
+	ResolveMode mode = p_source_voxel_gi.is_valid() ? RESOLVE_MODE_GI_VOXEL_GI : RESOLVE_MODE_GI;
+	RID shader = resolve.shader.version_get_shader(resolve.shader_version, mode);
+	ERR_FAIL_COND(shader.is_null());
+
+	RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
+	RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, resolve.pipelines[mode]);
+	RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 0, u_source_depth, u_source_normal_roughness), 0);
+	RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 1, u_dest_depth, u_dest_normal_roughness), 1);
+	if (p_source_voxel_gi.is_valid()) {
+		RD::Uniform u_source_voxel_gi(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_voxel_gi }));
+		RD::Uniform u_dest_voxel_gi(RD::UNIFORM_TYPE_IMAGE, 0, p_dest_voxel_gi);
+
+		RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 2, u_source_voxel_gi), 2);
+		RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 3, u_dest_voxel_gi), 3);
+	}
+
+	RD::get_singleton()->compute_list_set_push_constant(compute_list, &push_constant, sizeof(ResolvePushConstant));
+
+	RD::get_singleton()->compute_list_dispatch_threads(compute_list, p_screen_size.x, p_screen_size.y, 1);
+
+	RD::get_singleton()->compute_list_end(p_barrier);
+}
+
+void Resolve::resolve_depth(RID p_source_depth, RID p_dest_depth, Vector2i p_screen_size, int p_samples, uint32_t p_barrier) {
+	UniformSetCacheRD *uniform_set_cache = UniformSetCacheRD::get_singleton();
+	ERR_FAIL_NULL(uniform_set_cache);
+	MaterialStorage *material_storage = MaterialStorage::get_singleton();
+	ERR_FAIL_NULL(material_storage);
+
+	ResolvePushConstant push_constant;
+	push_constant.screen_size[0] = p_screen_size.x;
+	push_constant.screen_size[1] = p_screen_size.y;
+	push_constant.samples = p_samples;
+
+	// setup our uniforms
+	RID default_sampler = material_storage->sampler_rd_get_default(RS::CANVAS_ITEM_TEXTURE_FILTER_LINEAR, RS::CANVAS_ITEM_TEXTURE_REPEAT_DISABLED);
+
+	RD::Uniform u_source_depth(RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE, 0, Vector<RID>({ default_sampler, p_source_depth }));
+	RD::Uniform u_dest_depth(RD::UNIFORM_TYPE_IMAGE, 0, p_dest_depth);
+
+	ResolveMode mode = RESOLVE_MODE_DEPTH;
+	RID shader = resolve.shader.version_get_shader(resolve.shader_version, mode);
+	ERR_FAIL_COND(shader.is_null());
+
+	RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
+	RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, resolve.pipelines[mode]);
+	RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 0, u_source_depth), 0);
+	RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set_cache->get_cache(shader, 1, u_dest_depth), 1);
+
+	RD::get_singleton()->compute_list_set_push_constant(compute_list, &push_constant, sizeof(ResolvePushConstant));
+
+	RD::get_singleton()->compute_list_dispatch_threads(compute_list, p_screen_size.x, p_screen_size.y, 1);
+
+	RD::get_singleton()->compute_list_end(p_barrier);
+}

+ 74 - 0
servers/rendering/renderer_rd/effects/resolve.h

@@ -0,0 +1,74 @@
+/*************************************************************************/
+/*  resolve.h                                                            */
+/*************************************************************************/
+/*                       This file is part of:                           */
+/*                           GODOT ENGINE                                */
+/*                      https://godotengine.org                          */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.                 */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).   */
+/*                                                                       */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the       */
+/* "Software"), to deal in the Software without restriction, including   */
+/* without limitation the rights to use, copy, modify, merge, publish,   */
+/* distribute, sublicense, and/or sell copies of the Software, and to    */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions:                                             */
+/*                                                                       */
+/* The above copyright notice and this permission notice shall be        */
+/* included in all copies or substantial portions of the Software.       */
+/*                                                                       */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
+/*************************************************************************/
+
+#ifndef RESOLVE_RD_H
+#define RESOLVE_RD_H
+
+#include "servers/rendering/renderer_rd/pipeline_cache_rd.h"
+#include "servers/rendering/renderer_rd/shaders/effects/resolve.glsl.gen.h"
+#include "servers/rendering/renderer_scene_render.h"
+
+#include "servers/rendering_server.h"
+
+namespace RendererRD {
+
+class Resolve {
+private:
+	struct ResolvePushConstant {
+		int32_t screen_size[2];
+		int32_t samples;
+		uint32_t pad;
+	};
+
+	enum ResolveMode {
+		RESOLVE_MODE_GI,
+		RESOLVE_MODE_GI_VOXEL_GI,
+		RESOLVE_MODE_DEPTH,
+		RESOLVE_MODE_MAX
+	};
+
+	struct ResolveShader {
+		ResolvePushConstant push_constant;
+		ResolveShaderRD shader;
+		RID shader_version;
+		RID pipelines[RESOLVE_MODE_MAX]; //3 quality levels
+	} resolve;
+
+public:
+	Resolve();
+	~Resolve();
+
+	void resolve_gi(RID p_source_depth, RID p_source_normal_roughness, RID p_source_voxel_gi, RID p_dest_depth, RID p_dest_normal_roughness, RID p_dest_voxel_gi, Vector2i p_screen_size, int p_samples, uint32_t p_barrier = RD::BARRIER_MASK_ALL);
+	void resolve_depth(RID p_source_depth, RID p_dest_depth, Vector2i p_screen_size, int p_samples, uint32_t p_barrier = RD::BARRIER_MASK_ALL);
+};
+
+} // namespace RendererRD
+
+#endif // !RESOLVE_RD_H

+ 0 - 56
servers/rendering/renderer_rd/effects_rd.cpp

@@ -1396,46 +1396,6 @@ void EffectsRD::cubemap_filter_raster(RID p_source_cubemap, RID p_dest_framebuff
 	RD::get_singleton()->draw_list_end();
 }
 
-void EffectsRD::resolve_gi(RID p_source_depth, RID p_source_normal_roughness, RID p_source_voxel_gi, RID p_dest_depth, RID p_dest_normal_roughness, RID p_dest_voxel_gi, Vector2i p_screen_size, int p_samples, uint32_t p_barrier) {
-	ResolvePushConstant push_constant;
-	push_constant.screen_size[0] = p_screen_size.x;
-	push_constant.screen_size[1] = p_screen_size.y;
-	push_constant.samples = p_samples;
-
-	RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
-	RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, resolve.pipelines[p_source_voxel_gi.is_valid() ? RESOLVE_MODE_GI_VOXEL_GI : RESOLVE_MODE_GI]);
-	RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture_pair(p_source_depth, p_source_normal_roughness), 0);
-	RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_image_pair(p_dest_depth, p_dest_normal_roughness), 1);
-	if (p_source_voxel_gi.is_valid()) {
-		RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_source_voxel_gi), 2);
-		RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_dest_voxel_gi), 3);
-	}
-
-	RD::get_singleton()->compute_list_set_push_constant(compute_list, &push_constant, sizeof(ResolvePushConstant));
-
-	RD::get_singleton()->compute_list_dispatch_threads(compute_list, p_screen_size.x, p_screen_size.y, 1);
-
-	RD::get_singleton()->compute_list_end(p_barrier);
-}
-
-void EffectsRD::resolve_depth(RID p_source_depth, RID p_dest_depth, Vector2i p_screen_size, int p_samples, uint32_t p_barrier) {
-	ResolvePushConstant push_constant;
-	push_constant.screen_size[0] = p_screen_size.x;
-	push_constant.screen_size[1] = p_screen_size.y;
-	push_constant.samples = p_samples;
-
-	RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
-	RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, resolve.pipelines[RESOLVE_MODE_DEPTH]);
-	RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_compute_uniform_set_from_texture(p_source_depth), 0);
-	RD::get_singleton()->compute_list_bind_uniform_set(compute_list, _get_uniform_set_from_image(p_dest_depth), 1);
-
-	RD::get_singleton()->compute_list_set_push_constant(compute_list, &push_constant, sizeof(ResolvePushConstant));
-
-	RD::get_singleton()->compute_list_dispatch_threads(compute_list, p_screen_size.x, p_screen_size.y, 1);
-
-	RD::get_singleton()->compute_list_end(p_barrier);
-}
-
 void EffectsRD::sort_buffer(RID p_uniform_set, int p_size) {
 	Sort::PushConstant push_constant;
 	push_constant.total_elements = p_size;
@@ -2009,21 +1969,6 @@ EffectsRD::EffectsRD(bool p_prefer_raster_effects) {
 				ssil.pipelines[i] = RD::get_singleton()->compute_pipeline_create(ssil.interleave_shader.version_get_shader(ssil.interleave_shader_version, i - SSIL_INTERLEAVE));
 			}
 		}
-
-		{
-			Vector<String> resolve_modes;
-			resolve_modes.push_back("\n#define MODE_RESOLVE_GI\n");
-			resolve_modes.push_back("\n#define MODE_RESOLVE_GI\n#define VOXEL_GI_RESOLVE\n");
-			resolve_modes.push_back("\n#define MODE_RESOLVE_DEPTH\n");
-
-			resolve.shader.initialize(resolve_modes);
-
-			resolve.shader_version = resolve.shader.version_create();
-
-			for (int i = 0; i < RESOLVE_MODE_MAX; i++) {
-				resolve.pipelines[i] = RD::get_singleton()->compute_pipeline_create(resolve.shader.version_get_shader(resolve.shader_version, i));
-			}
-		}
 	}
 
 	{
@@ -2110,7 +2055,6 @@ EffectsRD::~EffectsRD() {
 		filter.compute_shader.version_free(filter.shader_version);
 	}
 	if (!prefer_raster_effects) {
-		resolve.shader.version_free(resolve.shader_version);
 		specular_merge.shader.version_free(specular_merge.shader_version);
 		ss_effects.downsample_shader.version_free(ss_effects.downsample_shader_version);
 		ssao.blur_shader.version_free(ssao.blur_shader_version);

+ 0 - 24
servers/rendering/renderer_rd/effects_rd.h

@@ -43,7 +43,6 @@
 #include "servers/rendering/renderer_rd/shaders/fsr_upscale.glsl.gen.h"
 #include "servers/rendering/renderer_rd/shaders/luminance_reduce.glsl.gen.h"
 #include "servers/rendering/renderer_rd/shaders/luminance_reduce_raster.glsl.gen.h"
-#include "servers/rendering/renderer_rd/shaders/resolve.glsl.gen.h"
 #include "servers/rendering/renderer_rd/shaders/roughness_limiter.glsl.gen.h"
 #include "servers/rendering/renderer_rd/shaders/screen_space_reflection.glsl.gen.h"
 #include "servers/rendering/renderer_rd/shaders/screen_space_reflection_filter.glsl.gen.h"
@@ -579,26 +578,6 @@ private:
 		RID pipelines[3]; //3 quality levels
 	} sss;
 
-	struct ResolvePushConstant {
-		int32_t screen_size[2];
-		int32_t samples;
-		uint32_t pad;
-	};
-
-	enum ResolveMode {
-		RESOLVE_MODE_GI,
-		RESOLVE_MODE_GI_VOXEL_GI,
-		RESOLVE_MODE_DEPTH,
-		RESOLVE_MODE_MAX
-	};
-
-	struct Resolve {
-		ResolvePushConstant push_constant;
-		ResolveShaderRD shader;
-		RID shader_version;
-		RID pipelines[RESOLVE_MODE_MAX]; //3 quality levels
-	} resolve;
-
 	enum SortMode {
 		SORT_MODE_BLOCK,
 		SORT_MODE_STEP,
@@ -733,9 +712,6 @@ public:
 	void merge_specular(RID p_dest_framebuffer, RID p_specular, RID p_base, RID p_reflection);
 	void sub_surface_scattering(RID p_diffuse, RID p_diffuse2, RID p_depth, const CameraMatrix &p_camera, const Size2i &p_screen_size, float p_scale, float p_depth_scale, RS::SubSurfaceScatteringQuality p_quality);
 
-	void resolve_gi(RID p_source_depth, RID p_source_normal_roughness, RID p_source_voxel_gi, RID p_dest_depth, RID p_dest_normal_roughness, RID p_dest_voxel_gi, Vector2i p_screen_size, int p_samples, uint32_t p_barrier = RD::BARRIER_MASK_ALL);
-	void resolve_depth(RID p_source_depth, RID p_dest_depth, Vector2i p_screen_size, int p_samples, uint32_t p_barrier = RD::BARRIER_MASK_ALL);
-
 	void sort_buffer(RID p_uniform_set, int p_size);
 
 	EffectsRD(bool p_prefer_raster_effects);

+ 5 - 0
servers/rendering/renderer_rd/environment/SCsub

@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+
+Import("env")
+
+env.add_source_files(env.servers_sources, "*.cpp")

Fichier diff supprimé car celui-ci est trop grand
+ 569 - 175
servers/rendering/renderer_rd/environment/gi.cpp


+ 168 - 33
servers/rendering/renderer_rd/renderer_scene_gi_rd.h → servers/rendering/renderer_rd/environment/gi.h

@@ -1,5 +1,5 @@
 /*************************************************************************/
-/*  renderer_scene_gi_rd.h                                               */
+/*  gi.h                                                                 */
 /*************************************************************************/
 /*                       This file is part of:                           */
 /*                           GODOT ENGINE                                */
@@ -28,33 +28,77 @@
 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
 /*************************************************************************/
 
-#ifndef RENDERING_SERVER_SCENE_GI_RD_H
-#define RENDERING_SERVER_SCENE_GI_RD_H
+#ifndef GI_RD_H
+#define GI_RD_H
 
 #include "core/templates/local_vector.h"
 #include "core/templates/rid_owner.h"
+#include "servers/rendering/environment/renderer_gi.h"
 #include "servers/rendering/renderer_compositor.h"
 #include "servers/rendering/renderer_rd/renderer_scene_environment_rd.h"
 #include "servers/rendering/renderer_rd/renderer_scene_sky_rd.h"
 #include "servers/rendering/renderer_rd/renderer_storage_rd.h"
-#include "servers/rendering/renderer_rd/shaders/gi.glsl.gen.h"
-#include "servers/rendering/renderer_rd/shaders/sdfgi_debug.glsl.gen.h"
-#include "servers/rendering/renderer_rd/shaders/sdfgi_debug_probes.glsl.gen.h"
-#include "servers/rendering/renderer_rd/shaders/sdfgi_direct_light.glsl.gen.h"
-#include "servers/rendering/renderer_rd/shaders/sdfgi_integrate.glsl.gen.h"
-#include "servers/rendering/renderer_rd/shaders/sdfgi_preprocess.glsl.gen.h"
-#include "servers/rendering/renderer_rd/shaders/voxel_gi.glsl.gen.h"
-#include "servers/rendering/renderer_rd/shaders/voxel_gi_debug.glsl.gen.h"
+#include "servers/rendering/renderer_rd/shaders/environment/gi.glsl.gen.h"
+#include "servers/rendering/renderer_rd/shaders/environment/sdfgi_debug.glsl.gen.h"
+#include "servers/rendering/renderer_rd/shaders/environment/sdfgi_debug_probes.glsl.gen.h"
+#include "servers/rendering/renderer_rd/shaders/environment/sdfgi_direct_light.glsl.gen.h"
+#include "servers/rendering/renderer_rd/shaders/environment/sdfgi_integrate.glsl.gen.h"
+#include "servers/rendering/renderer_rd/shaders/environment/sdfgi_preprocess.glsl.gen.h"
+#include "servers/rendering/renderer_rd/shaders/environment/voxel_gi.glsl.gen.h"
+#include "servers/rendering/renderer_rd/shaders/environment/voxel_gi_debug.glsl.gen.h"
 #include "servers/rendering/renderer_scene_render.h"
+#include "servers/rendering/renderer_storage.h"
 #include "servers/rendering/rendering_device.h"
 
 // Forward declare RenderDataRD and RendererSceneRenderRD so we can pass it into some of our methods, these classes are pretty tightly bound
 struct RenderDataRD;
 class RendererSceneRenderRD;
 
-class RendererSceneGIRD {
+namespace RendererRD {
+
+class GI : public RendererGI {
+public:
+	/* VOXEL GI STORAGE */
+
+	struct VoxelGI {
+		RID octree_buffer;
+		RID data_buffer;
+		RID sdf_texture;
+
+		uint32_t octree_buffer_size = 0;
+		uint32_t data_buffer_size = 0;
+
+		Vector<int> level_counts;
+
+		int cell_count = 0;
+
+		Transform3D to_cell_xform;
+		AABB bounds;
+		Vector3i octree_size;
+
+		float dynamic_range = 2.0;
+		float energy = 1.0;
+		float bias = 1.4;
+		float normal_bias = 0.0;
+		float propagation = 0.7;
+		bool interior = false;
+		bool use_two_bounces = false;
+
+		float anisotropy_strength = 0.5;
+
+		uint32_t version = 1;
+		uint32_t data_version = 1;
+
+		RendererStorage::Dependency dependency;
+	};
+
 private:
 	RendererStorageRD *storage = nullptr;
+	static GI *singleton;
+
+	/* VOXEL GI STORAGE */
+
+	mutable RID_Owner<VoxelGI, true> voxel_gi_owner;
 
 	/* VOXEL_GI INSTANCE */
 
@@ -196,10 +240,13 @@ private:
 			uint32_t use_occlusion;
 			float y_mult;
 
-			float cam_extent[3];
 			uint32_t probe_axis_size;
+			float z_near;
+			float reserved1;
+			float reserved2;
 
 			float cam_transform[16];
+			float inv_projection[16];
 		};
 
 		SdfgiDebugShaderRD debug;
@@ -209,13 +256,17 @@ private:
 
 		enum ProbeDebugMode {
 			PROBE_DEBUG_PROBES,
+			PROBE_DEBUG_PROBES_MULTIVIEW,
 			PROBE_DEBUG_VISIBILITY,
+			PROBE_DEBUG_VISIBILITY_MULTIVIEW,
 			PROBE_DEBUG_MAX
 		};
 
-		struct DebugProbesPushConstant {
-			float projection[16];
+		struct DebugProbesSceneData {
+			float projection[2][16];
+		};
 
+		struct DebugProbesPushConstant {
 			uint32_t band_power;
 			uint32_t sections_in_band;
 			uint32_t band_mask;
@@ -324,6 +375,60 @@ private:
 	} sdfgi_shader;
 
 public:
+	static GI *get_singleton() { return singleton; }
+
+	/* VOXEL GI API */
+
+	VoxelGI *get_voxel_gi(RID p_rid) { return voxel_gi_owner.get_or_null(p_rid); };
+	bool owns_voxel_gi(RID p_rid) { return voxel_gi_owner.owns(p_rid); };
+
+	virtual RID voxel_gi_allocate() override;
+	virtual void voxel_gi_free(RID p_voxel_gi) override;
+	virtual void voxel_gi_initialize(RID p_voxel_gi) override;
+
+	virtual void voxel_gi_allocate_data(RID p_voxel_gi, const Transform3D &p_to_cell_xform, const AABB &p_aabb, const Vector3i &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts) override;
+
+	virtual AABB voxel_gi_get_bounds(RID p_voxel_gi) const override;
+	virtual Vector3i voxel_gi_get_octree_size(RID p_voxel_gi) const override;
+	virtual Vector<uint8_t> voxel_gi_get_octree_cells(RID p_voxel_gi) const override;
+	virtual Vector<uint8_t> voxel_gi_get_data_cells(RID p_voxel_gi) const override;
+	virtual Vector<uint8_t> voxel_gi_get_distance_field(RID p_voxel_gi) const override;
+
+	virtual Vector<int> voxel_gi_get_level_counts(RID p_voxel_gi) const override;
+	virtual Transform3D voxel_gi_get_to_cell_xform(RID p_voxel_gi) const override;
+
+	virtual void voxel_gi_set_dynamic_range(RID p_voxel_gi, float p_range) override;
+	virtual float voxel_gi_get_dynamic_range(RID p_voxel_gi) const override;
+
+	virtual void voxel_gi_set_propagation(RID p_voxel_gi, float p_range) override;
+	virtual float voxel_gi_get_propagation(RID p_voxel_gi) const override;
+
+	virtual void voxel_gi_set_energy(RID p_voxel_gi, float p_energy) override;
+	virtual float voxel_gi_get_energy(RID p_voxel_gi) const override;
+
+	virtual void voxel_gi_set_bias(RID p_voxel_gi, float p_bias) override;
+	virtual float voxel_gi_get_bias(RID p_voxel_gi) const override;
+
+	virtual void voxel_gi_set_normal_bias(RID p_voxel_gi, float p_range) override;
+	virtual float voxel_gi_get_normal_bias(RID p_voxel_gi) const override;
+
+	virtual void voxel_gi_set_interior(RID p_voxel_gi, bool p_enable) override;
+	virtual bool voxel_gi_is_interior(RID p_voxel_gi) const override;
+
+	virtual void voxel_gi_set_use_two_bounces(RID p_voxel_gi, bool p_enable) override;
+	virtual bool voxel_gi_is_using_two_bounces(RID p_voxel_gi) const override;
+
+	virtual void voxel_gi_set_anisotropy_strength(RID p_voxel_gi, float p_strength) override;
+	virtual float voxel_gi_get_anisotropy_strength(RID p_voxel_gi) const override;
+
+	virtual uint32_t voxel_gi_get_version(RID p_probe) const override;
+	uint32_t voxel_gi_get_data_version(RID p_probe);
+
+	RID voxel_gi_get_octree_buffer(RID p_voxel_gi) const;
+	RID voxel_gi_get_data_buffer(RID p_voxel_gi) const;
+
+	RID voxel_gi_get_sdf_texture(RID p_voxel_gi);
+
 	/* VOXEL_GI INSTANCE */
 
 	//@TODO VoxelGIInstance is still directly used in the render code, we'll address this when we refactor the render code itself.
@@ -331,7 +436,7 @@ public:
 	struct VoxelGIInstance {
 		// access to our containers
 		RendererStorageRD *storage = nullptr;
-		RendererSceneGIRD *gi = nullptr;
+		GI *gi = nullptr;
 
 		RID probe;
 		RID texture;
@@ -455,7 +560,7 @@ public:
 
 		// access to our containers
 		RendererStorageRD *storage = nullptr;
-		RendererSceneGIRD *gi = nullptr;
+		GI *gi = nullptr;
 
 		// used for rendering (voxelization)
 		RID render_albedo;
@@ -497,7 +602,8 @@ public:
 		float min_cell_size = 0;
 		uint32_t probe_axis_count = 0; //amount of probes per axis, this is an odd number because it encloses endpoints
 
-		RID debug_uniform_set;
+		RID debug_uniform_set[RendererSceneRender::MAX_RENDER_VIEWS];
+		RID debug_probes_scene_data_ubo;
 		RID debug_probes_uniform_set;
 		RID cascades_ubo;
 
@@ -516,7 +622,7 @@ public:
 		int32_t cascade_dynamic_light_count[SDFGI::MAX_CASCADES]; //used dynamically
 		RID integrate_sky_uniform_set;
 
-		void create(RendererSceneEnvironmentRD *p_env, const Vector3 &p_world_position, uint32_t p_requested_history_size, RendererSceneGIRD *p_gi);
+		void create(RendererSceneEnvironmentRD *p_env, const Vector3 &p_world_position, uint32_t p_requested_history_size, GI *p_gi);
 		void erase();
 		void update(RendererSceneEnvironmentRD *p_env, const Vector3 &p_world_position);
 		void update_light();
@@ -525,8 +631,8 @@ public:
 		int get_pending_region_data(int p_region, Vector3i &r_local_offset, Vector3i &r_local_size, AABB &r_bounds) const;
 		void update_cascades();
 
-		void debug_draw(const CameraMatrix &p_projection, const Transform3D &p_transform, int p_width, int p_height, RID p_render_target, RID p_texture);
-		void debug_probes(RD::DrawListID p_draw_list, RID p_framebuffer, const CameraMatrix &p_camera_with_transform);
+		void debug_draw(uint32_t p_view_count, const CameraMatrix *p_projections, const Transform3D &p_transform, int p_width, int p_height, RID p_render_target, RID p_texture, const Vector<RID> &p_texture_views);
+		void debug_probes(RID p_framebuffer, const uint32_t p_view_count, const CameraMatrix *p_camera_with_transforms, bool p_will_continue_color, bool p_will_continue_depth);
 
 		void pre_process_gi(const Transform3D &p_transform, RenderDataRD *p_render_data, RendererSceneRenderRD *p_scene_render);
 		void render_region(RID p_render_buffers, int p_region, const PagedArray<RendererSceneRender::GeometryInstance *> &p_instances, RendererSceneRenderRD *p_scene_render);
@@ -561,8 +667,18 @@ public:
 		RID full_dispatch;
 		RID full_mask;
 
-		RID uniform_set;
+		/* GI buffers */
+		RID ambient_buffer;
+		RID reflection_buffer;
+		RID ambient_view[RendererSceneRender::MAX_RENDER_VIEWS];
+		RID reflection_view[RendererSceneRender::MAX_RENDER_VIEWS];
+		RID uniform_set[RendererSceneRender::MAX_RENDER_VIEWS];
 		bool using_half_size_gi = false;
+		uint32_t view_count = 1;
+
+		RID scene_data_ubo;
+
+		void free();
 	};
 
 	struct SDFGIData {
@@ -611,19 +727,28 @@ public:
 		uint32_t mipmaps; // 4 - 96
 	};
 
-	struct PushConstant {
-		int32_t screen_size[2];
-		float z_near;
-		float z_far;
+	struct SceneData {
+		float inv_projection[2][16];
+		float cam_transform[16];
+		float eye_offset[2][4];
 
-		float proj_info[4];
+		int32_t screen_size[2];
+		float pad1;
+		float pad2;
+	};
 
+	struct PushConstant {
+		uint32_t view_index;
 		uint32_t max_voxel_gi_instances;
 		uint32_t high_quality_vct;
 		uint32_t orthogonal;
-		uint32_t pad;
 
-		float cam_rotation[12];
+		float proj_info[4];
+
+		float z_near;
+		float z_far;
+		float pad1;
+		float pad2;
 	};
 
 	RID sdfgi_ubo;
@@ -634,6 +759,14 @@ public:
 		MODE_HALF_RES_VOXEL_GI,
 		MODE_HALF_RES_SDFGI,
 		MODE_HALF_RES_COMBINED,
+
+		MODE_VOXEL_GI_MULTIVIEW,
+		MODE_SDFGI_MULTIVIEW,
+		MODE_COMBINED_MULTIVIEW,
+		MODE_HALF_RES_VOXEL_GI_MULTIVIEW,
+		MODE_HALF_RES_SDFGI_MULTIVIEW,
+		MODE_HALF_RES_COMBINED_MULTIVIEW,
+
 		MODE_MAX
 	};
 
@@ -644,8 +777,8 @@ public:
 	RID shader_version;
 	RID pipelines[MODE_MAX];
 
-	RendererSceneGIRD();
-	~RendererSceneGIRD();
+	GI();
+	~GI();
 
 	void init(RendererStorageRD *p_storage, RendererSceneSkyRD *p_sky);
 	void free();
@@ -653,7 +786,7 @@ public:
 	SDFGI *create_sdfgi(RendererSceneEnvironmentRD *p_env, const Vector3 &p_world_position, uint32_t p_requested_history_size);
 
 	void setup_voxel_gi_instances(RID p_render_buffers, const Transform3D &p_transform, const PagedArray<RID> &p_voxel_gi_instances, uint32_t &r_voxel_gi_instances_used, RendererSceneRenderRD *p_scene_render);
-	void process_gi(RID p_render_buffers, RID p_normal_roughness_buffer, RID p_voxel_gi_buffer, RID p_environment, const CameraMatrix &p_projection, const Transform3D &p_transform, const PagedArray<RID> &p_voxel_gi_instances, RendererSceneRenderRD *p_scene_render);
+	void process_gi(RID p_render_buffers, RID *p_normal_roughness_views, RID p_voxel_gi_buffer, RID p_environment, uint32_t p_view_count, const CameraMatrix *p_projections, const Vector3 *p_eye_offsets, const Transform3D &p_cam_transform, const PagedArray<RID> &p_voxel_gi_instances, RendererSceneRenderRD *p_scene_render);
 
 	RID voxel_gi_instance_create(RID p_base);
 	void voxel_gi_instance_set_transform_to_data(RID p_probe, const Transform3D &p_xform);
@@ -662,4 +795,6 @@ public:
 	void debug_voxel_gi(RID p_voxel_gi, RD::DrawListID p_draw_list, RID p_framebuffer, const CameraMatrix &p_camera_with_transform, bool p_lighting, bool p_emission, float p_alpha);
 };
 
-#endif /* !RENDERING_SERVER_SCENE_GI_RD_H */
+} // namespace RendererRD
+
+#endif /* !GI_RD_H */

+ 175 - 29
servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp

@@ -48,6 +48,13 @@ void RenderForwardClustered::RenderBufferDataForwardClustered::ensure_specular()
 	if (!specular.is_valid()) {
 		RD::TextureFormat tf;
 		tf.format = RD::DATA_FORMAT_R16G16B16A16_SFLOAT;
+		if (view_count > 1) {
+			tf.texture_type = RD::TEXTURE_TYPE_2D_ARRAY;
+			tf.array_layers = view_count;
+		} else {
+			tf.texture_type = RD::TEXTURE_TYPE_2D;
+			tf.array_layers = 1;
+		}
 		tf.width = width;
 		tf.height = height;
 		tf.usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_STORAGE_BIT;
@@ -64,7 +71,7 @@ void RenderForwardClustered::RenderBufferDataForwardClustered::ensure_specular()
 				Vector<RID> fb;
 				fb.push_back(specular);
 
-				specular_only_fb = RD::get_singleton()->framebuffer_create(fb);
+				specular_only_fb = RD::get_singleton()->framebuffer_create(fb, RD::INVALID_ID, view_count);
 			}
 
 		} else {
@@ -76,7 +83,7 @@ void RenderForwardClustered::RenderBufferDataForwardClustered::ensure_specular()
 				Vector<RID> fb;
 				fb.push_back(specular_msaa);
 
-				specular_only_fb = RD::get_singleton()->framebuffer_create(fb);
+				specular_only_fb = RD::get_singleton()->framebuffer_create(fb, RD::INVALID_ID, view_count);
 			}
 		}
 	}
@@ -106,6 +113,13 @@ void RenderForwardClustered::RenderBufferDataForwardClustered::ensure_velocity()
 void RenderForwardClustered::RenderBufferDataForwardClustered::ensure_voxelgi() {
 	if (!voxelgi_buffer.is_valid()) {
 		RD::TextureFormat tf;
+		if (view_count > 1) {
+			tf.texture_type = RD::TEXTURE_TYPE_2D_ARRAY;
+			tf.array_layers = view_count;
+		} else {
+			tf.texture_type = RD::TEXTURE_TYPE_2D;
+			tf.array_layers = 1;
+		}
 		tf.format = RD::DATA_FORMAT_R8G8_UINT;
 		tf.width = width;
 		tf.height = height;
@@ -116,6 +130,14 @@ void RenderForwardClustered::RenderBufferDataForwardClustered::ensure_voxelgi()
 			tf_aa.usage_bits |= RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT;
 			tf_aa.samples = texture_samples;
 			voxelgi_buffer_msaa = RD::get_singleton()->texture_create(tf_aa, RD::TextureView());
+
+			if (view_count == 1) {
+				voxelgi_msaa_views[0] = voxelgi_buffer_msaa;
+			} else {
+				for (uint32_t v = 0; v < view_count; v++) {
+					voxelgi_msaa_views[v] = RD::get_singleton()->texture_create_shared_from_slice(RD::TextureView(), voxelgi_buffer_msaa, v, 0);
+				}
+			}
 		} else {
 			tf.usage_bits |= RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT;
 		}
@@ -124,6 +146,14 @@ void RenderForwardClustered::RenderBufferDataForwardClustered::ensure_voxelgi()
 
 		voxelgi_buffer = RD::get_singleton()->texture_create(tf, RD::TextureView());
 
+		if (view_count == 1) {
+			voxelgi_views[0] = voxelgi_buffer;
+		} else {
+			for (uint32_t v = 0; v < view_count; v++) {
+				voxelgi_views[v] = RD::get_singleton()->texture_create_shared_from_slice(RD::TextureView(), voxelgi_buffer, v, 0);
+			}
+		}
+
 		Vector<RID> fb;
 		if (msaa != RS::VIEWPORT_MSAA_DISABLED) {
 			fb.push_back(depth_msaa);
@@ -135,7 +165,7 @@ void RenderForwardClustered::RenderBufferDataForwardClustered::ensure_voxelgi()
 			fb.push_back(voxelgi_buffer);
 		}
 
-		depth_normal_roughness_voxelgi_fb = RD::get_singleton()->framebuffer_create(fb);
+		depth_normal_roughness_voxelgi_fb = RD::get_singleton()->framebuffer_create(fb, RD::INVALID_ID, view_count);
 	}
 }
 
@@ -144,7 +174,25 @@ void RenderForwardClustered::RenderBufferDataForwardClustered::clear() {
 		RD::get_singleton()->free(voxelgi_buffer);
 		voxelgi_buffer = RID();
 
+		if (view_count == 1) {
+			voxelgi_views[0] = RID();
+		} else {
+			for (uint32_t v = 0; v < view_count; v++) {
+				RD::get_singleton()->free(voxelgi_views[v]);
+				voxelgi_views[v] = RID();
+			}
+		}
+
 		if (voxelgi_buffer_msaa.is_valid()) {
+			if (view_count == 1) {
+				voxelgi_msaa_views[0] = RID();
+			} else {
+				for (uint32_t v = 0; v < view_count; v++) {
+					RD::get_singleton()->free(voxelgi_msaa_views[v]);
+					voxelgi_msaa_views[v] = RID();
+				}
+			}
+
 			RD::get_singleton()->free(voxelgi_buffer_msaa);
 			voxelgi_buffer_msaa = RID();
 		}
@@ -153,11 +201,35 @@ void RenderForwardClustered::RenderBufferDataForwardClustered::clear() {
 	}
 
 	if (color_msaa.is_valid()) {
+		if (view_count == 1) {
+			color_views[0] = RID();
+			color_msaa_views[0] = RID();
+		} else {
+			for (uint32_t v = 0; v < view_count; v++) {
+				RD::get_singleton()->free(color_views[v]);
+				RD::get_singleton()->free(color_msaa_views[v]);
+				color_views[v] = RID();
+				color_msaa_views[v] = RID();
+			}
+		}
+
 		RD::get_singleton()->free(color_msaa);
 		color_msaa = RID();
 	}
 
 	if (depth_msaa.is_valid()) {
+		if (view_count == 1) {
+			depth_views[0] = RID();
+			depth_msaa_views[0] = RID();
+		} else {
+			for (uint32_t v = 0; v < view_count; v++) {
+				RD::get_singleton()->free(depth_views[v]);
+				RD::get_singleton()->free(depth_msaa_views[v]);
+				depth_views[v] = RID();
+				depth_msaa_views[v] = RID();
+			}
+		}
+
 		RD::get_singleton()->free(depth_msaa);
 		depth_msaa = RID();
 	}
@@ -178,12 +250,31 @@ void RenderForwardClustered::RenderBufferDataForwardClustered::clear() {
 	color_framebuffers.clear(); // Color pass framebuffers are freed automatically by their dependency relations
 
 	if (normal_roughness_buffer.is_valid()) {
+		if (view_count == 1) {
+			normal_roughness_views[0] = RID();
+		} else {
+			for (uint32_t v = 0; v < view_count; v++) {
+				RD::get_singleton()->free(normal_roughness_views[v]);
+				normal_roughness_views[v] = RID();
+			}
+		}
+
 		RD::get_singleton()->free(normal_roughness_buffer);
+		normal_roughness_buffer = RID();
+
 		if (normal_roughness_buffer_msaa.is_valid()) {
+			if (view_count == 1) {
+				normal_roughness_msaa_views[0] = RID();
+			} else {
+				for (uint32_t v = 0; v < view_count; v++) {
+					RD::get_singleton()->free(normal_roughness_msaa_views[v]);
+					normal_roughness_msaa_views[v] = RID();
+				}
+			}
 			RD::get_singleton()->free(normal_roughness_buffer_msaa);
 			normal_roughness_buffer_msaa = RID();
 		}
-		normal_roughness_buffer = RID();
+
 		depth_normal_roughness_fb = RID();
 	}
 
@@ -259,6 +350,22 @@ void RenderForwardClustered::RenderBufferDataForwardClustered::configure(RID p_c
 
 		depth_msaa = RD::get_singleton()->texture_create(tf, RD::TextureView());
 
+		if (view_count == 1) {
+			// just reuse
+			color_views[0] = color;
+			depth_views[0] = depth;
+			color_msaa_views[0] = color_msaa;
+			depth_msaa_views[0] = depth_msaa;
+		} else {
+			// create slices
+			for (uint32_t v = 0; v < view_count; v++) {
+				color_views[v] = RD::get_singleton()->texture_create_shared_from_slice(RD::TextureView(), color, v, 0);
+				depth_views[v] = RD::get_singleton()->texture_create_shared_from_slice(RD::TextureView(), depth, v, 0);
+				color_msaa_views[v] = RD::get_singleton()->texture_create_shared_from_slice(RD::TextureView(), color_msaa, v, 0);
+				depth_msaa_views[v] = RD::get_singleton()->texture_create_shared_from_slice(RD::TextureView(), depth_msaa, v, 0);
+			}
+		}
+
 		{
 			Vector<RID> fb;
 			fb.push_back(color_msaa);
@@ -308,6 +415,8 @@ RID RenderForwardClustered::RenderBufferDataForwardClustered::get_color_pass_fb(
 }
 
 void RenderForwardClustered::_allocate_normal_roughness_texture(RenderBufferDataForwardClustered *rb) {
+	ERR_FAIL_COND_MSG(rb->view_count > 2, "Only support up to two views for roughness texture");
+
 	if (rb->normal_roughness_buffer.is_valid()) {
 		return;
 	}
@@ -316,6 +425,13 @@ void RenderForwardClustered::_allocate_normal_roughness_texture(RenderBufferData
 	tf.format = RD::DATA_FORMAT_R8G8B8A8_UNORM;
 	tf.width = rb->width;
 	tf.height = rb->height;
+	if (rb->view_count > 1) {
+		tf.texture_type = RD::TEXTURE_TYPE_2D_ARRAY;
+		tf.array_layers = rb->view_count;
+	} else {
+		tf.texture_type = RD::TEXTURE_TYPE_2D;
+		tf.array_layers = 1;
+	}
 	tf.usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_STORAGE_BIT;
 
 	if (rb->msaa != RS::VIEWPORT_MSAA_DISABLED) {
@@ -330,7 +446,7 @@ void RenderForwardClustered::_allocate_normal_roughness_texture(RenderBufferData
 		Vector<RID> fb;
 		fb.push_back(rb->depth);
 		fb.push_back(rb->normal_roughness_buffer);
-		rb->depth_normal_roughness_fb = RD::get_singleton()->framebuffer_create(fb);
+		rb->depth_normal_roughness_fb = RD::get_singleton()->framebuffer_create(fb, RD::INVALID_ID, rb->view_count);
 	} else {
 		tf.usage_bits = RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT | RD::TEXTURE_USAGE_CAN_COPY_FROM_BIT | RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_STORAGE_BIT;
 		tf.samples = rb->texture_samples;
@@ -339,7 +455,21 @@ void RenderForwardClustered::_allocate_normal_roughness_texture(RenderBufferData
 		Vector<RID> fb;
 		fb.push_back(rb->depth_msaa);
 		fb.push_back(rb->normal_roughness_buffer_msaa);
-		rb->depth_normal_roughness_fb = RD::get_singleton()->framebuffer_create(fb);
+		rb->depth_normal_roughness_fb = RD::get_singleton()->framebuffer_create(fb, RD::INVALID_ID, rb->view_count);
+	}
+
+	if (rb->view_count == 1) {
+		rb->normal_roughness_views[0] = rb->normal_roughness_buffer;
+		if (rb->msaa != RS::VIEWPORT_MSAA_DISABLED) {
+			rb->normal_roughness_msaa_views[0] = rb->normal_roughness_buffer_msaa;
+		}
+	} else {
+		for (uint32_t v = 0; v < rb->view_count; v++) {
+			rb->normal_roughness_views[v] = RD::get_singleton()->texture_create_shared_from_slice(RD::TextureView(), rb->normal_roughness_buffer, v, 0);
+			if (rb->msaa != RS::VIEWPORT_MSAA_DISABLED) {
+				rb->normal_roughness_msaa_views[v] = RD::get_singleton()->texture_create_shared_from_slice(RD::TextureView(), rb->normal_roughness_buffer_msaa, v, 0);
+			}
+		}
 	}
 }
 
@@ -503,22 +633,21 @@ void RenderForwardClustered::_render_list_template(RenderingDevice::DrawListID p
 				pipeline_version = p_params->view_count > 1 ? SceneShaderForwardClustered::PIPELINE_VERSION_DEPTH_PASS_MULTIVIEW : SceneShaderForwardClustered::PIPELINE_VERSION_DEPTH_PASS;
 			} break;
 			case PASS_MODE_SHADOW_DP: {
-				ERR_FAIL_COND_MSG(p_params->view_count > 1, "Multiview not supported for shadow DP  pass");
+				ERR_FAIL_COND_MSG(p_params->view_count > 1, "Multiview not supported for shadow DP pass");
 				pipeline_version = SceneShaderForwardClustered::PIPELINE_VERSION_DEPTH_PASS_DP;
 			} break;
 			case PASS_MODE_DEPTH_NORMAL_ROUGHNESS: {
-				ERR_FAIL_COND_MSG(p_params->view_count > 1, "Multiview not supported for depth/roughness pass");
-				pipeline_version = SceneShaderForwardClustered::PIPELINE_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS;
+				pipeline_version = p_params->view_count > 1 ? SceneShaderForwardClustered::PIPELINE_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS_MULTIVIEW : SceneShaderForwardClustered::PIPELINE_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS;
 			} break;
 			case PASS_MODE_DEPTH_NORMAL_ROUGHNESS_VOXEL_GI: {
-				ERR_FAIL_COND_MSG(p_params->view_count > 1, "Multiview not supported for voxel GI pass");
-				pipeline_version = SceneShaderForwardClustered::PIPELINE_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS_AND_VOXEL_GI;
+				pipeline_version = p_params->view_count > 1 ? SceneShaderForwardClustered::PIPELINE_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS_AND_VOXEL_GI_MULTIVIEW : SceneShaderForwardClustered::PIPELINE_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS_AND_VOXEL_GI;
 			} break;
 			case PASS_MODE_DEPTH_MATERIAL: {
 				ERR_FAIL_COND_MSG(p_params->view_count > 1, "Multiview not supported for material pass");
 				pipeline_version = SceneShaderForwardClustered::PIPELINE_VERSION_DEPTH_PASS_WITH_MATERIAL;
 			} break;
 			case PASS_MODE_SDF: {
+				// Note, SDF is prepared in world space, this shouldn't be a multiview buffer even when stereoscopic rendering is used.
 				ERR_FAIL_COND_MSG(p_params->view_count > 1, "Multiview not supported for SDF pass");
 				pipeline_version = SceneShaderForwardClustered::PIPELINE_VERSION_DEPTH_PASS_WITH_SDF;
 			} break;
@@ -1323,9 +1452,7 @@ void RenderForwardClustered::_render_scene(RenderDataRD *p_render_data, const Co
 			using_voxelgi = true;
 		}
 
-		if (p_render_data->view_count > 1) {
-			depth_pass_mode = PASS_MODE_DEPTH;
-		} else if (!p_render_data->environment.is_valid() && using_voxelgi) {
+		if (!p_render_data->environment.is_valid() && using_voxelgi) {
 			depth_pass_mode = PASS_MODE_DEPTH_NORMAL_ROUGHNESS_VOXEL_GI;
 		} else if (p_render_data->environment.is_valid() && (environment_is_ssr_enabled(p_render_data->environment) || environment_is_sdfgi_enabled(p_render_data->environment) || using_voxelgi)) {
 			if (environment_is_sdfgi_enabled(p_render_data->environment)) {
@@ -1531,9 +1658,13 @@ void RenderForwardClustered::_render_scene(RenderDataRD *p_render_data, const Co
 				if (needs_pre_resolve) {
 					RD::get_singleton()->barrier(RD::BARRIER_MASK_RASTER, RD::BARRIER_MASK_COMPUTE);
 				}
-				storage->get_effects()->resolve_gi(render_buffer->depth_msaa, render_buffer->normal_roughness_buffer_msaa, using_voxelgi ? render_buffer->voxelgi_buffer_msaa : RID(), render_buffer->depth, render_buffer->normal_roughness_buffer, using_voxelgi ? render_buffer->voxelgi_buffer : RID(), Vector2i(render_buffer->width, render_buffer->height), texture_multisamples[render_buffer->msaa]);
+				for (uint32_t v = 0; v < render_buffer->view_count; v++) {
+					resolve_effects->resolve_gi(render_buffer->depth_msaa_views[v], render_buffer->normal_roughness_msaa_views[v], using_voxelgi ? render_buffer->voxelgi_msaa_views[v] : RID(), render_buffer->depth_views[v], render_buffer->normal_roughness_views[v], using_voxelgi ? render_buffer->voxelgi_views[v] : RID(), Vector2i(render_buffer->width, render_buffer->height), texture_multisamples[render_buffer->msaa]);
+				}
 			} else if (finish_depth) {
-				storage->get_effects()->resolve_depth(render_buffer->depth_msaa, render_buffer->depth, Vector2i(render_buffer->width, render_buffer->height), texture_multisamples[render_buffer->msaa]);
+				for (uint32_t v = 0; v < render_buffer->view_count; v++) {
+					resolve_effects->resolve_depth(render_buffer->depth_msaa_views[v], render_buffer->depth_views[v], Vector2i(render_buffer->width, render_buffer->height), texture_multisamples[render_buffer->msaa]);
+				}
 			}
 			RD::get_singleton()->draw_command_end_label();
 		}
@@ -1541,7 +1672,8 @@ void RenderForwardClustered::_render_scene(RenderDataRD *p_render_data, const Co
 		continue_depth = !finish_depth;
 	}
 
-	_pre_opaque_render(p_render_data, using_ssao, using_ssil, using_sdfgi || using_voxelgi, render_buffer ? render_buffer->normal_roughness_buffer : RID(), render_buffer ? render_buffer->voxelgi_buffer : RID());
+	RID null_rids[2];
+	_pre_opaque_render(p_render_data, using_ssao, using_ssil, using_sdfgi || using_voxelgi, render_buffer ? render_buffer->normal_roughness_views : null_rids, render_buffer ? render_buffer->voxelgi_buffer : RID());
 
 	RD::get_singleton()->draw_command_begin_label("Render Opaque Pass");
 
@@ -1604,18 +1736,17 @@ void RenderForwardClustered::_render_scene(RenderDataRD *p_render_data, const Co
 	}
 
 	if (debug_sdfgi_probes) {
-		//debug voxelgis
+		//debug sdfgi
 		bool will_continue_color = (can_continue_color || draw_sky || draw_sky_fog_only);
 		bool will_continue_depth = (can_continue_depth || draw_sky || draw_sky_fog_only);
 
 		CameraMatrix dc;
 		dc.set_depth_correction(true);
-		CameraMatrix cm = (dc * p_render_data->cam_projection) * CameraMatrix(p_render_data->cam_transform.affine_inverse());
-		RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(color_only_framebuffer, RD::INITIAL_ACTION_CONTINUE, will_continue_color ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ, RD::INITIAL_ACTION_CONTINUE, will_continue_depth ? RD::FINAL_ACTION_CONTINUE : RD::FINAL_ACTION_READ);
-		RD::get_singleton()->draw_command_begin_label("Debug SDFGI");
-		_debug_sdfgi_probes(p_render_data->render_buffers, draw_list, color_only_framebuffer, cm);
-		RD::get_singleton()->draw_command_end_label();
-		RD::get_singleton()->draw_list_end();
+		CameraMatrix cms[RendererSceneRender::MAX_RENDER_VIEWS];
+		for (uint32_t v = 0; v < p_render_data->view_count; v++) {
+			cms[v] = (dc * p_render_data->view_projection[v]) * CameraMatrix(p_render_data->cam_transform.affine_inverse());
+		}
+		_debug_sdfgi_probes(p_render_data->render_buffers, color_only_framebuffer, p_render_data->view_count, cms, will_continue_color, will_continue_depth);
 	}
 
 	if (draw_sky || draw_sky_fog_only) {
@@ -1635,14 +1766,20 @@ void RenderForwardClustered::_render_scene(RenderDataRD *p_render_data, const Co
 	}
 
 	if (render_buffer && !can_continue_color && render_buffer->msaa != RS::VIEWPORT_MSAA_DISABLED) {
-		RD::get_singleton()->texture_resolve_multisample(render_buffer->color_msaa, render_buffer->color);
+		// Handle views individual, might want to look at rewriting our resolve to do both layers in one pass.
+		for (uint32_t v = 0; v < render_buffer->view_count; v++) {
+			RD::get_singleton()->texture_resolve_multisample(render_buffer->color_msaa_views[v], render_buffer->color_views[v]);
+		}
+		// TODO mame this do multiview
 		if (using_separate_specular) {
 			RD::get_singleton()->texture_resolve_multisample(render_buffer->specular_msaa, render_buffer->specular);
 		}
 	}
 
 	if (render_buffer && !can_continue_depth && render_buffer->msaa != RS::VIEWPORT_MSAA_DISABLED) {
-		storage->get_effects()->resolve_depth(render_buffer->depth_msaa, render_buffer->depth, Vector2i(render_buffer->width, render_buffer->height), texture_multisamples[render_buffer->msaa]);
+		for (uint32_t v = 0; v < render_buffer->view_count; v++) {
+			resolve_effects->resolve_depth(render_buffer->depth_msaa_views[v], render_buffer->depth_views[v], Vector2i(render_buffer->width, render_buffer->height), texture_multisamples[render_buffer->msaa]);
+		}
 	}
 
 	if (using_separate_specular) {
@@ -1697,11 +1834,13 @@ void RenderForwardClustered::_render_scene(RenderDataRD *p_render_data, const Co
 	RD::get_singleton()->draw_command_begin_label("Resolve");
 
 	if (render_buffer && render_buffer->msaa != RS::VIEWPORT_MSAA_DISABLED) {
-		RD::get_singleton()->texture_resolve_multisample(render_buffer->color_msaa, render_buffer->color);
-		if (render_buffer->use_taa) {
+		for (uint32_t v = 0; v < render_buffer->view_count; v++) {
+			RD::get_singleton()->texture_resolve_multisample(render_buffer->color_msaa_views[v], render_buffer->color_views[v]);
+			resolve_effects->resolve_depth(render_buffer->depth_msaa_views[v], render_buffer->depth_views[v], Vector2i(render_buffer->width, render_buffer->height), texture_multisamples[render_buffer->msaa]);
+		}
+		if (render_buffer->use_taa) { // TODO make TAA stereo capable, this will need to be handled in a separate PR
 			RD::get_singleton()->texture_resolve_multisample(render_buffer->velocity_buffer_msaa, render_buffer->velocity_buffer);
 		}
-		storage->get_effects()->resolve_depth(render_buffer->depth_msaa, render_buffer->depth, Vector2i(render_buffer->width, render_buffer->height), texture_multisamples[render_buffer->msaa]);
 	}
 
 	RD::get_singleton()->draw_command_end_label();
@@ -3320,9 +3459,16 @@ RenderForwardClustered::RenderForwardClustered(RendererStorageRD *p_storage) :
 	render_list_thread_threshold = GLOBAL_GET("rendering/limits/forward_renderer/threaded_render_minimum_instances");
 
 	_update_shader_quality_settings();
+
+	resolve_effects = memnew(RendererRD::Resolve());
 }
 
 RenderForwardClustered::~RenderForwardClustered() {
+	if (resolve_effects != nullptr) {
+		memdelete(resolve_effects);
+		resolve_effects = nullptr;
+	}
+
 	directional_shadow_atlas_set_size(0);
 
 	{

+ 13 - 2
servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h

@@ -32,6 +32,7 @@
 #define RENDERING_SERVER_SCENE_RENDER_FORWARD_CLUSTERED_H
 
 #include "core/templates/paged_allocator.h"
+#include "servers/rendering/renderer_rd/effects/resolve.h"
 #include "servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h"
 #include "servers/rendering/renderer_rd/pipeline_cache_rd.h"
 #include "servers/rendering/renderer_rd/renderer_scene_render_rd.h"
@@ -72,7 +73,6 @@ class RenderForwardClustered : public RendererSceneRenderRD {
 		RENDER_LIST_ALPHA, //used for transparent objects
 		RENDER_LIST_SECONDARY, //used for shadows and other objects
 		RENDER_LIST_MAX
-
 	};
 
 	/* Scene Shader */
@@ -99,7 +99,6 @@ class RenderForwardClustered : public RendererSceneRenderRD {
 		RID depth_msaa;
 		RID specular_msaa;
 		RID normal_roughness_buffer_msaa;
-		RID roughness_buffer_msaa;
 		RID voxelgi_buffer_msaa;
 		RID velocity_buffer_msaa;
 
@@ -110,7 +109,17 @@ class RenderForwardClustered : public RendererSceneRenderRD {
 		RID specular_only_fb;
 		int width, height;
 		HashMap<uint32_t, RID> color_framebuffers;
+
+		// for multiview
 		uint32_t view_count;
+		RID color_views[RendererSceneRender::MAX_RENDER_VIEWS]; // we should rewrite this so we get access to the existing views in our renderer, something we can address when we reorg this
+		RID depth_views[RendererSceneRender::MAX_RENDER_VIEWS]; // we should rewrite this so we get access to the existing views in our renderer, something we can address when we reorg this
+		RID color_msaa_views[RendererSceneRender::MAX_RENDER_VIEWS];
+		RID depth_msaa_views[RendererSceneRender::MAX_RENDER_VIEWS];
+		RID normal_roughness_views[RendererSceneRender::MAX_RENDER_VIEWS];
+		RID normal_roughness_msaa_views[RendererSceneRender::MAX_RENDER_VIEWS];
+		RID voxelgi_views[RendererSceneRender::MAX_RENDER_VIEWS];
+		RID voxelgi_msaa_views[RendererSceneRender::MAX_RENDER_VIEWS];
 
 		RID render_sdfgi_uniform_set;
 		void ensure_specular();
@@ -619,6 +628,8 @@ class RenderForwardClustered : public RendererSceneRenderRD {
 
 	virtual void _update_shader_quality_settings() override;
 
+	RendererRD::Resolve *resolve_effects = nullptr;
+
 protected:
 	virtual void _render_scene(RenderDataRD *p_render_data, const Color &p_default_bg_color) override;
 

+ 9 - 3
servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp

@@ -282,6 +282,8 @@ void SceneShaderForwardClustered::ShaderData::set_code(const String &p_code) {
 					SHADER_VERSION_DEPTH_PASS_WITH_MATERIAL,
 					SHADER_VERSION_DEPTH_PASS_WITH_SDF,
 					SHADER_VERSION_DEPTH_PASS_MULTIVIEW,
+					SHADER_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS_MULTIVIEW,
+					SHADER_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS_AND_VOXEL_GI_MULTIVIEW,
 					SHADER_VERSION_COLOR_PASS,
 				};
 
@@ -349,9 +351,9 @@ void SceneShaderForwardClustered::ShaderData::set_code(const String &p_code) {
 
 					if (k == PIPELINE_VERSION_DEPTH_PASS || k == PIPELINE_VERSION_DEPTH_PASS_DP || k == PIPELINE_VERSION_DEPTH_PASS_MULTIVIEW) {
 						//none, leave empty
-					} else if (k == PIPELINE_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS) {
+					} else if (k == PIPELINE_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS || k == PIPELINE_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS_MULTIVIEW) {
 						blend_state = blend_state_depth_normal_roughness;
-					} else if (k == PIPELINE_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS_AND_VOXEL_GI) {
+					} else if (k == PIPELINE_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS_AND_VOXEL_GI || k == PIPELINE_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS_AND_VOXEL_GI_MULTIVIEW) {
 						blend_state = blend_state_depth_normal_roughness_giprobe;
 					} else if (k == PIPELINE_VERSION_DEPTH_PASS_WITH_MATERIAL) {
 						blend_state = RD::PipelineColorBlendState::create_disabled(5); //writes to normal and roughness in opaque way
@@ -527,10 +529,12 @@ void SceneShaderForwardClustered::init(RendererStorageRD *p_storage, const Strin
 		shader_versions.push_back("\n#define MODE_RENDER_DEPTH\n"); // SHADER_VERSION_DEPTH_PASS
 		shader_versions.push_back("\n#define MODE_RENDER_DEPTH\n#define MODE_DUAL_PARABOLOID\n"); // SHADER_VERSION_DEPTH_PASS_DP
 		shader_versions.push_back("\n#define MODE_RENDER_DEPTH\n#define MODE_RENDER_NORMAL_ROUGHNESS\n"); // SHADER_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS
-		shader_versions.push_back("\n#define MODE_RENDER_DEPTH\n#define MODE_RENDER_NORMAL_ROUGHNESS\n#define MODE_RENDER_VOXEL_GI\n"); // SHADER_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS_AND_GIPROBE
+		shader_versions.push_back("\n#define MODE_RENDER_DEPTH\n#define MODE_RENDER_NORMAL_ROUGHNESS\n#define MODE_RENDER_VOXEL_GI\n"); // SHADER_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS_AND_VOXEL_GI
 		shader_versions.push_back("\n#define MODE_RENDER_DEPTH\n#define MODE_RENDER_MATERIAL\n"); // SHADER_VERSION_DEPTH_PASS_WITH_MATERIAL
 		shader_versions.push_back("\n#define MODE_RENDER_DEPTH\n#define MODE_RENDER_SDF\n"); // SHADER_VERSION_DEPTH_PASS_WITH_SDF
 		shader_versions.push_back("\n#define USE_MULTIVIEW\n#define MODE_RENDER_DEPTH\n"); // SHADER_VERSION_DEPTH_PASS_MULTIVIEW
+		shader_versions.push_back("\n#define USE_MULTIVIEW\n#define MODE_RENDER_DEPTH\n#define MODE_RENDER_NORMAL_ROUGHNESS\n"); // SHADER_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS_MULTIVIEW
+		shader_versions.push_back("\n#define USE_MULTIVIEW\n#define MODE_RENDER_DEPTH\n#define MODE_RENDER_NORMAL_ROUGHNESS\n#define MODE_RENDER_VOXEL_GI\n"); // SHADER_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS_AND_VOXEL_GI_MULTIVIEW
 
 		Vector<String> color_pass_flags = {
 			"\n#define MODE_SEPARATE_SPECULAR\n", // SHADER_COLOR_PASS_FLAG_SEPARATE_SPECULAR
@@ -553,6 +557,8 @@ void SceneShaderForwardClustered::init(RendererStorageRD *p_storage, const Strin
 
 		if (!RendererCompositorRD::singleton->is_xr_enabled()) {
 			shader.set_variant_enabled(SHADER_VERSION_DEPTH_PASS_MULTIVIEW, false);
+			shader.set_variant_enabled(SHADER_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS_MULTIVIEW, false);
+			shader.set_variant_enabled(SHADER_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS_AND_VOXEL_GI_MULTIVIEW, false);
 			// TODO Add a way to enable/disable color pass flags
 		}
 	}

+ 4 - 0
servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h

@@ -52,6 +52,8 @@ public:
 		SHADER_VERSION_DEPTH_PASS_WITH_MATERIAL,
 		SHADER_VERSION_DEPTH_PASS_WITH_SDF,
 		SHADER_VERSION_DEPTH_PASS_MULTIVIEW,
+		SHADER_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS_MULTIVIEW,
+		SHADER_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS_AND_VOXEL_GI_MULTIVIEW,
 		SHADER_VERSION_COLOR_PASS,
 		SHADER_VERSION_MAX
 	};
@@ -72,6 +74,8 @@ public:
 		PIPELINE_VERSION_DEPTH_PASS_WITH_MATERIAL,
 		PIPELINE_VERSION_DEPTH_PASS_WITH_SDF,
 		PIPELINE_VERSION_DEPTH_PASS_MULTIVIEW,
+		PIPELINE_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS_MULTIVIEW,
+		PIPELINE_VERSION_DEPTH_PASS_WITH_NORMAL_AND_ROUGHNESS_AND_VOXEL_GI_MULTIVIEW,
 		PIPELINE_VERSION_COLOR_PASS,
 		PIPELINE_VERSION_MAX
 	};

+ 2 - 1
servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp

@@ -675,7 +675,8 @@ void RenderForwardMobile::_render_scene(RenderDataRD *p_render_data, const Color
 		RD::get_singleton()->draw_command_end_label(); // Setup Sky resolution buffers
 	}
 
-	_pre_opaque_render(p_render_data, false, false, false, RID(), RID());
+	RID null_rids[2];
+	_pre_opaque_render(p_render_data, false, false, false, null_rids, RID());
 
 	uint32_t spec_constant_base_flags = 0;
 

+ 9 - 5
servers/rendering/renderer_rd/renderer_compositor_rd.h

@@ -98,11 +98,15 @@ protected:
 	static uint64_t frame;
 
 public:
-	RendererLightStorage *get_light_storage() { return light_storage; };
-	RendererMaterialStorage *get_material_storage() { return material_storage; };
-	RendererMeshStorage *get_mesh_storage() { return mesh_storage; };
-	RendererParticlesStorage *get_particles_storage() { return particles_storage; };
-	RendererTextureStorage *get_texture_storage() { return texture_storage; };
+	RendererLightStorage *get_light_storage() { return light_storage; }
+	RendererMaterialStorage *get_material_storage() { return material_storage; }
+	RendererMeshStorage *get_mesh_storage() { return mesh_storage; }
+	RendererParticlesStorage *get_particles_storage() { return particles_storage; }
+	RendererTextureStorage *get_texture_storage() { return texture_storage; }
+	RendererGI *get_gi() {
+		ERR_FAIL_NULL_V(scene, nullptr);
+		return scene->get_gi();
+	}
 	RendererStorage *get_storage() { return storage; }
 	RendererCanvasRender *get_canvas() { return canvas; }
 	RendererSceneRender *get_scene() { return scene; }

+ 34 - 35
servers/rendering/renderer_rd/renderer_scene_render_rd.cpp

@@ -74,7 +74,7 @@ void RendererSceneRenderRD::sdfgi_update(RID p_render_buffers, RID p_environment
 		rb->sdfgi = nullptr;
 	}
 
-	RendererSceneGIRD::SDFGI *sdfgi = rb->sdfgi;
+	RendererRD::GI::SDFGI *sdfgi = rb->sdfgi;
 	if (sdfgi == nullptr) {
 		// re-create
 		rb->sdfgi = gi.create_sdfgi(env, p_world_position, requested_history_size);
@@ -95,9 +95,9 @@ int RendererSceneRenderRD::sdfgi_get_pending_region_count(RID p_render_buffers)
 
 	int dirty_count = 0;
 	for (uint32_t i = 0; i < rb->sdfgi->cascades.size(); i++) {
-		const RendererSceneGIRD::SDFGI::Cascade &c = rb->sdfgi->cascades[i];
+		const RendererRD::GI::SDFGI::Cascade &c = rb->sdfgi->cascades[i];
 
-		if (c.dirty_regions == RendererSceneGIRD::SDFGI::Cascade::DIRTY_ALL) {
+		if (c.dirty_regions == RendererRD::GI::SDFGI::Cascade::DIRTY_ALL) {
 			dirty_count++;
 		} else {
 			for (int j = 0; j < 3; j++) {
@@ -1533,7 +1533,7 @@ void RendererSceneRenderRD::voxel_gi_update(RID p_probe, bool p_update_light_ins
 	gi.voxel_gi_update(p_probe, p_update_light_instances, p_light_instances, p_dynamic_objects, this);
 }
 
-void RendererSceneRenderRD::_debug_sdfgi_probes(RID p_render_buffers, RD::DrawListID p_draw_list, RID p_framebuffer, const CameraMatrix &p_camera_with_transform) {
+void RendererSceneRenderRD::_debug_sdfgi_probes(RID p_render_buffers, RID p_framebuffer, const uint32_t p_view_count, const CameraMatrix *p_camera_with_transforms, bool p_will_continue_color, bool p_will_continue_depth) {
 	RenderBuffers *rb = render_buffers_owner.get_or_null(p_render_buffers);
 	ERR_FAIL_COND(!rb);
 
@@ -1541,7 +1541,7 @@ void RendererSceneRenderRD::_debug_sdfgi_probes(RID p_render_buffers, RD::DrawLi
 		return; //nothing to debug
 	}
 
-	rb->sdfgi->debug_probes(p_draw_list, p_framebuffer, p_camera_with_transform);
+	rb->sdfgi->debug_probes(p_framebuffer, p_view_count, p_camera_with_transforms, p_will_continue_color, p_will_continue_depth);
 }
 
 ////////////////////////////////
@@ -1950,17 +1950,7 @@ void RendererSceneRenderRD::_free_render_buffer_data(RenderBuffers *rb) {
 		rb->taa.prev_velocity = RID();
 	}
 
-	if (rb->ambient_buffer.is_valid()) {
-		RD::get_singleton()->free(rb->ambient_buffer);
-		RD::get_singleton()->free(rb->reflection_buffer);
-		rb->ambient_buffer = RID();
-		rb->reflection_buffer = RID();
-	}
-
-	if (rb->gi.voxel_gi_buffer.is_valid()) {
-		RD::get_singleton()->free(rb->gi.voxel_gi_buffer);
-		rb->gi.voxel_gi_buffer = RID();
-	}
+	rb->rbgi.free();
 }
 
 void RendererSceneRenderRD::_process_sss(RID p_render_buffers, const CameraMatrix &p_camera) {
@@ -2796,11 +2786,11 @@ void RendererSceneRenderRD::_render_buffers_debug_draw(RID p_render_buffers, RID
 		copy_effects->copy_to_fb_rect(_render_buffers_get_normal_texture(p_render_buffers), texture_storage->render_target_get_rd_framebuffer(rb->render_target), Rect2(Vector2(), rtsize), false, false);
 	}
 
-	if (debug_draw == RS::VIEWPORT_DEBUG_DRAW_GI_BUFFER && rb->ambient_buffer.is_valid()) {
+	if (debug_draw == RS::VIEWPORT_DEBUG_DRAW_GI_BUFFER && rb->rbgi.ambient_buffer.is_valid()) {
 		Size2 rtsize = texture_storage->render_target_get_size(rb->render_target);
-		RID ambient_texture = rb->ambient_buffer;
-		RID reflection_texture = rb->reflection_buffer;
-		copy_effects->copy_to_fb_rect(ambient_texture, texture_storage->render_target_get_rd_framebuffer(rb->render_target), Rect2(Vector2(), rtsize), false, false, false, true, reflection_texture);
+		RID ambient_texture = rb->rbgi.ambient_buffer;
+		RID reflection_texture = rb->rbgi.reflection_buffer;
+		copy_effects->copy_to_fb_rect(ambient_texture, texture_storage->render_target_get_rd_framebuffer(rb->render_target), Rect2(Vector2(), rtsize), false, false, false, true, reflection_texture, rb->view_count > 1);
 	}
 
 	if (debug_draw == RS::VIEWPORT_DEBUG_DRAW_OCCLUDERS) {
@@ -2869,10 +2859,10 @@ RID RendererSceneRenderRD::render_buffers_get_ssil_texture(RID p_render_buffers)
 RID RendererSceneRenderRD::render_buffers_get_voxel_gi_buffer(RID p_render_buffers) {
 	RenderBuffers *rb = render_buffers_owner.get_or_null(p_render_buffers);
 	ERR_FAIL_COND_V(!rb, RID());
-	if (rb->gi.voxel_gi_buffer.is_null()) {
-		rb->gi.voxel_gi_buffer = RD::get_singleton()->uniform_buffer_create(sizeof(RendererSceneGIRD::VoxelGIData) * RendererSceneGIRD::MAX_VOXEL_GI_INSTANCES);
+	if (rb->rbgi.voxel_gi_buffer.is_null()) {
+		rb->rbgi.voxel_gi_buffer = RD::get_singleton()->uniform_buffer_create(sizeof(RendererRD::GI::VoxelGIData) * RendererRD::GI::MAX_VOXEL_GI_INSTANCES);
 	}
-	return rb->gi.voxel_gi_buffer;
+	return rb->rbgi.voxel_gi_buffer;
 }
 
 RID RendererSceneRenderRD::render_buffers_get_default_voxel_gi_buffer() {
@@ -2882,12 +2872,13 @@ RID RendererSceneRenderRD::render_buffers_get_default_voxel_gi_buffer() {
 RID RendererSceneRenderRD::render_buffers_get_gi_ambient_texture(RID p_render_buffers) {
 	RenderBuffers *rb = render_buffers_owner.get_or_null(p_render_buffers);
 	ERR_FAIL_COND_V(!rb, RID());
-	return rb->ambient_buffer;
+
+	return rb->rbgi.ambient_buffer;
 }
 RID RendererSceneRenderRD::render_buffers_get_gi_reflection_texture(RID p_render_buffers) {
 	RenderBuffers *rb = render_buffers_owner.get_or_null(p_render_buffers);
 	ERR_FAIL_COND_V(!rb, RID());
-	return rb->reflection_buffer;
+	return rb->rbgi.reflection_buffer;
 }
 
 uint32_t RendererSceneRenderRD::render_buffers_get_sdfgi_cascade_count(RID p_render_buffers) const {
@@ -2925,7 +2916,7 @@ Vector3i RendererSceneRenderRD::render_buffers_get_sdfgi_cascade_probe_offset(RI
 	ERR_FAIL_COND_V(!rb, Vector3i());
 	ERR_FAIL_COND_V(!rb->sdfgi, Vector3i());
 	ERR_FAIL_UNSIGNED_INDEX_V(p_cascade, rb->sdfgi->cascades.size(), Vector3i());
-	int32_t probe_divisor = rb->sdfgi->cascade_size / RendererSceneGIRD::SDFGI::PROBE_DIVISOR;
+	int32_t probe_divisor = rb->sdfgi->cascade_size / RendererRD::GI::SDFGI::PROBE_DIVISOR;
 
 	return rb->sdfgi->cascades[p_cascade].position / probe_divisor;
 }
@@ -4615,8 +4606,8 @@ void RendererSceneRenderRD::_update_volumetric_fog(RID p_render_buffers, RID p_e
 			RD::Uniform u;
 			u.uniform_type = RD::UNIFORM_TYPE_TEXTURE;
 			u.binding = 12;
-			for (int i = 0; i < RendererSceneGIRD::MAX_VOXEL_GI_INSTANCES; i++) {
-				u.append_id(rb->gi.voxel_gi_textures[i]);
+			for (int i = 0; i < RendererRD::GI::MAX_VOXEL_GI_INSTANCES; i++) {
+				u.append_id(rb->rbgi.voxel_gi_textures[i]);
 			}
 			uniforms.push_back(u);
 			copy_uniforms.push_back(u);
@@ -4930,7 +4921,7 @@ void RendererSceneRenderRD::_pre_resolve_render(RenderDataRD *p_render_data, boo
 	}
 }
 
-void RendererSceneRenderRD::_pre_opaque_render(RenderDataRD *p_render_data, bool p_use_ssao, bool p_use_ssil, bool p_use_gi, RID p_normal_roughness_buffer, RID p_voxel_gi_buffer) {
+void RendererSceneRenderRD::_pre_opaque_render(RenderDataRD *p_render_data, bool p_use_ssao, bool p_use_ssil, bool p_use_gi, RID *p_normal_roughness_views, RID p_voxel_gi_buffer) {
 	// Render shadows while GI is rendering, due to how barriers are handled, this should happen at the same time
 	RendererRD::LightStorage *light_storage = RendererRD::LightStorage::get_singleton();
 
@@ -5005,7 +4996,7 @@ void RendererSceneRenderRD::_pre_opaque_render(RenderDataRD *p_render_data, bool
 
 	//start GI
 	if (render_gi) {
-		gi.process_gi(p_render_data->render_buffers, p_normal_roughness_buffer, p_voxel_gi_buffer, p_render_data->environment, p_render_data->cam_projection, p_render_data->cam_transform, *p_render_data->voxel_gi_instances, this);
+		gi.process_gi(p_render_data->render_buffers, p_normal_roughness_views, p_voxel_gi_buffer, p_render_data->environment, p_render_data->view_count, p_render_data->view_projection, p_render_data->view_eye_offset, p_render_data->cam_transform, *p_render_data->voxel_gi_instances, this);
 	}
 
 	//Do shadow rendering (in parallel with GI)
@@ -5046,11 +5037,13 @@ void RendererSceneRenderRD::_pre_opaque_render(RenderDataRD *p_render_data, bool
 		}
 
 		if (p_use_ssao) {
-			_process_ssao(p_render_data->render_buffers, p_render_data->environment, p_normal_roughness_buffer, p_render_data->cam_projection);
+			// TODO make these proper stereo and thus use p_normal_roughness_views correctly
+			_process_ssao(p_render_data->render_buffers, p_render_data->environment, p_normal_roughness_views[0], p_render_data->cam_projection);
 		}
 
 		if (p_use_ssil) {
-			_process_ssil(p_render_data->render_buffers, p_render_data->environment, p_normal_roughness_buffer, p_render_data->cam_projection, p_render_data->cam_transform);
+			// TODO make these proper stereo and thus use p_normal_roughness_views correctly
+			_process_ssil(p_render_data->render_buffers, p_render_data->environment, p_normal_roughness_views[0], p_render_data->cam_projection, p_render_data->cam_transform);
 		}
 	}
 
@@ -5195,7 +5188,7 @@ void RendererSceneRenderRD::render_scene(RID p_render_buffers, const CameraData
 	//assign render indices to voxel_gi_instances
 	if (is_dynamic_gi_supported()) {
 		for (uint32_t i = 0; i < (uint32_t)p_voxel_gi_instances.size(); i++) {
-			RendererSceneGIRD::VoxelGIInstance *voxel_gi_inst = gi.voxel_gi_instance_owner.get_or_null(p_voxel_gi_instances[i]);
+			RendererRD::GI::VoxelGIInstance *voxel_gi_inst = gi.voxel_gi_instance_owner.get_or_null(p_voxel_gi_instances[i]);
 			if (voxel_gi_inst) {
 				voxel_gi_inst->render_index = i;
 			}
@@ -5249,7 +5242,13 @@ void RendererSceneRenderRD::render_scene(RID p_render_buffers, const CameraData
 
 		_render_buffers_debug_draw(p_render_buffers, p_shadow_atlas, p_occluder_debug_tex);
 		if (debug_draw == RS::VIEWPORT_DEBUG_DRAW_SDFGI && rb != nullptr && rb->sdfgi != nullptr) {
-			rb->sdfgi->debug_draw(render_data.cam_projection, render_data.cam_transform, rb->width, rb->height, rb->render_target, rb->texture);
+			Vector<RID> view_rids;
+
+			for (int v = 0; v < rb->views.size(); v++) {
+				view_rids.push_back(rb->views[v].view_texture);
+			}
+
+			rb->sdfgi->debug_draw(render_data.view_count, render_data.view_projection, render_data.cam_transform, rb->width, rb->height, rb->render_target, rb->texture, view_rids);
 		}
 	}
 }
@@ -5518,7 +5517,7 @@ bool RendererSceneRenderRD::free(RID p_rid) {
 	} else if (lightmap_instance_owner.owns(p_rid)) {
 		lightmap_instance_owner.free(p_rid);
 	} else if (gi.voxel_gi_instance_owner.owns(p_rid)) {
-		RendererSceneGIRD::VoxelGIInstance *voxel_gi = gi.voxel_gi_instance_owner.get_or_null(p_rid);
+		RendererRD::GI::VoxelGIInstance *voxel_gi = gi.voxel_gi_instance_owner.get_or_null(p_rid);
 		if (voxel_gi->texture.is_valid()) {
 			RD::get_singleton()->free(voxel_gi->texture);
 			RD::get_singleton()->free(voxel_gi->write_buffer);

+ 11 - 10
servers/rendering/renderer_rd/renderer_scene_render_rd.h

@@ -38,8 +38,8 @@
 #include "servers/rendering/renderer_rd/effects/bokeh_dof.h"
 #include "servers/rendering/renderer_rd/effects/copy_effects.h"
 #include "servers/rendering/renderer_rd/effects/tone_mapper.h"
+#include "servers/rendering/renderer_rd/environment/gi.h"
 #include "servers/rendering/renderer_rd/renderer_scene_environment_rd.h"
-#include "servers/rendering/renderer_rd/renderer_scene_gi_rd.h"
 #include "servers/rendering/renderer_rd/renderer_scene_sky_rd.h"
 #include "servers/rendering/renderer_rd/renderer_storage_rd.h"
 #include "servers/rendering/renderer_rd/shaders/volumetric_fog.glsl.gen.h"
@@ -99,7 +99,7 @@ struct RenderDataRD {
 
 class RendererSceneRenderRD : public RendererSceneRender {
 	friend RendererSceneSkyRD;
-	friend RendererSceneGIRD;
+	friend RendererRD::GI;
 
 protected:
 	RendererStorageRD *storage = nullptr;
@@ -131,7 +131,7 @@ protected:
 	virtual void _render_sdfgi(RID p_render_buffers, const Vector3i &p_from, const Vector3i &p_size, const AABB &p_bounds, const PagedArray<GeometryInstance *> &p_instances, const RID &p_albedo_texture, const RID &p_emission_texture, const RID &p_emission_aniso_texture, const RID &p_geom_facing_texture) = 0;
 	virtual void _render_particle_collider_heightfield(RID p_fb, const Transform3D &p_cam_transform, const CameraMatrix &p_cam_projection, const PagedArray<GeometryInstance *> &p_instances) = 0;
 
-	void _debug_sdfgi_probes(RID p_render_buffers, RD::DrawListID p_draw_list, RID p_framebuffer, const CameraMatrix &p_camera_with_transform);
+	void _debug_sdfgi_probes(RID p_render_buffers, RID p_framebuffer, uint32_t p_view_count, const CameraMatrix *p_camera_with_transforms, bool p_will_continue_color, bool p_will_continue_depth);
 	void _debug_draw_cluster(RID p_render_buffers);
 
 	RenderBufferData *render_buffers_get_data(RID p_render_buffers);
@@ -151,7 +151,7 @@ protected:
 	void _post_prepass_render(RenderDataRD *p_render_data, bool p_use_gi);
 	void _pre_resolve_render(RenderDataRD *p_render_data, bool p_use_gi);
 
-	void _pre_opaque_render(RenderDataRD *p_render_data, bool p_use_ssao, bool p_use_ssil, bool p_use_gi, RID p_normal_roughness_buffer, RID p_voxel_gi_buffer);
+	void _pre_opaque_render(RenderDataRD *p_render_data, bool p_use_ssao, bool p_use_ssil, bool p_use_gi, RID *p_normal_roughness_views, RID p_voxel_gi_buffer);
 
 	void _render_buffers_copy_screen_texture(const RenderDataRD *p_render_data);
 	void _render_buffers_copy_depth_texture(const RenderDataRD *p_render_data);
@@ -163,7 +163,7 @@ protected:
 	PagedArrayPool<GeometryInstance *> cull_argument_pool;
 	PagedArray<GeometryInstance *> cull_argument; //need this to exist
 
-	RendererSceneGIRD gi;
+	RendererRD::GI gi;
 	RendererSceneSkyRD sky;
 
 	RendererSceneEnvironmentRD *get_environment(RID p_environment) {
@@ -503,9 +503,9 @@ private:
 		};
 		Vector<View> views;
 
-		RendererSceneGIRD::SDFGI *sdfgi = nullptr;
+		RendererRD::GI::SDFGI *sdfgi = nullptr;
 		VolumetricFog *volumetric_fog = nullptr;
-		RendererSceneGIRD::RenderBuffersGI gi;
+		RendererRD::GI::RenderBuffersGI rbgi;
 
 		ClusterBuilderRD *cluster_builder = nullptr;
 
@@ -606,9 +606,6 @@ private:
 			RID temp;
 			RID prev_velocity; // Last frame velocity buffer
 		} taa;
-
-		RID ambient_buffer;
-		RID reflection_buffer;
 	};
 
 	/* GI */
@@ -997,6 +994,10 @@ public:
 	virtual Transform3D geometry_instance_get_transform(GeometryInstance *p_instance) = 0;
 	virtual AABB geometry_instance_get_aabb(GeometryInstance *p_instance) = 0;
 
+	/* GI */
+
+	RendererRD::GI *get_gi() { return &gi; }
+
 	/* SHADOW ATLAS API */
 
 	virtual RID shadow_atlas_create() override;

+ 6 - 338
servers/rendering/renderer_rd/renderer_storage_rd.cpp

@@ -35,6 +35,7 @@
 #include "core/io/resource_loader.h"
 #include "core/math/math_defs.h"
 #include "renderer_compositor_rd.h"
+#include "servers/rendering/renderer_rd/environment/gi.h"
 #include "servers/rendering/renderer_rd/storage_rd/light_storage.h"
 #include "servers/rendering/renderer_rd/storage_rd/mesh_storage.h"
 #include "servers/rendering/renderer_rd/storage_rd/particles_storage.h"
@@ -173,336 +174,6 @@ void RendererStorageRD::visibility_notifier_call(RID p_notifier, bool p_enter, b
 	}
 }
 
-/* VOXEL GI */
-
-RID RendererStorageRD::voxel_gi_allocate() {
-	return voxel_gi_owner.allocate_rid();
-}
-void RendererStorageRD::voxel_gi_initialize(RID p_voxel_gi) {
-	voxel_gi_owner.initialize_rid(p_voxel_gi, VoxelGI());
-}
-
-void RendererStorageRD::voxel_gi_allocate_data(RID p_voxel_gi, const Transform3D &p_to_cell_xform, const AABB &p_aabb, const Vector3i &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts) {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND(!voxel_gi);
-
-	if (voxel_gi->octree_buffer.is_valid()) {
-		RD::get_singleton()->free(voxel_gi->octree_buffer);
-		RD::get_singleton()->free(voxel_gi->data_buffer);
-		if (voxel_gi->sdf_texture.is_valid()) {
-			RD::get_singleton()->free(voxel_gi->sdf_texture);
-		}
-
-		voxel_gi->sdf_texture = RID();
-		voxel_gi->octree_buffer = RID();
-		voxel_gi->data_buffer = RID();
-		voxel_gi->octree_buffer_size = 0;
-		voxel_gi->data_buffer_size = 0;
-		voxel_gi->cell_count = 0;
-	}
-
-	voxel_gi->to_cell_xform = p_to_cell_xform;
-	voxel_gi->bounds = p_aabb;
-	voxel_gi->octree_size = p_octree_size;
-	voxel_gi->level_counts = p_level_counts;
-
-	if (p_octree_cells.size()) {
-		ERR_FAIL_COND(p_octree_cells.size() % 32 != 0); //cells size must be a multiple of 32
-
-		uint32_t cell_count = p_octree_cells.size() / 32;
-
-		ERR_FAIL_COND(p_data_cells.size() != (int)cell_count * 16); //see that data size matches
-
-		voxel_gi->cell_count = cell_count;
-		voxel_gi->octree_buffer = RD::get_singleton()->storage_buffer_create(p_octree_cells.size(), p_octree_cells);
-		voxel_gi->octree_buffer_size = p_octree_cells.size();
-		voxel_gi->data_buffer = RD::get_singleton()->storage_buffer_create(p_data_cells.size(), p_data_cells);
-		voxel_gi->data_buffer_size = p_data_cells.size();
-
-		if (p_distance_field.size()) {
-			RD::TextureFormat tf;
-			tf.format = RD::DATA_FORMAT_R8_UNORM;
-			tf.width = voxel_gi->octree_size.x;
-			tf.height = voxel_gi->octree_size.y;
-			tf.depth = voxel_gi->octree_size.z;
-			tf.texture_type = RD::TEXTURE_TYPE_3D;
-			tf.usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_CAN_UPDATE_BIT | RD::TEXTURE_USAGE_CAN_COPY_FROM_BIT;
-			Vector<Vector<uint8_t>> s;
-			s.push_back(p_distance_field);
-			voxel_gi->sdf_texture = RD::get_singleton()->texture_create(tf, RD::TextureView(), s);
-		}
-#if 0
-			{
-				RD::TextureFormat tf;
-				tf.format = RD::DATA_FORMAT_R8_UNORM;
-				tf.width = voxel_gi->octree_size.x;
-				tf.height = voxel_gi->octree_size.y;
-				tf.depth = voxel_gi->octree_size.z;
-				tf.type = RD::TEXTURE_TYPE_3D;
-				tf.usage_bits = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_STORAGE_BIT | RD::TEXTURE_USAGE_CAN_COPY_TO_BIT;
-				tf.shareable_formats.push_back(RD::DATA_FORMAT_R8_UNORM);
-				tf.shareable_formats.push_back(RD::DATA_FORMAT_R8_UINT);
-				voxel_gi->sdf_texture = RD::get_singleton()->texture_create(tf, RD::TextureView());
-			}
-			RID shared_tex;
-			{
-				RD::TextureView tv;
-				tv.format_override = RD::DATA_FORMAT_R8_UINT;
-				shared_tex = RD::get_singleton()->texture_create_shared(tv, voxel_gi->sdf_texture);
-			}
-			//update SDF texture
-			Vector<RD::Uniform> uniforms;
-			{
-				RD::Uniform u;
-				u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
-				u.binding = 1;
-				u.append_id(voxel_gi->octree_buffer);
-				uniforms.push_back(u);
-			}
-			{
-				RD::Uniform u;
-				u.uniform_type = RD::UNIFORM_TYPE_STORAGE_BUFFER;
-				u.binding = 2;
-				u.append_id(voxel_gi->data_buffer);
-				uniforms.push_back(u);
-			}
-			{
-				RD::Uniform u;
-				u.uniform_type = RD::UNIFORM_TYPE_IMAGE;
-				u.binding = 3;
-				u.append_id(shared_tex);
-				uniforms.push_back(u);
-			}
-
-			RID uniform_set = RD::get_singleton()->uniform_set_create(uniforms, voxel_gi_sdf_shader_version_shader, 0);
-
-			{
-				uint32_t push_constant[4] = { 0, 0, 0, 0 };
-
-				for (int i = 0; i < voxel_gi->level_counts.size() - 1; i++) {
-					push_constant[0] += voxel_gi->level_counts[i];
-				}
-				push_constant[1] = push_constant[0] + voxel_gi->level_counts[voxel_gi->level_counts.size() - 1];
-
-				print_line("offset: " + itos(push_constant[0]));
-				print_line("size: " + itos(push_constant[1]));
-				//create SDF
-				RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();
-				RD::get_singleton()->compute_list_bind_compute_pipeline(compute_list, voxel_gi_sdf_shader_pipeline);
-				RD::get_singleton()->compute_list_bind_uniform_set(compute_list, uniform_set, 0);
-				RD::get_singleton()->compute_list_set_push_constant(compute_list, push_constant, sizeof(uint32_t) * 4);
-				RD::get_singleton()->compute_list_dispatch(compute_list, voxel_gi->octree_size.x / 4, voxel_gi->octree_size.y / 4, voxel_gi->octree_size.z / 4);
-				RD::get_singleton()->compute_list_end();
-			}
-
-			RD::get_singleton()->free(uniform_set);
-			RD::get_singleton()->free(shared_tex);
-		}
-#endif
-	}
-
-	voxel_gi->version++;
-	voxel_gi->data_version++;
-
-	voxel_gi->dependency.changed_notify(DEPENDENCY_CHANGED_AABB);
-}
-
-AABB RendererStorageRD::voxel_gi_get_bounds(RID p_voxel_gi) const {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND_V(!voxel_gi, AABB());
-
-	return voxel_gi->bounds;
-}
-
-Vector3i RendererStorageRD::voxel_gi_get_octree_size(RID p_voxel_gi) const {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND_V(!voxel_gi, Vector3i());
-	return voxel_gi->octree_size;
-}
-
-Vector<uint8_t> RendererStorageRD::voxel_gi_get_octree_cells(RID p_voxel_gi) const {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND_V(!voxel_gi, Vector<uint8_t>());
-
-	if (voxel_gi->octree_buffer.is_valid()) {
-		return RD::get_singleton()->buffer_get_data(voxel_gi->octree_buffer);
-	}
-	return Vector<uint8_t>();
-}
-
-Vector<uint8_t> RendererStorageRD::voxel_gi_get_data_cells(RID p_voxel_gi) const {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND_V(!voxel_gi, Vector<uint8_t>());
-
-	if (voxel_gi->data_buffer.is_valid()) {
-		return RD::get_singleton()->buffer_get_data(voxel_gi->data_buffer);
-	}
-	return Vector<uint8_t>();
-}
-
-Vector<uint8_t> RendererStorageRD::voxel_gi_get_distance_field(RID p_voxel_gi) const {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND_V(!voxel_gi, Vector<uint8_t>());
-
-	if (voxel_gi->data_buffer.is_valid()) {
-		return RD::get_singleton()->texture_get_data(voxel_gi->sdf_texture, 0);
-	}
-	return Vector<uint8_t>();
-}
-
-Vector<int> RendererStorageRD::voxel_gi_get_level_counts(RID p_voxel_gi) const {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND_V(!voxel_gi, Vector<int>());
-
-	return voxel_gi->level_counts;
-}
-
-Transform3D RendererStorageRD::voxel_gi_get_to_cell_xform(RID p_voxel_gi) const {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND_V(!voxel_gi, Transform3D());
-
-	return voxel_gi->to_cell_xform;
-}
-
-void RendererStorageRD::voxel_gi_set_dynamic_range(RID p_voxel_gi, float p_range) {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND(!voxel_gi);
-
-	voxel_gi->dynamic_range = p_range;
-	voxel_gi->version++;
-}
-
-float RendererStorageRD::voxel_gi_get_dynamic_range(RID p_voxel_gi) const {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND_V(!voxel_gi, 0);
-
-	return voxel_gi->dynamic_range;
-}
-
-void RendererStorageRD::voxel_gi_set_propagation(RID p_voxel_gi, float p_range) {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND(!voxel_gi);
-
-	voxel_gi->propagation = p_range;
-	voxel_gi->version++;
-}
-
-float RendererStorageRD::voxel_gi_get_propagation(RID p_voxel_gi) const {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND_V(!voxel_gi, 0);
-	return voxel_gi->propagation;
-}
-
-void RendererStorageRD::voxel_gi_set_energy(RID p_voxel_gi, float p_energy) {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND(!voxel_gi);
-
-	voxel_gi->energy = p_energy;
-}
-
-float RendererStorageRD::voxel_gi_get_energy(RID p_voxel_gi) const {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND_V(!voxel_gi, 0);
-	return voxel_gi->energy;
-}
-
-void RendererStorageRD::voxel_gi_set_bias(RID p_voxel_gi, float p_bias) {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND(!voxel_gi);
-
-	voxel_gi->bias = p_bias;
-}
-
-float RendererStorageRD::voxel_gi_get_bias(RID p_voxel_gi) const {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND_V(!voxel_gi, 0);
-	return voxel_gi->bias;
-}
-
-void RendererStorageRD::voxel_gi_set_normal_bias(RID p_voxel_gi, float p_normal_bias) {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND(!voxel_gi);
-
-	voxel_gi->normal_bias = p_normal_bias;
-}
-
-float RendererStorageRD::voxel_gi_get_normal_bias(RID p_voxel_gi) const {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND_V(!voxel_gi, 0);
-	return voxel_gi->normal_bias;
-}
-
-void RendererStorageRD::voxel_gi_set_anisotropy_strength(RID p_voxel_gi, float p_strength) {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND(!voxel_gi);
-
-	voxel_gi->anisotropy_strength = p_strength;
-}
-
-float RendererStorageRD::voxel_gi_get_anisotropy_strength(RID p_voxel_gi) const {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND_V(!voxel_gi, 0);
-	return voxel_gi->anisotropy_strength;
-}
-
-void RendererStorageRD::voxel_gi_set_interior(RID p_voxel_gi, bool p_enable) {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND(!voxel_gi);
-
-	voxel_gi->interior = p_enable;
-}
-
-void RendererStorageRD::voxel_gi_set_use_two_bounces(RID p_voxel_gi, bool p_enable) {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND(!voxel_gi);
-
-	voxel_gi->use_two_bounces = p_enable;
-	voxel_gi->version++;
-}
-
-bool RendererStorageRD::voxel_gi_is_using_two_bounces(RID p_voxel_gi) const {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND_V(!voxel_gi, false);
-	return voxel_gi->use_two_bounces;
-}
-
-bool RendererStorageRD::voxel_gi_is_interior(RID p_voxel_gi) const {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND_V(!voxel_gi, 0);
-	return voxel_gi->interior;
-}
-
-uint32_t RendererStorageRD::voxel_gi_get_version(RID p_voxel_gi) {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND_V(!voxel_gi, 0);
-	return voxel_gi->version;
-}
-
-uint32_t RendererStorageRD::voxel_gi_get_data_version(RID p_voxel_gi) {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND_V(!voxel_gi, 0);
-	return voxel_gi->data_version;
-}
-
-RID RendererStorageRD::voxel_gi_get_octree_buffer(RID p_voxel_gi) const {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND_V(!voxel_gi, RID());
-	return voxel_gi->octree_buffer;
-}
-
-RID RendererStorageRD::voxel_gi_get_data_buffer(RID p_voxel_gi) const {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND_V(!voxel_gi, RID());
-	return voxel_gi->data_buffer;
-}
-
-RID RendererStorageRD::voxel_gi_get_sdf_texture(RID p_voxel_gi) {
-	VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_voxel_gi);
-	ERR_FAIL_COND_V(!voxel_gi, RID());
-
-	return voxel_gi->sdf_texture;
-}
-
 /* misc */
 
 void RendererStorageRD::base_update_dependency(RID p_base, DependencyTracker *p_instance) {
@@ -521,8 +192,8 @@ void RendererStorageRD::base_update_dependency(RID p_base, DependencyTracker *p_
 	} else if (RendererRD::TextureStorage::get_singleton()->owns_decal(p_base)) {
 		RendererRD::Decal *decal = RendererRD::TextureStorage::get_singleton()->get_decal(p_base);
 		p_instance->update_dependency(&decal->dependency);
-	} else if (voxel_gi_owner.owns(p_base)) {
-		VoxelGI *gip = voxel_gi_owner.get_or_null(p_base);
+	} else if (RendererRD::GI::get_singleton()->owns_voxel_gi(p_base)) {
+		RendererRD::GI::VoxelGI *gip = RendererRD::GI::get_singleton()->get_voxel_gi(p_base);
 		p_instance->update_dependency(&gip->dependency);
 	} else if (RendererRD::LightStorage::get_singleton()->owns_lightmap(p_base)) {
 		RendererRD::Lightmap *lm = RendererRD::LightStorage::get_singleton()->get_lightmap(p_base);
@@ -558,7 +229,7 @@ RS::InstanceType RendererStorageRD::get_base_type(RID p_rid) const {
 	if (RendererRD::TextureStorage::get_singleton()->owns_decal(p_rid)) {
 		return RS::INSTANCE_DECAL;
 	}
-	if (voxel_gi_owner.owns(p_rid)) {
+	if (RendererRD::GI::get_singleton()->owns_voxel_gi(p_rid)) {
 		return RS::INSTANCE_VOXEL_GI;
 	}
 	if (RendererRD::LightStorage::get_singleton()->owns_light(p_rid)) {
@@ -636,11 +307,8 @@ bool RendererStorageRD::free(RID p_rid) {
 		RendererRD::LightStorage::get_singleton()->reflection_probe_free(p_rid);
 	} else if (RendererRD::TextureStorage::get_singleton()->owns_decal(p_rid)) {
 		RendererRD::TextureStorage::get_singleton()->decal_free(p_rid);
-	} else if (voxel_gi_owner.owns(p_rid)) {
-		voxel_gi_allocate_data(p_rid, Transform3D(), AABB(), Vector3i(), Vector<uint8_t>(), Vector<uint8_t>(), Vector<uint8_t>(), Vector<int>()); //deallocate
-		VoxelGI *voxel_gi = voxel_gi_owner.get_or_null(p_rid);
-		voxel_gi->dependency.deleted_notify(p_rid);
-		voxel_gi_owner.free(p_rid);
+	} else if (RendererRD::GI::get_singleton()->owns_voxel_gi(p_rid)) {
+		RendererRD::GI::get_singleton()->voxel_gi_free(p_rid);
 	} else if (RendererRD::LightStorage::get_singleton()->owns_lightmap(p_rid)) {
 		RendererRD::LightStorage::get_singleton()->lightmap_free(p_rid);
 	} else if (RendererRD::LightStorage::get_singleton()->owns_light(p_rid)) {

+ 1 - 85
servers/rendering/renderer_rd/renderer_storage_rd.h

@@ -36,7 +36,7 @@
 #include "core/templates/rid_owner.h"
 #include "servers/rendering/renderer_compositor.h"
 #include "servers/rendering/renderer_rd/effects_rd.h"
-#include "servers/rendering/renderer_rd/shaders/voxel_gi_sdf.glsl.gen.h"
+#include "servers/rendering/renderer_rd/shaders/environment/voxel_gi_sdf.glsl.gen.h"
 #include "servers/rendering/renderer_rd/storage_rd/material_storage.h"
 #include "servers/rendering/renderer_scene_render.h"
 #include "servers/rendering/rendering_device.h"
@@ -147,42 +147,6 @@ private:
 
 	mutable RID_Owner<VisibilityNotifier> visibility_notifier_owner;
 
-	/* VOXEL GI */
-
-	struct VoxelGI {
-		RID octree_buffer;
-		RID data_buffer;
-		RID sdf_texture;
-
-		uint32_t octree_buffer_size = 0;
-		uint32_t data_buffer_size = 0;
-
-		Vector<int> level_counts;
-
-		int cell_count = 0;
-
-		Transform3D to_cell_xform;
-		AABB bounds;
-		Vector3i octree_size;
-
-		float dynamic_range = 2.0;
-		float energy = 1.0;
-		float bias = 1.4;
-		float normal_bias = 0.0;
-		float propagation = 0.7;
-		bool interior = false;
-		bool use_two_bounces = false;
-
-		float anisotropy_strength = 0.5;
-
-		uint32_t version = 1;
-		uint32_t data_version = 1;
-
-		Dependency dependency;
-	};
-
-	mutable RID_Owner<VoxelGI, true> voxel_gi_owner;
-
 	/* EFFECTS */
 
 	EffectsRD *effects = nullptr;
@@ -192,54 +156,6 @@ public:
 
 	void base_update_dependency(RID p_base, DependencyTracker *p_instance);
 
-	/* VOXEL GI API */
-
-	RID voxel_gi_allocate();
-	void voxel_gi_initialize(RID p_voxel_gi);
-
-	void voxel_gi_allocate_data(RID p_voxel_gi, const Transform3D &p_to_cell_xform, const AABB &p_aabb, const Vector3i &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts);
-
-	AABB voxel_gi_get_bounds(RID p_voxel_gi) const;
-	Vector3i voxel_gi_get_octree_size(RID p_voxel_gi) const;
-	Vector<uint8_t> voxel_gi_get_octree_cells(RID p_voxel_gi) const;
-	Vector<uint8_t> voxel_gi_get_data_cells(RID p_voxel_gi) const;
-	Vector<uint8_t> voxel_gi_get_distance_field(RID p_voxel_gi) const;
-
-	Vector<int> voxel_gi_get_level_counts(RID p_voxel_gi) const;
-	Transform3D voxel_gi_get_to_cell_xform(RID p_voxel_gi) const;
-
-	void voxel_gi_set_dynamic_range(RID p_voxel_gi, float p_range);
-	float voxel_gi_get_dynamic_range(RID p_voxel_gi) const;
-
-	void voxel_gi_set_propagation(RID p_voxel_gi, float p_range);
-	float voxel_gi_get_propagation(RID p_voxel_gi) const;
-
-	void voxel_gi_set_energy(RID p_voxel_gi, float p_energy);
-	float voxel_gi_get_energy(RID p_voxel_gi) const;
-
-	void voxel_gi_set_bias(RID p_voxel_gi, float p_bias);
-	float voxel_gi_get_bias(RID p_voxel_gi) const;
-
-	void voxel_gi_set_normal_bias(RID p_voxel_gi, float p_range);
-	float voxel_gi_get_normal_bias(RID p_voxel_gi) const;
-
-	void voxel_gi_set_interior(RID p_voxel_gi, bool p_enable);
-	bool voxel_gi_is_interior(RID p_voxel_gi) const;
-
-	void voxel_gi_set_use_two_bounces(RID p_voxel_gi, bool p_enable);
-	bool voxel_gi_is_using_two_bounces(RID p_voxel_gi) const;
-
-	void voxel_gi_set_anisotropy_strength(RID p_voxel_gi, float p_strength);
-	float voxel_gi_get_anisotropy_strength(RID p_voxel_gi) const;
-
-	uint32_t voxel_gi_get_version(RID p_probe);
-	uint32_t voxel_gi_get_data_version(RID p_probe);
-
-	RID voxel_gi_get_octree_buffer(RID p_voxel_gi) const;
-	RID voxel_gi_get_data_buffer(RID p_voxel_gi) const;
-
-	RID voxel_gi_get_sdf_texture(RID p_voxel_gi);
-
 	/* FOG VOLUMES */
 
 	virtual RID fog_volume_allocate();

+ 1 - 0
servers/rendering/renderer_rd/shaders/SCsub

@@ -17,3 +17,4 @@ if "RD_GLSL" in env["BUILDERS"]:
         env.RD_GLSL(glsl_file)
 
 SConscript("effects/SCsub")
+SConscript("environment/SCsub")

+ 0 - 0
servers/rendering/renderer_rd/shaders/resolve.glsl → servers/rendering/renderer_rd/shaders/effects/resolve.glsl


+ 17 - 0
servers/rendering/renderer_rd/shaders/environment/SCsub

@@ -0,0 +1,17 @@
+#!/usr/bin/env python
+
+Import("env")
+
+if "RD_GLSL" in env["BUILDERS"]:
+    # find all include files
+    gl_include_files = [str(f) for f in Glob("*_inc.glsl")]
+
+    # find all shader code(all glsl files excluding our include files)
+    glsl_files = [str(f) for f in Glob("*.glsl") if str(f) not in gl_include_files]
+
+    # make sure we recompile shaders if include files change
+    env.Depends([f + ".gen.h" for f in glsl_files], gl_include_files)
+
+    # compile shaders
+    for glsl_file in glsl_files:
+        env.RD_GLSL(glsl_file)

+ 33 - 11
servers/rendering/renderer_rd/shaders/gi.glsl → servers/rendering/renderer_rd/shaders/environment/gi.glsl

@@ -86,19 +86,29 @@ voxel_gi_instances;
 
 layout(set = 0, binding = 17) uniform texture3D voxel_gi_textures[MAX_VOXEL_GI_INSTANCES];
 
-layout(push_constant, std430) uniform Params {
-	ivec2 screen_size;
-	float z_near;
-	float z_far;
+layout(set = 0, binding = 18, std140) uniform SceneData {
+	mat4x4 inv_projection[2];
+	mat4x4 cam_transform;
+	vec4 eye_offset[2];
 
-	vec4 proj_info;
+	ivec2 screen_size;
+	float pad1;
+	float pad2;
+}
+scene_data;
 
+layout(push_constant, std430) uniform Params {
+	uint view_index;
 	uint max_voxel_gi_instances;
 	bool high_quality_vct;
 	bool orthogonal;
-	uint pad;
 
-	mat3x4 cam_rotation;
+	vec4 proj_info;
+
+	float z_near;
+	float z_far;
+	float pad1;
+	float pad2;
 }
 params;
 
@@ -130,6 +140,16 @@ vec4 blend_color(vec4 src, vec4 dst) {
 }
 
 vec3 reconstruct_position(ivec2 screen_pos) {
+#ifdef USE_MULTIVIEW
+	vec4 pos;
+	pos.xy = (2.0 * vec2(screen_pos) / vec2(scene_data.screen_size)) - 1.0;
+	pos.z = texelFetch(sampler2D(depth_buffer, linear_sampler), screen_pos, 0).r * 2.0 - 1.0;
+	pos.w = 1.0;
+
+	pos = scene_data.inv_projection[params.view_index] * pos;
+
+	return pos.xyz / pos.w;
+#else
 	vec3 pos;
 	pos.z = texelFetch(sampler2D(depth_buffer, linear_sampler), screen_pos, 0).r;
 
@@ -147,6 +167,7 @@ vec3 reconstruct_position(ivec2 screen_pos) {
 	}
 
 	return pos;
+#endif
 }
 
 void sdfvoxel_gi_process(uint cascade, vec3 cascade_pos, vec3 cam_pos, vec3 cam_normal, vec3 cam_specular_normal, float roughness, out vec3 diffuse_light, out vec3 specular_light) {
@@ -579,9 +600,10 @@ void process_gi(ivec2 pos, vec3 vertex, inout vec4 ambient_light, inout vec4 ref
 	if (normal.length() > 0.5) {
 		//valid normal, can do GI
 		float roughness = normal_roughness.w;
-		vertex = mat3(params.cam_rotation) * vertex;
-		normal = normalize(mat3(params.cam_rotation) * normal);
-		vec3 reflection = normalize(reflect(normalize(vertex), normal));
+		vec3 view = -normalize(mat3(scene_data.cam_transform) * (vertex - scene_data.eye_offset[params.view_index].xyz));
+		vertex = mat3(scene_data.cam_transform) * vertex;
+		normal = normalize(mat3(scene_data.cam_transform) * normal);
+		vec3 reflection = normalize(reflect(-view, normal));
 
 #ifdef USE_SDFGI
 		sdfgi_process(vertex, normal, reflection, roughness, ambient_light, reflection_light);
@@ -629,7 +651,7 @@ void main() {
 #ifdef MODE_HALF_RES
 	pos <<= 1;
 #endif
-	if (any(greaterThanEqual(pos, params.screen_size))) { //too large, do nothing
+	if (any(greaterThanEqual(pos, scene_data.screen_size))) { //too large, do nothing
 		return;
 	}
 

+ 7 - 3
servers/rendering/renderer_rd/shaders/sdfgi_debug.glsl → servers/rendering/renderer_rd/shaders/environment/sdfgi_debug.glsl

@@ -40,10 +40,13 @@ layout(push_constant, std430) uniform Params {
 	bool use_occlusion;
 	float y_mult;
 
-	vec3 cam_extent;
 	int probe_axis_size;
+	float z_near;
+	float reserved1;
+	float reserved2;
 
 	mat4 cam_transform;
+	mat4 inv_projection;
 }
 params;
 
@@ -81,8 +84,9 @@ void main() {
 	{
 		ray_pos = params.cam_transform[3].xyz;
 
-		ray_dir.xy = params.cam_extent.xy * ((vec2(screen_pos) / vec2(params.screen_size)) * 2.0 - 1.0);
-		ray_dir.z = params.cam_extent.z;
+		ray_dir.xy = ((vec2(screen_pos) / vec2(params.screen_size)) * 2.0 - 1.0);
+		ray_dir.z = params.z_near;
+		ray_dir = (params.inv_projection * vec4(ray_dir, 1.0)).xyz;
 
 		ray_dir = normalize(mat3(params.cam_transform) * ray_dir);
 	}

+ 42 - 6
servers/rendering/renderer_rd/shaders/sdfgi_debug_probes.glsl → servers/rendering/renderer_rd/shaders/environment/sdfgi_debug_probes.glsl

@@ -2,13 +2,28 @@
 
 #version 450
 
+#if defined(USE_MULTIVIEW) && defined(has_VK_KHR_multiview)
+#extension GL_EXT_multiview : enable
+#endif
+
+#ifdef USE_MULTIVIEW
+#ifdef has_VK_KHR_multiview
+#define ViewIndex gl_ViewIndex
+#else // has_VK_KHR_multiview
+// !BAS! This needs to become an input once we implement our fallback!
+#define ViewIndex 0
+#endif // has_VK_KHR_multiview
+#else // USE_MULTIVIEW
+// Set to zero, not supported in non stereo
+#define ViewIndex 0
+#endif //USE_MULTIVIEW
+
 #VERSION_DEFINES
 
 #define MAX_CASCADES 8
+#define MAX_VIEWS 2
 
 layout(push_constant, std430) uniform Params {
-	mat4 projection;
-
 	uint band_power;
 	uint sections_in_band;
 	uint band_mask;
@@ -68,6 +83,11 @@ cascades;
 layout(set = 0, binding = 4) uniform texture3D occlusion_texture;
 layout(set = 0, binding = 3) uniform sampler linear_sampler;
 
+layout(set = 0, binding = 5, std140) uniform SceneData {
+	mat4 projection[MAX_VIEWS];
+}
+scene_data;
+
 void main() {
 #ifdef MODE_PROBES
 	probe_index = gl_InstanceIndex;
@@ -85,7 +105,7 @@ void main() {
 
 	vertex += (cascades.data[params.cascade].offset + vec3(probe_cell) * probe_cell_size) / vec3(1.0, params.y_mult, 1.0);
 
-	gl_Position = params.projection * vec4(vertex, 1.0);
+	gl_Position = scene_data.projection[ViewIndex] * vec4(vertex, 1.0);
 #endif
 
 #ifdef MODE_VISIBILITY
@@ -144,7 +164,7 @@ void main() {
 
 	visibility = dot(texelFetch(sampler3D(occlusion_texture, linear_sampler), tex_pos, 0), layer_axis[occlusion_layer]);
 
-	gl_Position = params.projection * vec4(vertex, 1.0);
+	gl_Position = scene_data.projection[ViewIndex] * vec4(vertex, 1.0);
 
 #endif
 }
@@ -153,16 +173,32 @@ void main() {
 
 #version 450
 
+#if defined(USE_MULTIVIEW) && defined(has_VK_KHR_multiview)
+#extension GL_EXT_multiview : enable
+#endif
+
+#ifdef USE_MULTIVIEW
+#ifdef has_VK_KHR_multiview
+#define ViewIndex gl_ViewIndex
+#else // has_VK_KHR_multiview
+// !BAS! This needs to become an input once we implement our fallback!
+#define ViewIndex 0
+#endif // has_VK_KHR_multiview
+#else // USE_MULTIVIEW
+// Set to zero, not supported in non stereo
+#define ViewIndex 0
+#endif //USE_MULTIVIEW
+
 #VERSION_DEFINES
 
+#define MAX_VIEWS 2
+
 layout(location = 0) out vec4 frag_color;
 
 layout(set = 0, binding = 2) uniform texture2DArray lightprobe_texture;
 layout(set = 0, binding = 3) uniform sampler linear_sampler;
 
 layout(push_constant, std430) uniform Params {
-	mat4 projection;
-
 	uint band_power;
 	uint sections_in_band;
 	uint band_mask;

+ 0 - 0
servers/rendering/renderer_rd/shaders/sdfgi_direct_light.glsl → servers/rendering/renderer_rd/shaders/environment/sdfgi_direct_light.glsl


+ 0 - 0
servers/rendering/renderer_rd/shaders/sdfgi_integrate.glsl → servers/rendering/renderer_rd/shaders/environment/sdfgi_integrate.glsl


+ 0 - 0
servers/rendering/renderer_rd/shaders/sdfgi_preprocess.glsl → servers/rendering/renderer_rd/shaders/environment/sdfgi_preprocess.glsl


+ 0 - 0
servers/rendering/renderer_rd/shaders/voxel_gi.glsl → servers/rendering/renderer_rd/shaders/environment/voxel_gi.glsl


+ 0 - 0
servers/rendering/renderer_rd/shaders/voxel_gi_debug.glsl → servers/rendering/renderer_rd/shaders/environment/voxel_gi_debug.glsl


+ 0 - 0
servers/rendering/renderer_rd/shaders/voxel_gi_sdf.glsl → servers/rendering/renderer_rd/shaders/environment/voxel_gi_sdf.glsl


+ 13 - 0
servers/rendering/renderer_rd/shaders/scene_forward_clustered.glsl

@@ -1238,12 +1238,20 @@ void fragment_shader(in SceneData scene_data) {
 		if (scene_data.gi_upscale_for_msaa) {
 			vec2 base_coord = screen_uv;
 			vec2 closest_coord = base_coord;
+#ifdef USE_MULTIVIEW
+			float closest_ang = dot(normal, textureLod(sampler2DArray(normal_roughness_buffer, material_samplers[SAMPLER_LINEAR_CLAMP]), vec3(base_coord, ViewIndex), 0.0).xyz * 2.0 - 1.0);
+#else // USE_MULTIVIEW
 			float closest_ang = dot(normal, textureLod(sampler2D(normal_roughness_buffer, material_samplers[SAMPLER_LINEAR_CLAMP]), base_coord, 0.0).xyz * 2.0 - 1.0);
+#endif // USE_MULTIVIEW
 
 			for (int i = 0; i < 4; i++) {
 				const vec2 neighbours[4] = vec2[](vec2(-1, 0), vec2(1, 0), vec2(0, -1), vec2(0, 1));
 				vec2 neighbour_coord = base_coord + neighbours[i] * scene_data.screen_pixel_size;
+#ifdef USE_MULTIVIEW
+				float neighbour_ang = dot(normal, textureLod(sampler2DArray(normal_roughness_buffer, material_samplers[SAMPLER_LINEAR_CLAMP]), vec3(neighbour_coord, ViewIndex), 0.0).xyz * 2.0 - 1.0);
+#else // USE_MULTIVIEW
 				float neighbour_ang = dot(normal, textureLod(sampler2D(normal_roughness_buffer, material_samplers[SAMPLER_LINEAR_CLAMP]), neighbour_coord, 0.0).xyz * 2.0 - 1.0);
+#endif // USE_MULTIVIEW
 				if (neighbour_ang > closest_ang) {
 					closest_ang = neighbour_ang;
 					closest_coord = neighbour_coord;
@@ -1256,8 +1264,13 @@ void fragment_shader(in SceneData scene_data) {
 			coord = screen_uv;
 		}
 
+#ifdef USE_MULTIVIEW
+		vec4 buffer_ambient = textureLod(sampler2DArray(ambient_buffer, material_samplers[SAMPLER_LINEAR_CLAMP]), vec3(coord, ViewIndex), 0.0);
+		vec4 buffer_reflection = textureLod(sampler2DArray(reflection_buffer, material_samplers[SAMPLER_LINEAR_CLAMP]), vec3(coord, ViewIndex), 0.0);
+#else // USE_MULTIVIEW
 		vec4 buffer_ambient = textureLod(sampler2D(ambient_buffer, material_samplers[SAMPLER_LINEAR_CLAMP]), coord, 0.0);
 		vec4 buffer_reflection = textureLod(sampler2D(reflection_buffer, material_samplers[SAMPLER_LINEAR_CLAMP]), coord, 0.0);
+#endif // USE_MULTIVIEW
 
 		ambient_light = mix(ambient_light, buffer_ambient.rgb, buffer_ambient.a);
 		specular_light = mix(specular_light, buffer_reflection.rgb, buffer_reflection.a);

+ 7 - 1
servers/rendering/renderer_rd/shaders/scene_forward_clustered_inc.glsl

@@ -317,10 +317,16 @@ layout(r32ui, set = 1, binding = 12) uniform restrict uimage3D geom_facing_grid;
 layout(set = 1, binding = 9) uniform texture2D depth_buffer;
 layout(set = 1, binding = 10) uniform texture2D color_buffer;
 
+#ifdef USE_MULTIVIEW
+layout(set = 1, binding = 11) uniform texture2DArray normal_roughness_buffer;
+layout(set = 1, binding = 13) uniform texture2DArray ambient_buffer;
+layout(set = 1, binding = 14) uniform texture2DArray reflection_buffer;
+#else // USE_MULTIVIEW
 layout(set = 1, binding = 11) uniform texture2D normal_roughness_buffer;
-layout(set = 1, binding = 12) uniform texture2D ao_buffer;
 layout(set = 1, binding = 13) uniform texture2D ambient_buffer;
 layout(set = 1, binding = 14) uniform texture2D reflection_buffer;
+#endif
+layout(set = 1, binding = 12) uniform texture2D ao_buffer;
 layout(set = 1, binding = 15) uniform texture2DArray sdfgi_lightprobe_texture;
 layout(set = 1, binding = 16) uniform texture3D sdfgi_occlusion_cascades;
 

+ 1 - 1
servers/rendering/renderer_scene_cull.cpp

@@ -1894,7 +1894,7 @@ void RendererSceneCull::_update_instance_aabb(Instance *p_instance) {
 
 		} break;
 		case RenderingServer::INSTANCE_VOXEL_GI: {
-			new_aabb = RSG::storage->voxel_gi_get_bounds(p_instance->base);
+			new_aabb = RSG::gi->voxel_gi_get_bounds(p_instance->base);
 
 		} break;
 		case RenderingServer::INSTANCE_LIGHTMAP: {

+ 0 - 42
servers/rendering/renderer_storage.h

@@ -122,48 +122,6 @@ public:
 
 	virtual void base_update_dependency(RID p_base, DependencyTracker *p_instance) = 0;
 
-	/* VOXEL GI API */
-
-	virtual RID voxel_gi_allocate() = 0;
-	virtual void voxel_gi_initialize(RID p_rid) = 0;
-
-	virtual void voxel_gi_allocate_data(RID p_voxel_gi, const Transform3D &p_to_cell_xform, const AABB &p_aabb, const Vector3i &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts) = 0;
-
-	virtual AABB voxel_gi_get_bounds(RID p_voxel_gi) const = 0;
-	virtual Vector3i voxel_gi_get_octree_size(RID p_voxel_gi) const = 0;
-	virtual Vector<uint8_t> voxel_gi_get_octree_cells(RID p_voxel_gi) const = 0;
-	virtual Vector<uint8_t> voxel_gi_get_data_cells(RID p_voxel_gi) const = 0;
-	virtual Vector<uint8_t> voxel_gi_get_distance_field(RID p_voxel_gi) const = 0;
-
-	virtual Vector<int> voxel_gi_get_level_counts(RID p_voxel_gi) const = 0;
-	virtual Transform3D voxel_gi_get_to_cell_xform(RID p_voxel_gi) const = 0;
-
-	virtual void voxel_gi_set_dynamic_range(RID p_voxel_gi, float p_range) = 0;
-	virtual float voxel_gi_get_dynamic_range(RID p_voxel_gi) const = 0;
-
-	virtual void voxel_gi_set_propagation(RID p_voxel_gi, float p_range) = 0;
-	virtual float voxel_gi_get_propagation(RID p_voxel_gi) const = 0;
-
-	virtual void voxel_gi_set_energy(RID p_voxel_gi, float p_energy) = 0;
-	virtual float voxel_gi_get_energy(RID p_voxel_gi) const = 0;
-
-	virtual void voxel_gi_set_bias(RID p_voxel_gi, float p_bias) = 0;
-	virtual float voxel_gi_get_bias(RID p_voxel_gi) const = 0;
-
-	virtual void voxel_gi_set_normal_bias(RID p_voxel_gi, float p_range) = 0;
-	virtual float voxel_gi_get_normal_bias(RID p_voxel_gi) const = 0;
-
-	virtual void voxel_gi_set_interior(RID p_voxel_gi, bool p_enable) = 0;
-	virtual bool voxel_gi_is_interior(RID p_voxel_gi) const = 0;
-
-	virtual void voxel_gi_set_use_two_bounces(RID p_voxel_gi, bool p_enable) = 0;
-	virtual bool voxel_gi_is_using_two_bounces(RID p_voxel_gi) const = 0;
-
-	virtual void voxel_gi_set_anisotropy_strength(RID p_voxel_gi, float p_strength) = 0;
-	virtual float voxel_gi_get_anisotropy_strength(RID p_voxel_gi) const = 0;
-
-	virtual uint32_t voxel_gi_get_version(RID p_probe) = 0;
-
 	/* FOG VOLUMES */
 
 	virtual RID fog_volume_allocate() = 0;

+ 1 - 0
servers/rendering/rendering_server_default.cpp

@@ -404,6 +404,7 @@ RenderingServerDefault::RenderingServerDefault(bool p_create_thread) :
 	RSG::mesh_storage = RSG::rasterizer->get_mesh_storage();
 	RSG::particles_storage = RSG::rasterizer->get_particles_storage();
 	RSG::texture_storage = RSG::rasterizer->get_texture_storage();
+	RSG::gi = RSG::rasterizer->get_gi();
 	RSG::storage = RSG::rasterizer->get_storage();
 	RSG::canvas_render = RSG::rasterizer->get_canvas();
 	sr->set_scene_render(RSG::rasterizer->get_scene());

+ 2 - 2
servers/rendering/rendering_server_default.h

@@ -435,8 +435,8 @@ public:
 #undef ServerName
 #undef server_name
 
-#define ServerName RendererStorage
-#define server_name RSG::storage
+#define ServerName RendererGI
+#define server_name RSG::gi
 
 	FUNCRIDSPLIT(voxel_gi)
 

+ 1 - 0
servers/rendering/rendering_server_globals.cpp

@@ -37,6 +37,7 @@ RendererMaterialStorage *RenderingServerGlobals::material_storage = nullptr;
 RendererMeshStorage *RenderingServerGlobals::mesh_storage = nullptr;
 RendererParticlesStorage *RenderingServerGlobals::particles_storage = nullptr;
 RendererTextureStorage *RenderingServerGlobals::texture_storage = nullptr;
+RendererGI *RenderingServerGlobals::gi = nullptr;
 RendererStorage *RenderingServerGlobals::storage = nullptr;
 RendererCanvasRender *RenderingServerGlobals::canvas_render = nullptr;
 RendererCompositor *RenderingServerGlobals::rasterizer = nullptr;

+ 2 - 0
servers/rendering/rendering_server_globals.h

@@ -31,6 +31,7 @@
 #ifndef RENDERING_SERVER_GLOBALS_H
 #define RENDERING_SERVER_GLOBALS_H
 
+#include "servers/rendering/environment/renderer_gi.h"
 #include "servers/rendering/renderer_canvas_cull.h"
 #include "servers/rendering/renderer_canvas_render.h"
 #include "servers/rendering/renderer_scene.h"
@@ -53,6 +54,7 @@ public:
 	static RendererMeshStorage *mesh_storage;
 	static RendererParticlesStorage *particles_storage;
 	static RendererTextureStorage *texture_storage;
+	static RendererGI *gi;
 	static RendererStorage *storage;
 	static RendererCanvasRender *canvas_render;
 	static RendererCompositor *rasterizer;

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff