Move Sky(RD) into environment
Move Fog logic from render scene render to fog
This commit is contained in:
parent
3e0e84a54c
commit
bad5c659a4
11 changed files with 1437 additions and 1332 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -34,12 +34,19 @@
|
|||
#include "core/templates/local_vector.h"
|
||||
#include "core/templates/rid_owner.h"
|
||||
#include "servers/rendering/environment/renderer_fog.h"
|
||||
#include "servers/rendering/renderer_rd/cluster_builder_rd.h"
|
||||
#include "servers/rendering/renderer_rd/environment/gi.h"
|
||||
#include "servers/rendering/renderer_rd/renderer_scene_environment_rd.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/environment/volumetric_fog.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/environment/volumetric_fog_process.glsl.gen.h"
|
||||
#include "servers/rendering/storage/utilities.h"
|
||||
|
||||
namespace RendererRD {
|
||||
|
||||
class Fog : public RendererFog {
|
||||
public:
|
||||
/* FOG VOLUMES */
|
||||
|
||||
struct FogVolume {
|
||||
RID material;
|
||||
Vector3 extents = Vector3(1, 1, 1);
|
||||
|
|
@ -49,10 +56,179 @@ public:
|
|||
Dependency dependency;
|
||||
};
|
||||
|
||||
struct FogVolumeInstance {
|
||||
RID volume;
|
||||
Transform3D transform;
|
||||
bool active = false;
|
||||
};
|
||||
|
||||
private:
|
||||
static Fog *singleton;
|
||||
|
||||
mutable RID_Owner<FogVolume, true> fog_volume_owner;
|
||||
mutable RID_Owner<FogVolumeInstance> fog_volume_instance_owner;
|
||||
|
||||
/* Volumetric Fog */
|
||||
struct VolumetricFogShader {
|
||||
enum FogSet {
|
||||
FOG_SET_BASE,
|
||||
FOG_SET_UNIFORMS,
|
||||
FOG_SET_MATERIAL,
|
||||
FOG_SET_MAX,
|
||||
};
|
||||
|
||||
struct FogPushConstant {
|
||||
float position[3];
|
||||
float pad;
|
||||
|
||||
float extents[3];
|
||||
float pad2;
|
||||
|
||||
int32_t corner[3];
|
||||
uint32_t shape;
|
||||
|
||||
float transform[16];
|
||||
};
|
||||
|
||||
struct VolumeUBO {
|
||||
float fog_frustum_size_begin[2];
|
||||
float fog_frustum_size_end[2];
|
||||
|
||||
float fog_frustum_end;
|
||||
float z_near;
|
||||
float z_far;
|
||||
float time;
|
||||
|
||||
int32_t fog_volume_size[3];
|
||||
uint32_t directional_light_count;
|
||||
|
||||
uint32_t use_temporal_reprojection;
|
||||
uint32_t temporal_frame;
|
||||
float detail_spread;
|
||||
float temporal_blend;
|
||||
|
||||
float to_prev_view[16];
|
||||
float transform[16];
|
||||
};
|
||||
|
||||
ShaderCompiler compiler;
|
||||
VolumetricFogShaderRD shader;
|
||||
RID volume_ubo;
|
||||
|
||||
RID default_shader;
|
||||
RID default_material;
|
||||
RID default_shader_rd;
|
||||
|
||||
RID base_uniform_set;
|
||||
|
||||
RID params_ubo;
|
||||
|
||||
enum {
|
||||
VOLUMETRIC_FOG_PROCESS_SHADER_DENSITY,
|
||||
VOLUMETRIC_FOG_PROCESS_SHADER_DENSITY_WITH_SDFGI,
|
||||
VOLUMETRIC_FOG_PROCESS_SHADER_FILTER,
|
||||
VOLUMETRIC_FOG_PROCESS_SHADER_FOG,
|
||||
VOLUMETRIC_FOG_PROCESS_SHADER_COPY,
|
||||
VOLUMETRIC_FOG_PROCESS_SHADER_MAX,
|
||||
};
|
||||
|
||||
struct ParamsUBO {
|
||||
float fog_frustum_size_begin[2];
|
||||
float fog_frustum_size_end[2];
|
||||
|
||||
float fog_frustum_end;
|
||||
float ambient_inject;
|
||||
float z_far;
|
||||
uint32_t filter_axis;
|
||||
|
||||
float ambient_color[3];
|
||||
float sky_contribution;
|
||||
|
||||
int32_t fog_volume_size[3];
|
||||
uint32_t directional_light_count;
|
||||
|
||||
float base_emission[3];
|
||||
float base_density;
|
||||
|
||||
float base_scattering[3];
|
||||
float phase_g;
|
||||
|
||||
float detail_spread;
|
||||
float gi_inject;
|
||||
uint32_t max_voxel_gi_instances;
|
||||
uint32_t cluster_type_size;
|
||||
|
||||
float screen_size[2];
|
||||
uint32_t cluster_shift;
|
||||
uint32_t cluster_width;
|
||||
|
||||
uint32_t max_cluster_element_count_div_32;
|
||||
uint32_t use_temporal_reprojection;
|
||||
uint32_t temporal_frame;
|
||||
float temporal_blend;
|
||||
|
||||
float cam_rotation[12];
|
||||
float to_prev_view[16];
|
||||
float radiance_inverse_xform[12];
|
||||
};
|
||||
|
||||
VolumetricFogProcessShaderRD process_shader;
|
||||
|
||||
RID process_shader_version;
|
||||
RID process_pipelines[VOLUMETRIC_FOG_PROCESS_SHADER_MAX];
|
||||
|
||||
} volumetric_fog;
|
||||
|
||||
Vector3i _point_get_position_in_froxel_volume(const Vector3 &p_point, float fog_end, const Vector2 &fog_near_size, const Vector2 &fog_far_size, float volumetric_fog_detail_spread, const Vector3 &fog_size, const Transform3D &p_cam_transform);
|
||||
|
||||
struct FogShaderData : public RendererRD::ShaderData {
|
||||
bool valid = false;
|
||||
RID version;
|
||||
|
||||
RID pipeline;
|
||||
HashMap<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
|
||||
Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms;
|
||||
|
||||
Vector<uint32_t> ubo_offsets;
|
||||
uint32_t ubo_size = 0;
|
||||
|
||||
String path;
|
||||
String code;
|
||||
HashMap<StringName, HashMap<int, RID>> default_texture_params;
|
||||
|
||||
bool uses_time = false;
|
||||
|
||||
virtual void set_path_hint(const String &p_hint);
|
||||
virtual void set_code(const String &p_Code);
|
||||
virtual void set_default_texture_param(const StringName &p_name, RID p_texture, int p_index);
|
||||
virtual void get_param_list(List<PropertyInfo> *p_param_list) const;
|
||||
virtual void get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const;
|
||||
virtual bool is_param_texture(const StringName &p_param) const;
|
||||
virtual bool is_animated() const;
|
||||
virtual bool casts_shadows() const;
|
||||
virtual Variant get_default_parameter(const StringName &p_parameter) const;
|
||||
virtual RS::ShaderNativeSourceCode get_native_source_code() const;
|
||||
|
||||
FogShaderData() {}
|
||||
virtual ~FogShaderData();
|
||||
};
|
||||
|
||||
struct FogMaterialData : public RendererRD::MaterialData {
|
||||
FogShaderData *shader_data = nullptr;
|
||||
RID uniform_set;
|
||||
bool uniform_set_updated;
|
||||
|
||||
virtual void set_render_priority(int p_priority) {}
|
||||
virtual void set_next_pass(RID p_pass) {}
|
||||
virtual bool update_parameters(const HashMap<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty);
|
||||
virtual ~FogMaterialData();
|
||||
};
|
||||
|
||||
RendererRD::ShaderData *_create_fog_shader_func();
|
||||
static RendererRD::ShaderData *_create_fog_shader_funcs();
|
||||
|
||||
RendererRD::MaterialData *_create_fog_material_func(FogShaderData *p_shader);
|
||||
static RendererRD::MaterialData *_create_fog_material_funcs(RendererRD::ShaderData *p_shader);
|
||||
|
||||
public:
|
||||
static Fog *get_singleton() { return singleton; }
|
||||
|
|
@ -76,6 +252,76 @@ public:
|
|||
RID fog_volume_get_material(RID p_fog_volume) const;
|
||||
virtual AABB fog_volume_get_aabb(RID p_fog_volume) const override;
|
||||
Vector3 fog_volume_get_extents(RID p_fog_volume) const;
|
||||
|
||||
/* FOG VOLUMES INSTANCE */
|
||||
|
||||
FogVolumeInstance *get_fog_volume_instance(RID p_rid) { return fog_volume_instance_owner.get_or_null(p_rid); };
|
||||
bool owns_fog_volume_instance(RID p_rid) { return fog_volume_instance_owner.owns(p_rid); };
|
||||
|
||||
RID fog_volume_instance_create(RID p_fog_volume);
|
||||
void fog_instance_free(RID p_rid);
|
||||
|
||||
/* Volumetric FOG */
|
||||
struct VolumetricFog {
|
||||
enum {
|
||||
MAX_TEMPORAL_FRAMES = 16
|
||||
};
|
||||
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
uint32_t depth = 0;
|
||||
|
||||
float length;
|
||||
float spread;
|
||||
|
||||
RID light_density_map;
|
||||
RID prev_light_density_map;
|
||||
RID fog_map;
|
||||
RID density_map;
|
||||
RID light_map;
|
||||
RID emissive_map;
|
||||
|
||||
RID fog_uniform_set;
|
||||
RID copy_uniform_set;
|
||||
RID process_uniform_set_density;
|
||||
RID process_uniform_set;
|
||||
RID process_uniform_set2;
|
||||
RID sdfgi_uniform_set;
|
||||
RID sky_uniform_set;
|
||||
|
||||
int last_shadow_filter = -1;
|
||||
|
||||
VolumetricFog(const Vector3i &fog_size, RID p_sky_shader);
|
||||
~VolumetricFog();
|
||||
};
|
||||
|
||||
void init_fog_shader(uint32_t p_max_directional_lights, int p_roughness_layers, bool p_is_using_radiance_cubemap_array);
|
||||
void free_fog_shader();
|
||||
|
||||
struct VolumetricFogSettings {
|
||||
Vector2i rb_size;
|
||||
double time;
|
||||
bool is_using_radiance_cubemap_array;
|
||||
uint32_t max_cluster_elements;
|
||||
bool volumetric_fog_filter_active;
|
||||
RID shadow_sampler;
|
||||
RID voxel_gl_buffer;
|
||||
RID shadow_atlas_depth;
|
||||
RID omni_light_buffer;
|
||||
RID spot_light_buffer;
|
||||
RID directional_shadow_depth;
|
||||
RID directional_light_buffer;
|
||||
|
||||
// Objects related to our render buffer
|
||||
VolumetricFog *vfog;
|
||||
ClusterBuilderRD *cluster_builder;
|
||||
GI *gi;
|
||||
GI::SDFGI *sdfgi;
|
||||
GI::RenderBuffersGI *rbgi;
|
||||
RendererSceneEnvironmentRD *env;
|
||||
SkyRD *sky;
|
||||
};
|
||||
void volumetric_fog_update(const VolumetricFogSettings &p_settings, const Projection &p_cam_projection, const Transform3D &p_cam_transform, const Transform3D &p_prev_cam_inv_transform, RID p_shadow_atlas, int p_directional_light_count, bool p_use_directional_shadows, int p_positional_light_count, int p_voxel_gi_count, const PagedArray<RID> &p_fog_volumes);
|
||||
};
|
||||
|
||||
} // namespace RendererRD
|
||||
|
|
|
|||
|
|
@ -1268,7 +1268,7 @@ void GI::SDFGI::update_light() {
|
|||
RD::get_singleton()->draw_command_end_label();
|
||||
}
|
||||
|
||||
void GI::SDFGI::update_probes(RendererSceneEnvironmentRD *p_env, RendererSceneSkyRD::Sky *p_sky) {
|
||||
void GI::SDFGI::update_probes(RendererSceneEnvironmentRD *p_env, SkyRD::Sky *p_sky) {
|
||||
RD::get_singleton()->draw_command_begin_label("SDFGI Update Probes");
|
||||
|
||||
SDFGIShader::IntegratePushConstant push_constant;
|
||||
|
|
@ -3233,7 +3233,7 @@ GI::~GI() {
|
|||
singleton = nullptr;
|
||||
}
|
||||
|
||||
void GI::init(RendererSceneSkyRD *p_sky) {
|
||||
void GI::init(SkyRD *p_sky) {
|
||||
RendererRD::TextureStorage *texture_storage = RendererRD::TextureStorage::get_singleton();
|
||||
RendererRD::MaterialStorage *material_storage = RendererRD::MaterialStorage::get_singleton();
|
||||
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@
|
|||
#include "core/templates/rid_owner.h"
|
||||
#include "servers/rendering/environment/renderer_gi.h"
|
||||
#include "servers/rendering/renderer_compositor.h"
|
||||
#include "servers/rendering/renderer_rd/environment/sky.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/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"
|
||||
|
|
@ -618,7 +618,7 @@ public:
|
|||
void erase();
|
||||
void update(RendererSceneEnvironmentRD *p_env, const Vector3 &p_world_position);
|
||||
void update_light();
|
||||
void update_probes(RendererSceneEnvironmentRD *p_env, RendererSceneSkyRD::Sky *p_sky);
|
||||
void update_probes(RendererSceneEnvironmentRD *p_env, RendererRD::SkyRD::Sky *p_sky);
|
||||
void store_probes();
|
||||
int get_pending_region_data(int p_region, Vector3i &r_local_offset, Vector3i &r_local_size, AABB &r_bounds) const;
|
||||
void update_cascades();
|
||||
|
|
@ -769,7 +769,7 @@ public:
|
|||
GI();
|
||||
~GI();
|
||||
|
||||
void init(RendererSceneSkyRD *p_sky);
|
||||
void init(RendererRD::SkyRD *p_sky);
|
||||
void free();
|
||||
|
||||
SDFGI *create_sdfgi(RendererSceneEnvironmentRD *p_env, const Vector3 &p_world_position, uint32_t p_requested_history_size);
|
||||
|
|
|
|||
1926
servers/rendering/renderer_rd/environment/sky.cpp
Normal file
1926
servers/rendering/renderer_rd/environment/sky.cpp
Normal file
File diff suppressed because it is too large
Load diff
325
servers/rendering/renderer_rd/environment/sky.h
Normal file
325
servers/rendering/renderer_rd/environment/sky.h
Normal file
|
|
@ -0,0 +1,325 @@
|
|||
/*************************************************************************/
|
||||
/* sky.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 SKY_RD_H
|
||||
#define SKY_RD_H
|
||||
|
||||
#include "core/templates/rid_owner.h"
|
||||
#include "servers/rendering/renderer_compositor.h"
|
||||
#include "servers/rendering/renderer_rd/pipeline_cache_rd.h"
|
||||
#include "servers/rendering/renderer_rd/renderer_scene_environment_rd.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/environment/sky.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"
|
||||
#include "servers/rendering/shader_compiler.h"
|
||||
|
||||
// Forward declare RendererSceneRenderRD so we can pass it into some of our methods, these classes are pretty tightly bound
|
||||
class RendererSceneRenderRD;
|
||||
|
||||
namespace RendererRD {
|
||||
|
||||
class SkyRD {
|
||||
public:
|
||||
enum SkySet {
|
||||
SKY_SET_UNIFORMS,
|
||||
SKY_SET_MATERIAL,
|
||||
SKY_SET_TEXTURES,
|
||||
SKY_SET_FOG,
|
||||
SKY_SET_MAX
|
||||
};
|
||||
|
||||
// Skys need less info from Directional Lights than the normal shaders
|
||||
struct SkyDirectionalLightData {
|
||||
float direction[3];
|
||||
float energy;
|
||||
float color[3];
|
||||
float size;
|
||||
uint32_t enabled;
|
||||
uint32_t pad[3];
|
||||
};
|
||||
|
||||
private:
|
||||
RD::DataFormat texture_format = RD::DATA_FORMAT_R16G16B16A16_SFLOAT;
|
||||
|
||||
RID index_buffer;
|
||||
RID index_array;
|
||||
|
||||
enum SkyTextureSetVersion {
|
||||
SKY_TEXTURE_SET_BACKGROUND,
|
||||
SKY_TEXTURE_SET_HALF_RES,
|
||||
SKY_TEXTURE_SET_QUARTER_RES,
|
||||
SKY_TEXTURE_SET_CUBEMAP,
|
||||
SKY_TEXTURE_SET_CUBEMAP_HALF_RES,
|
||||
SKY_TEXTURE_SET_CUBEMAP_QUARTER_RES,
|
||||
SKY_TEXTURE_SET_MAX
|
||||
};
|
||||
|
||||
enum SkyVersion {
|
||||
SKY_VERSION_BACKGROUND,
|
||||
SKY_VERSION_HALF_RES,
|
||||
SKY_VERSION_QUARTER_RES,
|
||||
SKY_VERSION_CUBEMAP,
|
||||
SKY_VERSION_CUBEMAP_HALF_RES,
|
||||
SKY_VERSION_CUBEMAP_QUARTER_RES,
|
||||
|
||||
SKY_VERSION_BACKGROUND_MULTIVIEW,
|
||||
SKY_VERSION_HALF_RES_MULTIVIEW,
|
||||
SKY_VERSION_QUARTER_RES_MULTIVIEW,
|
||||
|
||||
SKY_VERSION_MAX
|
||||
};
|
||||
|
||||
struct SkyPushConstant {
|
||||
float orientation[12]; // 48 - 48
|
||||
float projections[RendererSceneRender::MAX_RENDER_VIEWS][4]; // 2 x 16 - 80
|
||||
float position[3]; // 12 - 92
|
||||
float multiplier; // 4 - 96
|
||||
float time; // 4 - 100
|
||||
float luminance_multiplier; // 4 - 104
|
||||
float pad[2]; // 8 - 112 // Using pad to align on 16 bytes
|
||||
// 128 is the max size of a push constant. We can replace "pad" but we can't add any more.
|
||||
};
|
||||
|
||||
struct SkyShaderData : public RendererRD::ShaderData {
|
||||
bool valid = false;
|
||||
RID version;
|
||||
|
||||
PipelineCacheRD pipelines[SKY_VERSION_MAX];
|
||||
HashMap<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
|
||||
Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms;
|
||||
|
||||
Vector<uint32_t> ubo_offsets;
|
||||
uint32_t ubo_size = 0;
|
||||
|
||||
String path;
|
||||
String code;
|
||||
HashMap<StringName, HashMap<int, RID>> default_texture_params;
|
||||
|
||||
bool uses_time = false;
|
||||
bool uses_position = false;
|
||||
bool uses_half_res = false;
|
||||
bool uses_quarter_res = false;
|
||||
bool uses_light = false;
|
||||
|
||||
virtual void set_code(const String &p_Code);
|
||||
virtual void set_path_hint(const String &p_hint);
|
||||
virtual void set_default_texture_param(const StringName &p_name, RID p_texture, int p_index);
|
||||
virtual void get_param_list(List<PropertyInfo> *p_param_list) const;
|
||||
virtual void get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const;
|
||||
virtual bool is_param_texture(const StringName &p_param) const;
|
||||
virtual bool is_animated() const;
|
||||
virtual bool casts_shadows() const;
|
||||
virtual Variant get_default_parameter(const StringName &p_parameter) const;
|
||||
virtual RS::ShaderNativeSourceCode get_native_source_code() const;
|
||||
|
||||
SkyShaderData() {}
|
||||
virtual ~SkyShaderData();
|
||||
};
|
||||
|
||||
void _render_sky(RD::DrawListID p_list, float p_time, RID p_fb, PipelineCacheRD *p_pipeline, RID p_uniform_set, RID p_texture_set, uint32_t p_view_count, const Projection *p_projections, const Basis &p_orientation, float p_multiplier, const Vector3 &p_position, float p_luminance_multiplier);
|
||||
|
||||
public:
|
||||
struct SkySceneState {
|
||||
struct UBO {
|
||||
uint32_t volumetric_fog_enabled;
|
||||
float volumetric_fog_inv_length;
|
||||
float volumetric_fog_detail_spread;
|
||||
|
||||
float fog_aerial_perspective;
|
||||
|
||||
float fog_light_color[3];
|
||||
float fog_sun_scatter;
|
||||
|
||||
uint32_t fog_enabled;
|
||||
float fog_density;
|
||||
|
||||
float z_far;
|
||||
uint32_t directional_light_count;
|
||||
};
|
||||
|
||||
UBO ubo;
|
||||
|
||||
SkyDirectionalLightData *directional_lights = nullptr;
|
||||
SkyDirectionalLightData *last_frame_directional_lights = nullptr;
|
||||
uint32_t max_directional_lights;
|
||||
uint32_t last_frame_directional_light_count;
|
||||
RID directional_light_buffer;
|
||||
RID uniform_set;
|
||||
RID uniform_buffer;
|
||||
RID fog_uniform_set;
|
||||
RID default_fog_uniform_set;
|
||||
|
||||
RID fog_shader;
|
||||
RID fog_material;
|
||||
RID fog_only_texture_uniform_set;
|
||||
} sky_scene_state;
|
||||
|
||||
struct ReflectionData {
|
||||
struct Layer {
|
||||
struct Mipmap {
|
||||
RID framebuffers[6];
|
||||
RID views[6];
|
||||
Size2i size;
|
||||
};
|
||||
Vector<Mipmap> mipmaps; //per-face view
|
||||
Vector<RID> views; // per-cubemap view
|
||||
};
|
||||
|
||||
struct DownsampleLayer {
|
||||
struct Mipmap {
|
||||
RID view;
|
||||
Size2i size;
|
||||
|
||||
// for mobile only
|
||||
RID views[6];
|
||||
RID framebuffers[6];
|
||||
};
|
||||
Vector<Mipmap> mipmaps;
|
||||
};
|
||||
|
||||
RID radiance_base_cubemap; //cubemap for first layer, first cubemap
|
||||
RID downsampled_radiance_cubemap;
|
||||
DownsampleLayer downsampled_layer;
|
||||
RID coefficient_buffer;
|
||||
|
||||
bool dirty = true;
|
||||
|
||||
Vector<Layer> layers;
|
||||
|
||||
void clear_reflection_data();
|
||||
void update_reflection_data(int p_size, int p_mipmaps, bool p_use_array, RID p_base_cube, int p_base_layer, bool p_low_quality, int p_roughness_layers, RD::DataFormat p_texture_format);
|
||||
void create_reflection_fast_filter(bool p_use_arrays);
|
||||
void create_reflection_importance_sample(bool p_use_arrays, int p_cube_side, int p_base_layer, uint32_t p_sky_ggx_samples_quality);
|
||||
void update_reflection_mipmaps(int p_start, int p_end);
|
||||
};
|
||||
|
||||
/* Sky shader */
|
||||
|
||||
struct SkyShader {
|
||||
SkyShaderRD shader;
|
||||
ShaderCompiler compiler;
|
||||
|
||||
RID default_shader;
|
||||
RID default_material;
|
||||
RID default_shader_rd;
|
||||
} sky_shader;
|
||||
|
||||
struct SkyMaterialData : public RendererRD::MaterialData {
|
||||
SkyShaderData *shader_data = nullptr;
|
||||
RID uniform_set;
|
||||
bool uniform_set_updated;
|
||||
|
||||
virtual void set_render_priority(int p_priority) {}
|
||||
virtual void set_next_pass(RID p_pass) {}
|
||||
virtual bool update_parameters(const HashMap<StringName, Variant> &p_parameters, bool p_uniform_dirty, bool p_textures_dirty);
|
||||
virtual ~SkyMaterialData();
|
||||
};
|
||||
|
||||
struct Sky {
|
||||
RID radiance;
|
||||
RID half_res_pass;
|
||||
RID half_res_framebuffer;
|
||||
RID quarter_res_pass;
|
||||
RID quarter_res_framebuffer;
|
||||
Size2i screen_size;
|
||||
|
||||
RID texture_uniform_sets[SKY_TEXTURE_SET_MAX];
|
||||
RID uniform_set;
|
||||
|
||||
RID material;
|
||||
RID uniform_buffer;
|
||||
|
||||
int radiance_size = 256;
|
||||
|
||||
RS::SkyMode mode = RS::SKY_MODE_AUTOMATIC;
|
||||
|
||||
ReflectionData reflection;
|
||||
bool dirty = false;
|
||||
int processing_layer = 0;
|
||||
Sky *dirty_list = nullptr;
|
||||
|
||||
//State to track when radiance cubemap needs updating
|
||||
SkyMaterialData *prev_material = nullptr;
|
||||
Vector3 prev_position;
|
||||
float prev_time;
|
||||
|
||||
void free();
|
||||
|
||||
RID get_textures(SkyTextureSetVersion p_version, RID p_default_shader_rd);
|
||||
bool set_radiance_size(int p_radiance_size);
|
||||
bool set_mode(RS::SkyMode p_mode);
|
||||
bool set_material(RID p_material);
|
||||
Ref<Image> bake_panorama(float p_energy, int p_roughness_layers, const Size2i &p_size);
|
||||
};
|
||||
|
||||
uint32_t sky_ggx_samples_quality;
|
||||
bool sky_use_cubemap_array;
|
||||
Sky *dirty_sky_list = nullptr;
|
||||
mutable RID_Owner<Sky, true> sky_owner;
|
||||
int roughness_layers;
|
||||
|
||||
RendererRD::ShaderData *_create_sky_shader_func();
|
||||
static RendererRD::ShaderData *_create_sky_shader_funcs();
|
||||
|
||||
RendererRD::MaterialData *_create_sky_material_func(SkyShaderData *p_shader);
|
||||
static RendererRD::MaterialData *_create_sky_material_funcs(RendererRD::ShaderData *p_shader);
|
||||
|
||||
SkyRD();
|
||||
void init();
|
||||
void set_texture_format(RD::DataFormat p_texture_format);
|
||||
~SkyRD();
|
||||
|
||||
void setup(RendererSceneEnvironmentRD *p_env, RID p_render_buffers, const PagedArray<RID> &p_lights, const Projection &p_projection, const Transform3D &p_transform, const Size2i p_screen_size, RendererSceneRenderRD *p_scene_render);
|
||||
void update(RendererSceneEnvironmentRD *p_env, const Projection &p_projection, const Transform3D &p_transform, double p_time, float p_luminance_multiplier = 1.0);
|
||||
void draw(RendererSceneEnvironmentRD *p_env, bool p_can_continue_color, bool p_can_continue_depth, RID p_fb, uint32_t p_view_count, const Projection *p_projections, const Transform3D &p_transform, double p_time); // only called by clustered renderer
|
||||
void update_res_buffers(RendererSceneEnvironmentRD *p_env, uint32_t p_view_count, const Projection *p_projections, const Transform3D &p_transform, double p_time, float p_luminance_multiplier = 1.0);
|
||||
void draw(RD::DrawListID p_draw_list, RendererSceneEnvironmentRD *p_env, RID p_fb, uint32_t p_view_count, const Projection *p_projections, const Transform3D &p_transform, double p_time, float p_luminance_multiplier = 1.0);
|
||||
|
||||
void invalidate_sky(Sky *p_sky);
|
||||
void update_dirty_skys();
|
||||
|
||||
RID sky_get_material(RID p_sky) const;
|
||||
|
||||
RID allocate_sky_rid();
|
||||
void initialize_sky_rid(RID p_rid);
|
||||
Sky *get_sky(RID p_sky) const;
|
||||
void free_sky(RID p_sky);
|
||||
void sky_set_radiance_size(RID p_sky, int p_radiance_size);
|
||||
void sky_set_mode(RID p_sky, RS::SkyMode p_mode);
|
||||
void sky_set_material(RID p_sky, RID p_material);
|
||||
Ref<Image> sky_bake_panorama(RID p_sky, float p_energy, bool p_bake_irradiance, const Size2i &p_size);
|
||||
|
||||
RID sky_get_radiance_texture_rd(RID p_sky) const;
|
||||
};
|
||||
|
||||
} // namespace RendererRD
|
||||
|
||||
#endif // SKY_RD_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue