Path: blob/master/servers/rendering/renderer_rd/environment/gi.h
21100 views
/**************************************************************************/1/* gi.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/templates/local_vector.h"33#include "core/templates/rid_owner.h"34#include "servers/rendering/environment/renderer_gi.h"35#include "servers/rendering/renderer_compositor.h"36#include "servers/rendering/renderer_rd/environment/sky.h"37#include "servers/rendering/renderer_rd/pipeline_deferred_rd.h"38#include "servers/rendering/renderer_rd/shaders/environment/gi.glsl.gen.h"39#include "servers/rendering/renderer_rd/shaders/environment/sdfgi_debug.glsl.gen.h"40#include "servers/rendering/renderer_rd/shaders/environment/sdfgi_debug_probes.glsl.gen.h"41#include "servers/rendering/renderer_rd/shaders/environment/sdfgi_direct_light.glsl.gen.h"42#include "servers/rendering/renderer_rd/shaders/environment/sdfgi_integrate.glsl.gen.h"43#include "servers/rendering/renderer_rd/shaders/environment/sdfgi_preprocess.glsl.gen.h"44#include "servers/rendering/renderer_rd/shaders/environment/voxel_gi.glsl.gen.h"45#include "servers/rendering/renderer_rd/shaders/environment/voxel_gi_debug.glsl.gen.h"46#include "servers/rendering/renderer_rd/storage_rd/render_buffer_custom_data_rd.h"47#include "servers/rendering/renderer_scene_render.h"48#include "servers/rendering/rendering_device.h"49#include "servers/rendering/storage/utilities.h"5051#define RB_SCOPE_GI SNAME("rbgi")52#define RB_SCOPE_SDFGI SNAME("sdfgi")5354#define RB_TEX_AMBIENT SNAME("ambient")55#define RB_TEX_REFLECTION SNAME("reflection")5657// Forward declare RenderDataRD and RendererSceneRenderRD so we can pass it into some of our methods, these classes are pretty tightly bound58class RenderDataRD;59class RendererSceneRenderRD;6061namespace RendererRD {6263class GI : public RendererGI {64public:65/* VOXEL GI STORAGE */6667struct VoxelGI {68RID octree_buffer;69RID data_buffer;70RID sdf_texture;7172uint32_t octree_buffer_size = 0;73uint32_t data_buffer_size = 0;7475Vector<int> level_counts;7677int cell_count = 0;7879Transform3D to_cell_xform;80AABB bounds;81Vector3i octree_size;8283float dynamic_range = 2.0;84float energy = 1.0;85float baked_exposure = 1.0;86float bias = 1.4;87float normal_bias = 0.0;88float propagation = 0.5;89bool interior = false;90bool use_two_bounces = true;9192uint32_t version = 1;93uint32_t data_version = 1;9495Dependency dependency;96};9798/* VOXEL_GI INSTANCE */99100//@TODO VoxelGIInstance is still directly used in the render code, we'll address this when we refactor the render code itself.101102struct VoxelGIInstance {103// access to our containers104GI *gi = nullptr;105106RID probe;107RID texture;108RID write_buffer;109110struct Mipmap {111RID texture;112RID uniform_set;113RID second_bounce_uniform_set;114RID write_uniform_set;115uint32_t level;116uint32_t cell_offset;117uint32_t cell_count;118};119Vector<Mipmap> mipmaps;120121struct DynamicMap {122RID texture; //color normally, or emission on first pass123RID fb_depth; //actual depth buffer for the first pass, float depth for later passes124RID depth; //actual depth buffer for the first pass, float depth for later passes125RID normal; //normal buffer for the first pass126RID albedo; //emission buffer for the first pass127RID orm; //orm buffer for the first pass128RID fb; //used for rendering, only valid on first map129RID uniform_set;130uint32_t size;131int mipmap; // mipmap to write to, -1 if no mipmap assigned132};133134Vector<DynamicMap> dynamic_maps;135136int slot = -1;137uint32_t last_probe_version = 0;138uint32_t last_probe_data_version = 0;139140//uint64_t last_pass = 0;141uint32_t render_index = 0;142143bool has_dynamic_object_data = false;144145Transform3D transform;146147void update(bool p_update_light_instances, const Vector<RID> &p_light_instances, const PagedArray<RenderGeometryInstance *> &p_dynamic_objects);148void debug(RD::DrawListID p_draw_list, RID p_framebuffer, const Projection &p_camera_with_transform, bool p_lighting, bool p_emission, float p_alpha);149void free_resources();150};151152private:153static GI *singleton;154155/* VOXEL GI STORAGE */156157mutable RID_Owner<VoxelGI, true> voxel_gi_owner;158159/* VOXEL_GI INSTANCE */160161mutable RID_Owner<VoxelGIInstance> voxel_gi_instance_owner;162163struct VoxelGILight {164uint32_t type;165float energy;166float radius;167float attenuation;168169float color[3];170float cos_spot_angle;171172float position[3];173float inv_spot_attenuation;174175float direction[3];176uint32_t has_shadow;177};178179struct VoxelGIPushConstant {180int32_t limits[3];181uint32_t stack_size;182183float emission_scale;184float propagation;185float dynamic_range;186uint32_t light_count;187188uint32_t cell_offset;189uint32_t cell_count;190float aniso_strength;191float cell_size;192};193194struct VoxelGIDynamicPushConstant {195int32_t limits[3];196uint32_t light_count;197int32_t x_dir[3];198float z_base;199int32_t y_dir[3];200float z_sign;201int32_t z_dir[3];202float pos_multiplier;203uint32_t rect_pos[2];204uint32_t rect_size[2];205uint32_t prev_rect_ofs[2];206uint32_t prev_rect_size[2];207uint32_t flip_x;208uint32_t flip_y;209float dynamic_range;210uint32_t on_mipmap;211float propagation;212float cell_size;213float pad[2];214};215216VoxelGILight *voxel_gi_lights = nullptr;217uint32_t voxel_gi_max_lights = 32;218RID voxel_gi_lights_uniform;219220enum {221VOXEL_GI_SHADER_VERSION_COMPUTE_LIGHT,222VOXEL_GI_SHADER_VERSION_COMPUTE_SECOND_BOUNCE,223VOXEL_GI_SHADER_VERSION_COMPUTE_MIPMAP,224VOXEL_GI_SHADER_VERSION_WRITE_TEXTURE,225VOXEL_GI_SHADER_VERSION_DYNAMIC_OBJECT_LIGHTING,226VOXEL_GI_SHADER_VERSION_DYNAMIC_SHRINK_WRITE,227VOXEL_GI_SHADER_VERSION_DYNAMIC_SHRINK_PLOT,228VOXEL_GI_SHADER_VERSION_DYNAMIC_SHRINK_WRITE_PLOT,229VOXEL_GI_SHADER_VERSION_MAX230};231232VoxelGiShaderRD voxel_gi_shader;233RID voxel_gi_lighting_shader_version;234RID voxel_gi_lighting_shader_version_shaders[VOXEL_GI_SHADER_VERSION_MAX];235PipelineDeferredRD voxel_gi_lighting_shader_version_pipelines[VOXEL_GI_SHADER_VERSION_MAX];236237enum {238VOXEL_GI_DEBUG_COLOR,239VOXEL_GI_DEBUG_LIGHT,240VOXEL_GI_DEBUG_EMISSION,241VOXEL_GI_DEBUG_LIGHT_FULL,242VOXEL_GI_DEBUG_MAX243};244245struct VoxelGIDebugPushConstant {246float projection[16];247uint32_t cell_offset;248float dynamic_range;249float alpha;250uint32_t level;251int32_t bounds[3];252uint32_t pad;253};254255VoxelGiDebugShaderRD voxel_gi_debug_shader;256RID voxel_gi_debug_shader_version;257RID voxel_gi_debug_shader_version_shaders[VOXEL_GI_DEBUG_MAX];258PipelineCacheRD voxel_gi_debug_shader_version_pipelines[VOXEL_GI_DEBUG_MAX];259RID voxel_gi_debug_uniform_set;260261/* SDFGI */262263struct SDFGIShader {264enum SDFGIPreprocessShaderVersion {265PRE_PROCESS_SCROLL,266PRE_PROCESS_SCROLL_OCCLUSION,267PRE_PROCESS_JUMP_FLOOD_INITIALIZE,268PRE_PROCESS_JUMP_FLOOD_INITIALIZE_HALF,269PRE_PROCESS_JUMP_FLOOD,270PRE_PROCESS_JUMP_FLOOD_OPTIMIZED,271PRE_PROCESS_JUMP_FLOOD_UPSCALE,272PRE_PROCESS_OCCLUSION,273PRE_PROCESS_STORE,274PRE_PROCESS_MAX275};276277struct PreprocessPushConstant {278int32_t scroll[3];279int32_t grid_size;280281int32_t probe_offset[3];282int32_t step_size;283284int32_t half_size;285uint32_t occlusion_index;286int32_t cascade;287uint32_t pad;288};289290SdfgiPreprocessShaderRD preprocess;291RID preprocess_shader;292PipelineDeferredRD preprocess_pipeline[PRE_PROCESS_MAX];293294struct DebugPushConstant {295float grid_size[3];296uint32_t max_cascades;297298int32_t screen_size[2];299float y_mult;300301float z_near;302303float inv_projection[3][4];304float cam_basis[3][3];305float cam_origin[3];306};307308SdfgiDebugShaderRD debug;309RID debug_shader;310RID debug_shader_version;311PipelineDeferredRD debug_pipeline;312313enum ProbeDebugMode {314PROBE_DEBUG_PROBES,315PROBE_DEBUG_PROBES_MULTIVIEW,316PROBE_DEBUG_VISIBILITY,317PROBE_DEBUG_VISIBILITY_MULTIVIEW,318PROBE_DEBUG_MAX319};320321struct DebugProbesSceneData {322float projection[2][16];323};324325struct DebugProbesPushConstant {326uint32_t band_power;327uint32_t sections_in_band;328uint32_t band_mask;329float section_arc;330331float grid_size[3];332uint32_t cascade;333334uint32_t pad;335float y_mult;336int32_t probe_debug_index;337int32_t probe_axis_size;338};339340SdfgiDebugProbesShaderRD debug_probes;341RID debug_probes_shader;342RID debug_probes_shader_version;343344PipelineCacheRD debug_probes_pipeline[PROBE_DEBUG_MAX];345346struct Light {347float color[3];348float energy;349350float direction[3];351uint32_t has_shadow;352353float position[3];354float attenuation;355356uint32_t type;357float cos_spot_angle;358float inv_spot_attenuation;359float radius;360};361362struct DirectLightPushConstant {363float grid_size[3];364uint32_t max_cascades;365366uint32_t cascade;367uint32_t light_count;368uint32_t process_offset;369uint32_t process_increment;370371int32_t probe_axis_size;372float bounce_feedback;373float y_mult;374uint32_t use_occlusion;375};376377enum {378DIRECT_LIGHT_MODE_STATIC,379DIRECT_LIGHT_MODE_DYNAMIC,380DIRECT_LIGHT_MODE_MAX381};382SdfgiDirectLightShaderRD direct_light;383RID direct_light_shader;384PipelineDeferredRD direct_light_pipeline[DIRECT_LIGHT_MODE_MAX];385386enum {387INTEGRATE_MODE_PROCESS,388INTEGRATE_MODE_STORE,389INTEGRATE_MODE_SCROLL,390INTEGRATE_MODE_SCROLL_STORE,391INTEGRATE_MODE_MAX392};393struct IntegratePushConstant {394enum {395SKY_FLAGS_MODE_COLOR = 0x01,396SKY_FLAGS_MODE_SKY = 0x02,397SKY_FLAGS_ORIENTATION_SIGN = 0x04,398};399400float grid_size[3];401uint32_t max_cascades;402403uint32_t probe_axis_size;404uint32_t cascade;405uint32_t history_index;406uint32_t history_size;407408uint32_t ray_count;409float ray_bias;410int32_t image_size[2];411412int32_t world_offset[3];413uint32_t sky_flags;414415int32_t scroll[3];416float sky_energy;417418float sky_color_or_orientation[3];419float y_mult;420421float sky_irradiance_border_size[2];422uint32_t store_ambient_texture;423uint32_t pad;424};425426SdfgiIntegrateShaderRD integrate;427RID integrate_shader;428PipelineDeferredRD integrate_pipeline[INTEGRATE_MODE_MAX];429430RID integrate_default_sky_uniform_set;431432} sdfgi_shader;433434public:435static GI *get_singleton() { return singleton; }436437/* GI */438439enum {440MAX_VOXEL_GI_INSTANCES = 8441};442443// Struct for use in render buffer444class RenderBuffersGI : public RenderBufferCustomDataRD {445GDCLASS(RenderBuffersGI, RenderBufferCustomDataRD)446447private:448RID voxel_gi_buffer;449450public:451RID voxel_gi_textures[MAX_VOXEL_GI_INSTANCES];452453RID full_buffer;454RID full_dispatch;455RID full_mask;456457/* GI buffers */458bool using_half_size_gi = false;459460RID uniform_set[RendererSceneRender::MAX_RENDER_VIEWS];461RID scene_data_ubo;462463RID get_voxel_gi_buffer();464465virtual void configure(RenderSceneBuffersRD *p_render_buffers) override {}466virtual void free_data() override;467};468469/* VOXEL GI API */470471bool owns_voxel_gi(RID p_rid) { return voxel_gi_owner.owns(p_rid); }472473virtual RID voxel_gi_allocate() override;474virtual void voxel_gi_free(RID p_voxel_gi) override;475virtual void voxel_gi_initialize(RID p_voxel_gi) override;476477virtual 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;478479virtual AABB voxel_gi_get_bounds(RID p_voxel_gi) const override;480virtual Vector3i voxel_gi_get_octree_size(RID p_voxel_gi) const override;481virtual Vector<uint8_t> voxel_gi_get_octree_cells(RID p_voxel_gi) const override;482virtual Vector<uint8_t> voxel_gi_get_data_cells(RID p_voxel_gi) const override;483virtual Vector<uint8_t> voxel_gi_get_distance_field(RID p_voxel_gi) const override;484485virtual Vector<int> voxel_gi_get_level_counts(RID p_voxel_gi) const override;486virtual Transform3D voxel_gi_get_to_cell_xform(RID p_voxel_gi) const override;487488virtual void voxel_gi_set_dynamic_range(RID p_voxel_gi, float p_range) override;489virtual float voxel_gi_get_dynamic_range(RID p_voxel_gi) const override;490491virtual void voxel_gi_set_propagation(RID p_voxel_gi, float p_range) override;492virtual float voxel_gi_get_propagation(RID p_voxel_gi) const override;493494virtual void voxel_gi_set_energy(RID p_voxel_gi, float p_energy) override;495virtual float voxel_gi_get_energy(RID p_voxel_gi) const override;496497virtual void voxel_gi_set_baked_exposure_normalization(RID p_voxel_gi, float p_baked_exposure) override;498virtual float voxel_gi_get_baked_exposure_normalization(RID p_voxel_gi) const override;499500virtual void voxel_gi_set_bias(RID p_voxel_gi, float p_bias) override;501virtual float voxel_gi_get_bias(RID p_voxel_gi) const override;502503virtual void voxel_gi_set_normal_bias(RID p_voxel_gi, float p_range) override;504virtual float voxel_gi_get_normal_bias(RID p_voxel_gi) const override;505506virtual void voxel_gi_set_interior(RID p_voxel_gi, bool p_enable) override;507virtual bool voxel_gi_is_interior(RID p_voxel_gi) const override;508509virtual void voxel_gi_set_use_two_bounces(RID p_voxel_gi, bool p_enable) override;510virtual bool voxel_gi_is_using_two_bounces(RID p_voxel_gi) const override;511512virtual uint32_t voxel_gi_get_version(RID p_probe) const override;513uint32_t voxel_gi_get_data_version(RID p_probe);514515RID voxel_gi_get_octree_buffer(RID p_voxel_gi) const;516RID voxel_gi_get_data_buffer(RID p_voxel_gi) const;517518RID voxel_gi_get_sdf_texture(RID p_voxel_gi);519520Dependency *voxel_gi_get_dependency(RID p_voxel_gi) const;521522/* VOXEL_GI INSTANCE */523524_FORCE_INLINE_ RID voxel_gi_instance_get_texture(RID p_probe) {525VoxelGIInstance *voxel_gi = voxel_gi_instance_owner.get_or_null(p_probe);526ERR_FAIL_NULL_V(voxel_gi, RID());527return voxel_gi->texture;528}529530_FORCE_INLINE_ void voxel_gi_instance_set_render_index(RID p_probe, uint32_t p_index) {531VoxelGIInstance *voxel_gi = voxel_gi_instance_owner.get_or_null(p_probe);532ERR_FAIL_NULL(voxel_gi);533534voxel_gi->render_index = p_index;535}536537bool voxel_gi_instance_owns(RID p_rid) const {538return voxel_gi_instance_owner.owns(p_rid);539}540541void voxel_gi_instance_free(RID p_rid);542543RS::VoxelGIQuality voxel_gi_quality = RS::VOXEL_GI_QUALITY_LOW;544545/* SDFGI */546547class SDFGI : public RenderBufferCustomDataRD {548GDCLASS(SDFGI, RenderBufferCustomDataRD)549550public:551enum {552MAX_CASCADES = 8,553CASCADE_SIZE = 128,554PROBE_DIVISOR = 16,555ANISOTROPY_SIZE = 6,556MAX_DYNAMIC_LIGHTS = 128,557MAX_STATIC_LIGHTS = 1024,558LIGHTPROBE_OCT_SIZE = 6,559SH_SIZE = 16560};561562struct Cascade {563struct UBO {564float offset[3];565float to_cell;566int32_t probe_offset[3];567uint32_t pad;568float pad2[4];569};570571//cascade blocks are full-size for volume (128^3), half size for albedo/emission572RID sdf_tex;573RID light_tex;574RID light_aniso_0_tex;575RID light_aniso_1_tex;576577RID light_data;578RID light_aniso_0_data;579RID light_aniso_1_data;580581struct SolidCell { // this struct is unused, but remains as reference for size582uint32_t position;583uint32_t albedo;584uint32_t static_light;585uint32_t static_light_aniso;586};587588// Buffers for indirect compute dispatch.589RID solid_cell_dispatch_buffer_storage;590RID solid_cell_dispatch_buffer_call;591RID solid_cell_buffer;592593RID lightprobe_history_tex;594RID lightprobe_average_tex;595596float cell_size;597Vector3i position;598599static const Vector3i DIRTY_ALL;600Vector3i dirty_regions; //(0,0,0 is not dirty, negative is refresh from the end, DIRTY_ALL is refresh all.601602RID sdf_store_uniform_set;603RID sdf_direct_light_static_uniform_set;604RID sdf_direct_light_dynamic_uniform_set;605RID scroll_uniform_set;606RID scroll_occlusion_uniform_set;607RID integrate_uniform_set;608RID lights_buffer;609610float baked_exposure_normalization = 1.0;611612bool all_dynamic_lights_dirty = true;613};614615// access to our containers616GI *gi = nullptr;617618// used for rendering (voxelization)619RID render_albedo;620RID render_emission;621RID render_emission_aniso;622RID render_occlusion[8];623RID render_geom_facing;624625RID render_sdf[2];626RID render_sdf_half[2];627628// used for ping pong processing in cascades629RID sdf_initialize_uniform_set;630RID sdf_initialize_half_uniform_set;631RID jump_flood_uniform_set[2];632RID jump_flood_half_uniform_set[2];633RID sdf_upscale_uniform_set;634int upscale_jfa_uniform_set_index;635RID occlusion_uniform_set;636637uint32_t cascade_size = 128;638639LocalVector<Cascade> cascades;640641RID lightprobe_texture;642RID lightprobe_data;643RID occlusion_texture;644RID occlusion_data;645RID ambient_texture; //integrates with volumetric fog646647RID lightprobe_history_scroll; //used for scrolling lightprobes648RID lightprobe_average_scroll; //used for scrolling lightprobes649650uint32_t history_size = 0;651float solid_cell_ratio = 0;652uint32_t solid_cell_count = 0;653654int num_cascades = 6;655float min_cell_size = 0;656uint32_t probe_axis_count = 0; //amount of probes per axis, this is an odd number because it encloses endpoints657658RID debug_uniform_set[RendererSceneRender::MAX_RENDER_VIEWS];659RID debug_probes_scene_data_ubo;660RID debug_probes_uniform_set;661RID cascades_ubo;662663bool uses_occlusion = false;664float bounce_feedback = 0.5;665bool reads_sky = true;666float energy = 1.0;667float normal_bias = 1.1;668float probe_bias = 1.1;669RS::EnvironmentSDFGIYScale y_scale_mode = RS::ENV_SDFGI_Y_SCALE_75_PERCENT;670671float y_mult = 1.0;672673uint32_t version = 0;674uint32_t render_pass = 0;675676int32_t cascade_dynamic_light_count[SDFGI::MAX_CASCADES]; //used dynamically677RID integrate_sky_uniform_set;678679virtual void configure(RenderSceneBuffersRD *p_render_buffers) override {}680virtual void free_data() override;681~SDFGI();682683void create(RID p_env, const Vector3 &p_world_position, uint32_t p_requested_history_size, GI *p_gi);684void update(RID p_env, const Vector3 &p_world_position);685void update_light();686void update_probes(RID p_env, RendererRD::SkyRD::Sky *p_sky);687void store_probes();688int get_pending_region_data(int p_region, Vector3i &r_local_offset, Vector3i &r_local_size, AABB &r_bounds) const;689void update_cascades();690691void debug_draw(uint32_t p_view_count, const Projection *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);692void debug_probes(RID p_framebuffer, const uint32_t p_view_count, const Projection *p_camera_with_transforms);693694void pre_process_gi(const Transform3D &p_transform, RenderDataRD *p_render_data);695void render_region(Ref<RenderSceneBuffersRD> p_render_buffers, int p_region, const PagedArray<RenderGeometryInstance *> &p_instances, float p_exposure_normalization);696void render_static_lights(RenderDataRD *p_render_data, Ref<RenderSceneBuffersRD> p_render_buffers, uint32_t p_cascade_count, const uint32_t *p_cascade_indices, const PagedArray<RID> *p_positional_light_cull_result);697};698699RS::EnvironmentSDFGIRayCount sdfgi_ray_count = RS::ENV_SDFGI_RAY_COUNT_16;700RS::EnvironmentSDFGIFramesToConverge sdfgi_frames_to_converge = RS::ENV_SDFGI_CONVERGE_IN_30_FRAMES;701RS::EnvironmentSDFGIFramesToUpdateLight sdfgi_frames_to_update_light = RS::ENV_SDFGI_UPDATE_LIGHT_IN_4_FRAMES;702703float sdfgi_solid_cell_ratio = 0.25;704Vector3 sdfgi_debug_probe_pos;705Vector3 sdfgi_debug_probe_dir;706bool sdfgi_debug_probe_enabled = false;707Vector3i sdfgi_debug_probe_index;708uint32_t sdfgi_current_version = 0;709710/* SDFGI UPDATE */711712int sdfgi_get_lightprobe_octahedron_size() const { return SDFGI::LIGHTPROBE_OCT_SIZE; }713714virtual void sdfgi_reset() override;715716struct SDFGIData {717float grid_size[3];718uint32_t max_cascades;719720uint32_t use_occlusion;721int32_t probe_axis_size;722float probe_to_uvw;723float normal_bias;724725float lightprobe_tex_pixel_size[3];726float energy;727728float lightprobe_uv_offset[3];729float y_mult;730731float occlusion_clamp[3];732uint32_t pad3;733734float occlusion_renormalize[3];735uint32_t pad4;736737float cascade_probe_size[3];738uint32_t pad5;739740struct ProbeCascadeData {741float position[3]; //offset of (0,0,0) in world coordinates742float to_probe; // 1/bounds * grid_size743int32_t probe_world_offset[3];744float to_cell; // 1/bounds * grid_size745float pad[3];746float exposure_normalization;747};748749ProbeCascadeData cascades[SDFGI::MAX_CASCADES];750};751752struct VoxelGIData {753float xform[16]; // 64 - 64754755float bounds[3]; // 12 - 76756float dynamic_range; // 4 - 80757758float bias; // 4 - 84759float normal_bias; // 4 - 88760uint32_t blend_ambient; // 4 - 92761uint32_t mipmaps; // 4 - 96762763float pad[3]; // 12 - 108764float exposure_normalization; // 4 - 112765};766767struct SceneData {768float inv_projection[2][16];769float cam_transform[16];770float eye_offset[2][4];771772int32_t screen_size[2];773float pad1;774float pad2;775};776777struct PushConstant {778uint32_t max_voxel_gi_instances;779uint32_t high_quality_vct;780uint32_t orthogonal;781uint32_t view_index;782783float proj_info[4];784785float z_near;786float z_far;787float pad2;788float pad3;789};790791RID sdfgi_ubo;792793enum Group {794GROUP_NORMAL,795GROUP_VRS,796};797798enum Mode {799MODE_VOXEL_GI,800MODE_VOXEL_GI_WITHOUT_SAMPLER,801MODE_SDFGI,802MODE_COMBINED,803MODE_COMBINED_WITHOUT_SAMPLER,804MODE_MAX805};806807enum ShaderSpecializations {808SHADER_SPECIALIZATION_HALF_RES = 1 << 0,809SHADER_SPECIALIZATION_USE_FULL_PROJECTION_MATRIX = 1 << 1,810SHADER_SPECIALIZATION_USE_VRS = 1 << 2,811SHADER_SPECIALIZATION_VARIATIONS = 8,812};813814RID default_voxel_gi_buffer;815816bool half_resolution = false;817GiShaderRD shader;818RID shader_version;819PipelineDeferredRD pipelines[SHADER_SPECIALIZATION_VARIATIONS][MODE_MAX];820821GI();822~GI();823824void init(RendererRD::SkyRD *p_sky);825void free();826827Ref<SDFGI> create_sdfgi(RID p_env, const Vector3 &p_world_position, uint32_t p_requested_history_size);828829void setup_voxel_gi_instances(RenderDataRD *p_render_data, Ref<RenderSceneBuffersRD> p_render_buffers, const Transform3D &p_transform, const PagedArray<RID> &p_voxel_gi_instances, uint32_t &r_voxel_gi_instances_used);830void process_gi(Ref<RenderSceneBuffersRD> p_render_buffers, const RID *p_normal_roughness_slices, RID p_voxel_gi_buffer, RID p_environment, uint32_t p_view_count, const Projection *p_projections, const Vector3 *p_eye_offsets, const Transform3D &p_cam_transform, const PagedArray<RID> &p_voxel_gi_instances);831832RID voxel_gi_instance_create(RID p_base);833void voxel_gi_instance_set_transform_to_data(RID p_probe, const Transform3D &p_xform);834bool voxel_gi_needs_update(RID p_probe) const;835void voxel_gi_update(RID p_probe, bool p_update_light_instances, const Vector<RID> &p_light_instances, const PagedArray<RenderGeometryInstance *> &p_dynamic_objects);836void debug_voxel_gi(RID p_voxel_gi, RD::DrawListID p_draw_list, RID p_framebuffer, const Projection &p_camera_with_transform, bool p_lighting, bool p_emission, float p_alpha);837838void enable_vrs_shader_group();839};840841} // namespace RendererRD842843844