Path: blob/master/servers/rendering/renderer_rd/environment/gi.h
10279 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/shaders/environment/gi.glsl.gen.h"38#include "servers/rendering/renderer_rd/shaders/environment/sdfgi_debug.glsl.gen.h"39#include "servers/rendering/renderer_rd/shaders/environment/sdfgi_debug_probes.glsl.gen.h"40#include "servers/rendering/renderer_rd/shaders/environment/sdfgi_direct_light.glsl.gen.h"41#include "servers/rendering/renderer_rd/shaders/environment/sdfgi_integrate.glsl.gen.h"42#include "servers/rendering/renderer_rd/shaders/environment/sdfgi_preprocess.glsl.gen.h"43#include "servers/rendering/renderer_rd/shaders/environment/voxel_gi.glsl.gen.h"44#include "servers/rendering/renderer_rd/shaders/environment/voxel_gi_debug.glsl.gen.h"45#include "servers/rendering/renderer_rd/storage_rd/render_buffer_custom_data_rd.h"46#include "servers/rendering/renderer_scene_render.h"47#include "servers/rendering/rendering_device.h"48#include "servers/rendering/storage/utilities.h"4950#define RB_SCOPE_GI SNAME("rbgi")51#define RB_SCOPE_SDFGI SNAME("sdfgi")5253#define RB_TEX_AMBIENT SNAME("ambient")54#define RB_TEX_REFLECTION SNAME("reflection")5556// Forward declare RenderDataRD and RendererSceneRenderRD so we can pass it into some of our methods, these classes are pretty tightly bound57class RenderDataRD;58class RendererSceneRenderRD;5960namespace RendererRD {6162class GI : public RendererGI {63public:64/* VOXEL GI STORAGE */6566struct VoxelGI {67RID octree_buffer;68RID data_buffer;69RID sdf_texture;7071uint32_t octree_buffer_size = 0;72uint32_t data_buffer_size = 0;7374Vector<int> level_counts;7576int cell_count = 0;7778Transform3D to_cell_xform;79AABB bounds;80Vector3i octree_size;8182float dynamic_range = 2.0;83float energy = 1.0;84float baked_exposure = 1.0;85float bias = 1.4;86float normal_bias = 0.0;87float propagation = 0.5;88bool interior = false;89bool use_two_bounces = true;9091uint32_t version = 1;92uint32_t data_version = 1;9394Dependency dependency;95};9697/* VOXEL_GI INSTANCE */9899//@TODO VoxelGIInstance is still directly used in the render code, we'll address this when we refactor the render code itself.100101struct VoxelGIInstance {102// access to our containers103GI *gi = nullptr;104105RID probe;106RID texture;107RID write_buffer;108109struct Mipmap {110RID texture;111RID uniform_set;112RID second_bounce_uniform_set;113RID write_uniform_set;114uint32_t level;115uint32_t cell_offset;116uint32_t cell_count;117};118Vector<Mipmap> mipmaps;119120struct DynamicMap {121RID texture; //color normally, or emission on first pass122RID fb_depth; //actual depth buffer for the first pass, float depth for later passes123RID depth; //actual depth buffer for the first pass, float depth for later passes124RID normal; //normal buffer for the first pass125RID albedo; //emission buffer for the first pass126RID orm; //orm buffer for the first pass127RID fb; //used for rendering, only valid on first map128RID uniform_set;129uint32_t size;130int mipmap; // mipmap to write to, -1 if no mipmap assigned131};132133Vector<DynamicMap> dynamic_maps;134135int slot = -1;136uint32_t last_probe_version = 0;137uint32_t last_probe_data_version = 0;138139//uint64_t last_pass = 0;140uint32_t render_index = 0;141142bool has_dynamic_object_data = false;143144Transform3D transform;145146void update(bool p_update_light_instances, const Vector<RID> &p_light_instances, const PagedArray<RenderGeometryInstance *> &p_dynamic_objects);147void debug(RD::DrawListID p_draw_list, RID p_framebuffer, const Projection &p_camera_with_transform, bool p_lighting, bool p_emission, float p_alpha);148void free_resources();149};150151private:152static GI *singleton;153154/* VOXEL GI STORAGE */155156mutable RID_Owner<VoxelGI, true> voxel_gi_owner;157158/* VOXEL_GI INSTANCE */159160mutable RID_Owner<VoxelGIInstance> voxel_gi_instance_owner;161162struct VoxelGILight {163uint32_t type;164float energy;165float radius;166float attenuation;167168float color[3];169float cos_spot_angle;170171float position[3];172float inv_spot_attenuation;173174float direction[3];175uint32_t has_shadow;176};177178struct VoxelGIPushConstant {179int32_t limits[3];180uint32_t stack_size;181182float emission_scale;183float propagation;184float dynamic_range;185uint32_t light_count;186187uint32_t cell_offset;188uint32_t cell_count;189float aniso_strength;190float cell_size;191};192193struct VoxelGIDynamicPushConstant {194int32_t limits[3];195uint32_t light_count;196int32_t x_dir[3];197float z_base;198int32_t y_dir[3];199float z_sign;200int32_t z_dir[3];201float pos_multiplier;202uint32_t rect_pos[2];203uint32_t rect_size[2];204uint32_t prev_rect_ofs[2];205uint32_t prev_rect_size[2];206uint32_t flip_x;207uint32_t flip_y;208float dynamic_range;209uint32_t on_mipmap;210float propagation;211float cell_size;212float pad[2];213};214215VoxelGILight *voxel_gi_lights = nullptr;216uint32_t voxel_gi_max_lights = 32;217RID voxel_gi_lights_uniform;218219enum {220VOXEL_GI_SHADER_VERSION_COMPUTE_LIGHT,221VOXEL_GI_SHADER_VERSION_COMPUTE_SECOND_BOUNCE,222VOXEL_GI_SHADER_VERSION_COMPUTE_MIPMAP,223VOXEL_GI_SHADER_VERSION_WRITE_TEXTURE,224VOXEL_GI_SHADER_VERSION_DYNAMIC_OBJECT_LIGHTING,225VOXEL_GI_SHADER_VERSION_DYNAMIC_SHRINK_WRITE,226VOXEL_GI_SHADER_VERSION_DYNAMIC_SHRINK_PLOT,227VOXEL_GI_SHADER_VERSION_DYNAMIC_SHRINK_WRITE_PLOT,228VOXEL_GI_SHADER_VERSION_MAX229};230231VoxelGiShaderRD voxel_gi_shader;232RID voxel_gi_lighting_shader_version;233RID voxel_gi_lighting_shader_version_shaders[VOXEL_GI_SHADER_VERSION_MAX];234RID voxel_gi_lighting_shader_version_pipelines[VOXEL_GI_SHADER_VERSION_MAX];235236enum {237VOXEL_GI_DEBUG_COLOR,238VOXEL_GI_DEBUG_LIGHT,239VOXEL_GI_DEBUG_EMISSION,240VOXEL_GI_DEBUG_LIGHT_FULL,241VOXEL_GI_DEBUG_MAX242};243244struct VoxelGIDebugPushConstant {245float projection[16];246uint32_t cell_offset;247float dynamic_range;248float alpha;249uint32_t level;250int32_t bounds[3];251uint32_t pad;252};253254VoxelGiDebugShaderRD voxel_gi_debug_shader;255RID voxel_gi_debug_shader_version;256RID voxel_gi_debug_shader_version_shaders[VOXEL_GI_DEBUG_MAX];257PipelineCacheRD voxel_gi_debug_shader_version_pipelines[VOXEL_GI_DEBUG_MAX];258RID voxel_gi_debug_uniform_set;259260/* SDFGI */261262struct SDFGIShader {263enum SDFGIPreprocessShaderVersion {264PRE_PROCESS_SCROLL,265PRE_PROCESS_SCROLL_OCCLUSION,266PRE_PROCESS_JUMP_FLOOD_INITIALIZE,267PRE_PROCESS_JUMP_FLOOD_INITIALIZE_HALF,268PRE_PROCESS_JUMP_FLOOD,269PRE_PROCESS_JUMP_FLOOD_OPTIMIZED,270PRE_PROCESS_JUMP_FLOOD_UPSCALE,271PRE_PROCESS_OCCLUSION,272PRE_PROCESS_STORE,273PRE_PROCESS_MAX274};275276struct PreprocessPushConstant {277int32_t scroll[3];278int32_t grid_size;279280int32_t probe_offset[3];281int32_t step_size;282283int32_t half_size;284uint32_t occlusion_index;285int32_t cascade;286uint32_t pad;287};288289SdfgiPreprocessShaderRD preprocess;290RID preprocess_shader;291RID preprocess_pipeline[PRE_PROCESS_MAX];292293struct DebugPushConstant {294float grid_size[3];295uint32_t max_cascades;296297int32_t screen_size[2];298float y_mult;299300float z_near;301302float inv_projection[3][4];303float cam_basis[3][3];304float cam_origin[3];305};306307SdfgiDebugShaderRD debug;308RID debug_shader;309RID debug_shader_version;310RID debug_pipeline;311312enum ProbeDebugMode {313PROBE_DEBUG_PROBES,314PROBE_DEBUG_PROBES_MULTIVIEW,315PROBE_DEBUG_VISIBILITY,316PROBE_DEBUG_VISIBILITY_MULTIVIEW,317PROBE_DEBUG_MAX318};319320struct DebugProbesSceneData {321float projection[2][16];322};323324struct DebugProbesPushConstant {325uint32_t band_power;326uint32_t sections_in_band;327uint32_t band_mask;328float section_arc;329330float grid_size[3];331uint32_t cascade;332333uint32_t pad;334float y_mult;335int32_t probe_debug_index;336int32_t probe_axis_size;337};338339SdfgiDebugProbesShaderRD debug_probes;340RID debug_probes_shader;341RID debug_probes_shader_version;342343PipelineCacheRD debug_probes_pipeline[PROBE_DEBUG_MAX];344345struct Light {346float color[3];347float energy;348349float direction[3];350uint32_t has_shadow;351352float position[3];353float attenuation;354355uint32_t type;356float cos_spot_angle;357float inv_spot_attenuation;358float radius;359};360361struct DirectLightPushConstant {362float grid_size[3];363uint32_t max_cascades;364365uint32_t cascade;366uint32_t light_count;367uint32_t process_offset;368uint32_t process_increment;369370int32_t probe_axis_size;371float bounce_feedback;372float y_mult;373uint32_t use_occlusion;374};375376enum {377DIRECT_LIGHT_MODE_STATIC,378DIRECT_LIGHT_MODE_DYNAMIC,379DIRECT_LIGHT_MODE_MAX380};381SdfgiDirectLightShaderRD direct_light;382RID direct_light_shader;383RID direct_light_pipeline[DIRECT_LIGHT_MODE_MAX];384385enum {386INTEGRATE_MODE_PROCESS,387INTEGRATE_MODE_STORE,388INTEGRATE_MODE_SCROLL,389INTEGRATE_MODE_SCROLL_STORE,390INTEGRATE_MODE_MAX391};392struct IntegratePushConstant {393enum {394SKY_FLAGS_MODE_COLOR = 0x01,395SKY_FLAGS_MODE_SKY = 0x02,396SKY_FLAGS_ORIENTATION_SIGN = 0x04,397};398399float grid_size[3];400uint32_t max_cascades;401402uint32_t probe_axis_size;403uint32_t cascade;404uint32_t history_index;405uint32_t history_size;406407uint32_t ray_count;408float ray_bias;409int32_t image_size[2];410411int32_t world_offset[3];412uint32_t sky_flags;413414int32_t scroll[3];415float sky_energy;416417float sky_color_or_orientation[3];418float y_mult;419420uint32_t store_ambient_texture;421uint32_t pad[3];422};423424SdfgiIntegrateShaderRD integrate;425RID integrate_shader;426RID integrate_pipeline[INTEGRATE_MODE_MAX];427428RID integrate_default_sky_uniform_set;429430} sdfgi_shader;431432public:433static GI *get_singleton() { return singleton; }434435/* GI */436437enum {438MAX_VOXEL_GI_INSTANCES = 8439};440441// Struct for use in render buffer442class RenderBuffersGI : public RenderBufferCustomDataRD {443GDCLASS(RenderBuffersGI, RenderBufferCustomDataRD)444445private:446RID voxel_gi_buffer;447448public:449RID voxel_gi_textures[MAX_VOXEL_GI_INSTANCES];450451RID full_buffer;452RID full_dispatch;453RID full_mask;454455/* GI buffers */456bool using_half_size_gi = false;457458RID uniform_set[RendererSceneRender::MAX_RENDER_VIEWS];459RID scene_data_ubo;460461RID get_voxel_gi_buffer();462463virtual void configure(RenderSceneBuffersRD *p_render_buffers) override {}464virtual void free_data() override;465};466467/* VOXEL GI API */468469bool owns_voxel_gi(RID p_rid) { return voxel_gi_owner.owns(p_rid); }470471virtual RID voxel_gi_allocate() override;472virtual void voxel_gi_free(RID p_voxel_gi) override;473virtual void voxel_gi_initialize(RID p_voxel_gi) override;474475virtual 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;476477virtual AABB voxel_gi_get_bounds(RID p_voxel_gi) const override;478virtual Vector3i voxel_gi_get_octree_size(RID p_voxel_gi) const override;479virtual Vector<uint8_t> voxel_gi_get_octree_cells(RID p_voxel_gi) const override;480virtual Vector<uint8_t> voxel_gi_get_data_cells(RID p_voxel_gi) const override;481virtual Vector<uint8_t> voxel_gi_get_distance_field(RID p_voxel_gi) const override;482483virtual Vector<int> voxel_gi_get_level_counts(RID p_voxel_gi) const override;484virtual Transform3D voxel_gi_get_to_cell_xform(RID p_voxel_gi) const override;485486virtual void voxel_gi_set_dynamic_range(RID p_voxel_gi, float p_range) override;487virtual float voxel_gi_get_dynamic_range(RID p_voxel_gi) const override;488489virtual void voxel_gi_set_propagation(RID p_voxel_gi, float p_range) override;490virtual float voxel_gi_get_propagation(RID p_voxel_gi) const override;491492virtual void voxel_gi_set_energy(RID p_voxel_gi, float p_energy) override;493virtual float voxel_gi_get_energy(RID p_voxel_gi) const override;494495virtual void voxel_gi_set_baked_exposure_normalization(RID p_voxel_gi, float p_baked_exposure) override;496virtual float voxel_gi_get_baked_exposure_normalization(RID p_voxel_gi) const override;497498virtual void voxel_gi_set_bias(RID p_voxel_gi, float p_bias) override;499virtual float voxel_gi_get_bias(RID p_voxel_gi) const override;500501virtual void voxel_gi_set_normal_bias(RID p_voxel_gi, float p_range) override;502virtual float voxel_gi_get_normal_bias(RID p_voxel_gi) const override;503504virtual void voxel_gi_set_interior(RID p_voxel_gi, bool p_enable) override;505virtual bool voxel_gi_is_interior(RID p_voxel_gi) const override;506507virtual void voxel_gi_set_use_two_bounces(RID p_voxel_gi, bool p_enable) override;508virtual bool voxel_gi_is_using_two_bounces(RID p_voxel_gi) const override;509510virtual uint32_t voxel_gi_get_version(RID p_probe) const override;511uint32_t voxel_gi_get_data_version(RID p_probe);512513RID voxel_gi_get_octree_buffer(RID p_voxel_gi) const;514RID voxel_gi_get_data_buffer(RID p_voxel_gi) const;515516RID voxel_gi_get_sdf_texture(RID p_voxel_gi);517518Dependency *voxel_gi_get_dependency(RID p_voxel_gi) const;519520/* VOXEL_GI INSTANCE */521522_FORCE_INLINE_ RID voxel_gi_instance_get_texture(RID p_probe) {523VoxelGIInstance *voxel_gi = voxel_gi_instance_owner.get_or_null(p_probe);524ERR_FAIL_NULL_V(voxel_gi, RID());525return voxel_gi->texture;526}527528_FORCE_INLINE_ void voxel_gi_instance_set_render_index(RID p_probe, uint32_t p_index) {529VoxelGIInstance *voxel_gi = voxel_gi_instance_owner.get_or_null(p_probe);530ERR_FAIL_NULL(voxel_gi);531532voxel_gi->render_index = p_index;533}534535bool voxel_gi_instance_owns(RID p_rid) const {536return voxel_gi_instance_owner.owns(p_rid);537}538539void voxel_gi_instance_free(RID p_rid);540541RS::VoxelGIQuality voxel_gi_quality = RS::VOXEL_GI_QUALITY_LOW;542543/* SDFGI */544545class SDFGI : public RenderBufferCustomDataRD {546GDCLASS(SDFGI, RenderBufferCustomDataRD)547548public:549enum {550MAX_CASCADES = 8,551CASCADE_SIZE = 128,552PROBE_DIVISOR = 16,553ANISOTROPY_SIZE = 6,554MAX_DYNAMIC_LIGHTS = 128,555MAX_STATIC_LIGHTS = 1024,556LIGHTPROBE_OCT_SIZE = 6,557SH_SIZE = 16558};559560struct Cascade {561struct UBO {562float offset[3];563float to_cell;564int32_t probe_offset[3];565uint32_t pad;566float pad2[4];567};568569//cascade blocks are full-size for volume (128^3), half size for albedo/emission570RID sdf_tex;571RID light_tex;572RID light_aniso_0_tex;573RID light_aniso_1_tex;574575RID light_data;576RID light_aniso_0_data;577RID light_aniso_1_data;578579struct SolidCell { // this struct is unused, but remains as reference for size580uint32_t position;581uint32_t albedo;582uint32_t static_light;583uint32_t static_light_aniso;584};585586// Buffers for indirect compute dispatch.587RID solid_cell_dispatch_buffer_storage;588RID solid_cell_dispatch_buffer_call;589RID solid_cell_buffer;590591RID lightprobe_history_tex;592RID lightprobe_average_tex;593594float cell_size;595Vector3i position;596597static const Vector3i DIRTY_ALL;598Vector3i dirty_regions; //(0,0,0 is not dirty, negative is refresh from the end, DIRTY_ALL is refresh all.599600RID sdf_store_uniform_set;601RID sdf_direct_light_static_uniform_set;602RID sdf_direct_light_dynamic_uniform_set;603RID scroll_uniform_set;604RID scroll_occlusion_uniform_set;605RID integrate_uniform_set;606RID lights_buffer;607608float baked_exposure_normalization = 1.0;609610bool all_dynamic_lights_dirty = true;611};612613// access to our containers614GI *gi = nullptr;615616// used for rendering (voxelization)617RID render_albedo;618RID render_emission;619RID render_emission_aniso;620RID render_occlusion[8];621RID render_geom_facing;622623RID render_sdf[2];624RID render_sdf_half[2];625626// used for ping pong processing in cascades627RID sdf_initialize_uniform_set;628RID sdf_initialize_half_uniform_set;629RID jump_flood_uniform_set[2];630RID jump_flood_half_uniform_set[2];631RID sdf_upscale_uniform_set;632int upscale_jfa_uniform_set_index;633RID occlusion_uniform_set;634635uint32_t cascade_size = 128;636637LocalVector<Cascade> cascades;638639RID lightprobe_texture;640RID lightprobe_data;641RID occlusion_texture;642RID occlusion_data;643RID ambient_texture; //integrates with volumetric fog644645RID lightprobe_history_scroll; //used for scrolling lightprobes646RID lightprobe_average_scroll; //used for scrolling lightprobes647648uint32_t history_size = 0;649float solid_cell_ratio = 0;650uint32_t solid_cell_count = 0;651652int num_cascades = 6;653float min_cell_size = 0;654uint32_t probe_axis_count = 0; //amount of probes per axis, this is an odd number because it encloses endpoints655656RID debug_uniform_set[RendererSceneRender::MAX_RENDER_VIEWS];657RID debug_probes_scene_data_ubo;658RID debug_probes_uniform_set;659RID cascades_ubo;660661bool uses_occlusion = false;662float bounce_feedback = 0.5;663bool reads_sky = true;664float energy = 1.0;665float normal_bias = 1.1;666float probe_bias = 1.1;667RS::EnvironmentSDFGIYScale y_scale_mode = RS::ENV_SDFGI_Y_SCALE_75_PERCENT;668669float y_mult = 1.0;670671uint32_t version = 0;672uint32_t render_pass = 0;673674int32_t cascade_dynamic_light_count[SDFGI::MAX_CASCADES]; //used dynamically675RID integrate_sky_uniform_set;676677virtual void configure(RenderSceneBuffersRD *p_render_buffers) override {}678virtual void free_data() override;679~SDFGI();680681void create(RID p_env, const Vector3 &p_world_position, uint32_t p_requested_history_size, GI *p_gi);682void update(RID p_env, const Vector3 &p_world_position);683void update_light();684void update_probes(RID p_env, RendererRD::SkyRD::Sky *p_sky);685void store_probes();686int get_pending_region_data(int p_region, Vector3i &r_local_offset, Vector3i &r_local_size, AABB &r_bounds) const;687void update_cascades();688689void 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);690void debug_probes(RID p_framebuffer, const uint32_t p_view_count, const Projection *p_camera_with_transforms);691692void pre_process_gi(const Transform3D &p_transform, RenderDataRD *p_render_data);693void render_region(Ref<RenderSceneBuffersRD> p_render_buffers, int p_region, const PagedArray<RenderGeometryInstance *> &p_instances, float p_exposure_normalization);694void 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);695};696697RS::EnvironmentSDFGIRayCount sdfgi_ray_count = RS::ENV_SDFGI_RAY_COUNT_16;698RS::EnvironmentSDFGIFramesToConverge sdfgi_frames_to_converge = RS::ENV_SDFGI_CONVERGE_IN_30_FRAMES;699RS::EnvironmentSDFGIFramesToUpdateLight sdfgi_frames_to_update_light = RS::ENV_SDFGI_UPDATE_LIGHT_IN_4_FRAMES;700701float sdfgi_solid_cell_ratio = 0.25;702Vector3 sdfgi_debug_probe_pos;703Vector3 sdfgi_debug_probe_dir;704bool sdfgi_debug_probe_enabled = false;705Vector3i sdfgi_debug_probe_index;706uint32_t sdfgi_current_version = 0;707708/* SDFGI UPDATE */709710int sdfgi_get_lightprobe_octahedron_size() const { return SDFGI::LIGHTPROBE_OCT_SIZE; }711712virtual void sdfgi_reset() override;713714struct SDFGIData {715float grid_size[3];716uint32_t max_cascades;717718uint32_t use_occlusion;719int32_t probe_axis_size;720float probe_to_uvw;721float normal_bias;722723float lightprobe_tex_pixel_size[3];724float energy;725726float lightprobe_uv_offset[3];727float y_mult;728729float occlusion_clamp[3];730uint32_t pad3;731732float occlusion_renormalize[3];733uint32_t pad4;734735float cascade_probe_size[3];736uint32_t pad5;737738struct ProbeCascadeData {739float position[3]; //offset of (0,0,0) in world coordinates740float to_probe; // 1/bounds * grid_size741int32_t probe_world_offset[3];742float to_cell; // 1/bounds * grid_size743float pad[3];744float exposure_normalization;745};746747ProbeCascadeData cascades[SDFGI::MAX_CASCADES];748};749750struct VoxelGIData {751float xform[16]; // 64 - 64752753float bounds[3]; // 12 - 76754float dynamic_range; // 4 - 80755756float bias; // 4 - 84757float normal_bias; // 4 - 88758uint32_t blend_ambient; // 4 - 92759uint32_t mipmaps; // 4 - 96760761float pad[3]; // 12 - 108762float exposure_normalization; // 4 - 112763};764765struct SceneData {766float inv_projection[2][16];767float cam_transform[16];768float eye_offset[2][4];769770int32_t screen_size[2];771float pad1;772float pad2;773};774775struct PushConstant {776uint32_t max_voxel_gi_instances;777uint32_t high_quality_vct;778uint32_t orthogonal;779uint32_t view_index;780781float proj_info[4];782783float z_near;784float z_far;785float pad2;786float pad3;787};788789RID sdfgi_ubo;790791enum Group {792GROUP_NORMAL,793GROUP_VRS,794};795796enum Mode {797MODE_VOXEL_GI,798MODE_VOXEL_GI_WITHOUT_SAMPLER,799MODE_SDFGI,800MODE_COMBINED,801MODE_COMBINED_WITHOUT_SAMPLER,802MODE_MAX803};804805enum ShaderSpecializations {806SHADER_SPECIALIZATION_HALF_RES = 1 << 0,807SHADER_SPECIALIZATION_USE_FULL_PROJECTION_MATRIX = 1 << 1,808SHADER_SPECIALIZATION_USE_VRS = 1 << 2,809SHADER_SPECIALIZATION_VARIATIONS = 8,810};811812RID default_voxel_gi_buffer;813814bool half_resolution = false;815GiShaderRD shader;816RID shader_version;817RID pipelines[SHADER_SPECIALIZATION_VARIATIONS][MODE_MAX];818819GI();820~GI();821822void init(RendererRD::SkyRD *p_sky);823void free();824825Ref<SDFGI> create_sdfgi(RID p_env, const Vector3 &p_world_position, uint32_t p_requested_history_size);826827void 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);828void 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);829830RID voxel_gi_instance_create(RID p_base);831void voxel_gi_instance_set_transform_to_data(RID p_probe, const Transform3D &p_xform);832bool voxel_gi_needs_update(RID p_probe) const;833void voxel_gi_update(RID p_probe, bool p_update_light_instances, const Vector<RID> &p_light_instances, const PagedArray<RenderGeometryInstance *> &p_dynamic_objects);834void 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);835836void enable_vrs_shader_group();837};838839} // namespace RendererRD840841842