mirror of
https://github.com/godotengine/godot.git
synced 2024-11-21 03:18:37 +08:00
Merge pull request #46046 from BastiaanOlij/cleanup_gi
Moving GI and Sky code from RendererSceneRenderRD into separate classes
This commit is contained in:
commit
da8eef486b
126
servers/rendering/renderer_rd/renderer_scene_environment_rd.cpp
Normal file
126
servers/rendering/renderer_rd/renderer_scene_environment_rd.cpp
Normal file
@ -0,0 +1,126 @@
|
||||
/*************************************************************************/
|
||||
/* renderer_scene_environment_rd.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 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 "servers/rendering/renderer_rd/renderer_scene_environment_rd.h"
|
||||
|
||||
uint64_t RendererSceneEnvironmentRD::auto_exposure_counter = 2;
|
||||
|
||||
void RendererSceneEnvironmentRD::set_ambient_light(const Color &p_color, RS::EnvironmentAmbientSource p_ambient, float p_energy, float p_sky_contribution, RS::EnvironmentReflectionSource p_reflection_source, const Color &p_ao_color) {
|
||||
ambient_light = p_color;
|
||||
ambient_source = p_ambient;
|
||||
ambient_light_energy = p_energy;
|
||||
ambient_sky_contribution = p_sky_contribution;
|
||||
reflection_source = p_reflection_source;
|
||||
ao_color = p_ao_color;
|
||||
}
|
||||
|
||||
void RendererSceneEnvironmentRD::set_tonemap(RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale) {
|
||||
exposure = p_exposure;
|
||||
tone_mapper = p_tone_mapper;
|
||||
if (!auto_exposure && p_auto_exposure) {
|
||||
auto_exposure_version = ++auto_exposure_counter;
|
||||
}
|
||||
auto_exposure = p_auto_exposure;
|
||||
white = p_white;
|
||||
min_luminance = p_min_luminance;
|
||||
max_luminance = p_max_luminance;
|
||||
auto_exp_speed = p_auto_exp_speed;
|
||||
auto_exp_scale = p_auto_exp_scale;
|
||||
}
|
||||
|
||||
void RendererSceneEnvironmentRD::set_glow(bool p_enable, Vector<float> p_levels, float p_intensity, float p_strength, float p_mix, float p_bloom_threshold, RS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap) {
|
||||
ERR_FAIL_COND_MSG(p_levels.size() != 7, "Size of array of glow levels must be 7");
|
||||
glow_enabled = p_enable;
|
||||
glow_levels = p_levels;
|
||||
glow_intensity = p_intensity;
|
||||
glow_strength = p_strength;
|
||||
glow_mix = p_mix;
|
||||
glow_bloom = p_bloom_threshold;
|
||||
glow_blend_mode = p_blend_mode;
|
||||
glow_hdr_bleed_threshold = p_hdr_bleed_threshold;
|
||||
glow_hdr_bleed_scale = p_hdr_bleed_scale;
|
||||
glow_hdr_luminance_cap = p_hdr_luminance_cap;
|
||||
}
|
||||
|
||||
void RendererSceneEnvironmentRD::set_sdfgi(bool p_enable, RS::EnvironmentSDFGICascades p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias) {
|
||||
sdfgi_enabled = p_enable;
|
||||
sdfgi_cascades = p_cascades;
|
||||
sdfgi_min_cell_size = p_min_cell_size;
|
||||
sdfgi_use_occlusion = p_use_occlusion;
|
||||
sdfgi_bounce_feedback = p_bounce_feedback;
|
||||
sdfgi_read_sky_light = p_read_sky;
|
||||
sdfgi_energy = p_energy;
|
||||
sdfgi_normal_bias = p_normal_bias;
|
||||
sdfgi_probe_bias = p_probe_bias;
|
||||
sdfgi_y_scale = p_y_scale;
|
||||
}
|
||||
|
||||
void RendererSceneEnvironmentRD::set_fog(bool p_enable, const Color &p_light_color, float p_light_energy, float p_sun_scatter, float p_density, float p_height, float p_height_density, float p_fog_aerial_perspective) {
|
||||
fog_enabled = p_enable;
|
||||
fog_light_color = p_light_color;
|
||||
fog_light_energy = p_light_energy;
|
||||
fog_sun_scatter = p_sun_scatter;
|
||||
fog_density = p_density;
|
||||
fog_height = p_height;
|
||||
fog_height_density = p_height_density;
|
||||
fog_aerial_perspective = p_fog_aerial_perspective;
|
||||
}
|
||||
|
||||
void RendererSceneEnvironmentRD::set_volumetric_fog(bool p_enable, float p_density, const Color &p_light, float p_light_energy, float p_length, float p_detail_spread, float p_gi_inject, bool p_temporal_reprojection, float p_temporal_reprojection_amount) {
|
||||
volumetric_fog_enabled = p_enable;
|
||||
volumetric_fog_density = p_density;
|
||||
volumetric_fog_light = p_light;
|
||||
volumetric_fog_light_energy = p_light_energy;
|
||||
volumetric_fog_length = p_length;
|
||||
volumetric_fog_detail_spread = p_detail_spread;
|
||||
volumetric_fog_gi_inject = p_gi_inject;
|
||||
volumetric_fog_temporal_reprojection = p_temporal_reprojection;
|
||||
volumetric_fog_temporal_reprojection_amount = p_temporal_reprojection_amount;
|
||||
}
|
||||
|
||||
void RendererSceneEnvironmentRD::set_ssr(bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance) {
|
||||
ssr_enabled = p_enable;
|
||||
ssr_max_steps = p_max_steps;
|
||||
ssr_fade_in = p_fade_int;
|
||||
ssr_fade_out = p_fade_out;
|
||||
ssr_depth_tolerance = p_depth_tolerance;
|
||||
}
|
||||
|
||||
void RendererSceneEnvironmentRD::set_ssao(bool p_enable, float p_radius, float p_intensity, float p_power, float p_detail, float p_horizon, float p_sharpness, float p_light_affect, float p_ao_channel_affect) {
|
||||
ssao_enabled = p_enable;
|
||||
ssao_radius = p_radius;
|
||||
ssao_intensity = p_intensity;
|
||||
ssao_power = p_power;
|
||||
ssao_detail = p_detail;
|
||||
ssao_horizon = p_horizon;
|
||||
ssao_sharpness = p_sharpness;
|
||||
ssao_direct_light_affect = p_light_affect;
|
||||
ssao_ao_channel_affect = p_ao_channel_affect;
|
||||
}
|
155
servers/rendering/renderer_rd/renderer_scene_environment_rd.h
Normal file
155
servers/rendering/renderer_rd/renderer_scene_environment_rd.h
Normal file
@ -0,0 +1,155 @@
|
||||
/*************************************************************************/
|
||||
/* renderer_scene_environment_rd.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 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 RENDERING_SERVER_SCENE_ENVIRONMENT_RD_H
|
||||
#define RENDERING_SERVER_SCENE_ENVIRONMENT_RD_H
|
||||
|
||||
#include "servers/rendering/renderer_scene_render.h"
|
||||
#include "servers/rendering/rendering_device.h"
|
||||
|
||||
class RendererSceneEnvironmentRD {
|
||||
private:
|
||||
static uint64_t auto_exposure_counter;
|
||||
|
||||
public:
|
||||
// BG
|
||||
RS::EnvironmentBG background = RS::ENV_BG_CLEAR_COLOR;
|
||||
RID sky;
|
||||
float sky_custom_fov = 0.0;
|
||||
Basis sky_orientation;
|
||||
Color bg_color;
|
||||
float bg_energy = 1.0;
|
||||
int canvas_max_layer = 0;
|
||||
RS::EnvironmentAmbientSource ambient_source = RS::ENV_AMBIENT_SOURCE_BG;
|
||||
Color ambient_light;
|
||||
float ambient_light_energy = 1.0;
|
||||
float ambient_sky_contribution = 1.0;
|
||||
RS::EnvironmentReflectionSource reflection_source = RS::ENV_REFLECTION_SOURCE_BG;
|
||||
Color ao_color;
|
||||
|
||||
/// Tonemap
|
||||
|
||||
RS::EnvironmentToneMapper tone_mapper;
|
||||
float exposure = 1.0;
|
||||
float white = 1.0;
|
||||
bool auto_exposure = false;
|
||||
float min_luminance = 0.2;
|
||||
float max_luminance = 8.0;
|
||||
float auto_exp_speed = 0.2;
|
||||
float auto_exp_scale = 0.5;
|
||||
uint64_t auto_exposure_version = 0;
|
||||
|
||||
// Fog
|
||||
bool fog_enabled = false;
|
||||
Color fog_light_color = Color(0.5, 0.6, 0.7);
|
||||
float fog_light_energy = 1.0;
|
||||
float fog_sun_scatter = 0.0;
|
||||
float fog_density = 0.001;
|
||||
float fog_height = 0.0;
|
||||
float fog_height_density = 0.0; //can be negative to invert effect
|
||||
float fog_aerial_perspective = 0.0;
|
||||
|
||||
/// Volumetric Fog
|
||||
///
|
||||
bool volumetric_fog_enabled = false;
|
||||
float volumetric_fog_density = 0.01;
|
||||
Color volumetric_fog_light = Color(0, 0, 0);
|
||||
float volumetric_fog_light_energy = 0.0;
|
||||
float volumetric_fog_length = 64.0;
|
||||
float volumetric_fog_detail_spread = 2.0;
|
||||
float volumetric_fog_gi_inject = 0.0;
|
||||
bool volumetric_fog_temporal_reprojection = true;
|
||||
float volumetric_fog_temporal_reprojection_amount = 0.9;
|
||||
|
||||
/// Glow
|
||||
|
||||
bool glow_enabled = false;
|
||||
Vector<float> glow_levels;
|
||||
float glow_intensity = 0.8;
|
||||
float glow_strength = 1.0;
|
||||
float glow_bloom = 0.0;
|
||||
float glow_mix = 0.01;
|
||||
RS::EnvironmentGlowBlendMode glow_blend_mode = RS::ENV_GLOW_BLEND_MODE_SOFTLIGHT;
|
||||
float glow_hdr_bleed_threshold = 1.0;
|
||||
float glow_hdr_luminance_cap = 12.0;
|
||||
float glow_hdr_bleed_scale = 2.0;
|
||||
|
||||
/// SSAO
|
||||
|
||||
bool ssao_enabled = false;
|
||||
float ssao_radius = 1.0;
|
||||
float ssao_intensity = 2.0;
|
||||
float ssao_power = 1.5;
|
||||
float ssao_detail = 0.5;
|
||||
float ssao_horizon = 0.06;
|
||||
float ssao_sharpness = 0.98;
|
||||
float ssao_direct_light_affect = 0.0;
|
||||
float ssao_ao_channel_affect = 0.0;
|
||||
|
||||
/// SSR
|
||||
///
|
||||
bool ssr_enabled = false;
|
||||
int ssr_max_steps = 64;
|
||||
float ssr_fade_in = 0.15;
|
||||
float ssr_fade_out = 2.0;
|
||||
float ssr_depth_tolerance = 0.2;
|
||||
|
||||
/// SDFGI
|
||||
bool sdfgi_enabled = false;
|
||||
RS::EnvironmentSDFGICascades sdfgi_cascades;
|
||||
float sdfgi_min_cell_size = 0.2;
|
||||
bool sdfgi_use_occlusion = false;
|
||||
float sdfgi_bounce_feedback = 0.0;
|
||||
bool sdfgi_read_sky_light = false;
|
||||
float sdfgi_energy = 1.0;
|
||||
float sdfgi_normal_bias = 1.1;
|
||||
float sdfgi_probe_bias = 1.1;
|
||||
RS::EnvironmentSDFGIYScale sdfgi_y_scale = RS::ENV_SDFGI_Y_SCALE_DISABLED;
|
||||
|
||||
/// Adjustments
|
||||
|
||||
bool adjustments_enabled = false;
|
||||
float adjustments_brightness = 1.0f;
|
||||
float adjustments_contrast = 1.0f;
|
||||
float adjustments_saturation = 1.0f;
|
||||
bool use_1d_color_correction = false;
|
||||
RID color_correction = RID();
|
||||
|
||||
void set_ambient_light(const Color &p_color, RS::EnvironmentAmbientSource p_ambient, float p_energy, float p_sky_contribution, RS::EnvironmentReflectionSource p_reflection_source, const Color &p_ao_color);
|
||||
void set_tonemap(RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale);
|
||||
void set_glow(bool p_enable, Vector<float> p_levels, float p_intensity, float p_strength, float p_mix, float p_bloom_threshold, RS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, float p_hdr_luminance_cap);
|
||||
void set_sdfgi(bool p_enable, RS::EnvironmentSDFGICascades p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, float p_bounce_feedback, bool p_read_sky, float p_energy, float p_normal_bias, float p_probe_bias);
|
||||
void set_fog(bool p_enable, const Color &p_light_color, float p_light_energy, float p_sun_scatter, float p_density, float p_height, float p_height_density, float p_fog_aerial_perspective);
|
||||
void set_volumetric_fog(bool p_enable, float p_density, const Color &p_light, float p_light_energy, float p_length, float p_detail_spread, float p_gi_inject, bool p_temporal_reprojection, float p_temporal_reprojection_amount);
|
||||
void set_ssr(bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance);
|
||||
void set_ssao(bool p_enable, float p_radius, float p_intensity, float p_power, float p_detail, float p_horizon, float p_sharpness, float p_light_affect, float p_ao_channel_affect);
|
||||
};
|
||||
|
||||
#endif /* !RENDERING_SERVER_SCENE_ENVIRONMENT_RD_H */
|
3383
servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp
Normal file
3383
servers/rendering/renderer_rd/renderer_scene_gi_rd.cpp
Normal file
File diff suppressed because it is too large
Load Diff
653
servers/rendering/renderer_rd/renderer_scene_gi_rd.h
Normal file
653
servers/rendering/renderer_rd/renderer_scene_gi_rd.h
Normal file
@ -0,0 +1,653 @@
|
||||
/*************************************************************************/
|
||||
/* renderer_scene_gi_rd.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 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 RENDERING_SERVER_SCENE_GI_RD_H
|
||||
#define RENDERING_SERVER_SCENE_GI_RD_H
|
||||
|
||||
#include "core/templates/local_vector.h"
|
||||
#include "core/templates/rid_owner.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/gi.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/giprobe.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/giprobe_debug.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_scene_render.h"
|
||||
#include "servers/rendering/rendering_device.h"
|
||||
|
||||
// Forward declare RendererSceneRenderRD so we can pass it into some of our methods, these classes are pretty tightly bound
|
||||
class RendererSceneRenderRD;
|
||||
|
||||
class RendererSceneGIRD {
|
||||
private:
|
||||
// !BAS! need to see which things become internal..
|
||||
|
||||
RendererStorageRD *storage;
|
||||
|
||||
public:
|
||||
/* GIPROBE INSTANCE */
|
||||
|
||||
struct GIProbeLight {
|
||||
uint32_t type;
|
||||
float energy;
|
||||
float radius;
|
||||
float attenuation;
|
||||
|
||||
float color[3];
|
||||
float cos_spot_angle;
|
||||
|
||||
float position[3];
|
||||
float inv_spot_attenuation;
|
||||
|
||||
float direction[3];
|
||||
uint32_t has_shadow;
|
||||
};
|
||||
|
||||
struct GIProbePushConstant {
|
||||
int32_t limits[3];
|
||||
uint32_t stack_size;
|
||||
|
||||
float emission_scale;
|
||||
float propagation;
|
||||
float dynamic_range;
|
||||
uint32_t light_count;
|
||||
|
||||
uint32_t cell_offset;
|
||||
uint32_t cell_count;
|
||||
float aniso_strength;
|
||||
uint32_t pad;
|
||||
};
|
||||
|
||||
struct GIProbeDynamicPushConstant {
|
||||
int32_t limits[3];
|
||||
uint32_t light_count;
|
||||
int32_t x_dir[3];
|
||||
float z_base;
|
||||
int32_t y_dir[3];
|
||||
float z_sign;
|
||||
int32_t z_dir[3];
|
||||
float pos_multiplier;
|
||||
uint32_t rect_pos[2];
|
||||
uint32_t rect_size[2];
|
||||
uint32_t prev_rect_ofs[2];
|
||||
uint32_t prev_rect_size[2];
|
||||
uint32_t flip_x;
|
||||
uint32_t flip_y;
|
||||
float dynamic_range;
|
||||
uint32_t on_mipmap;
|
||||
float propagation;
|
||||
float pad[3];
|
||||
};
|
||||
|
||||
struct GIProbeInstance {
|
||||
// access to our containers
|
||||
RendererStorageRD *storage;
|
||||
RendererSceneGIRD *gi;
|
||||
|
||||
RID probe;
|
||||
RID texture;
|
||||
RID write_buffer;
|
||||
|
||||
struct Mipmap {
|
||||
RID texture;
|
||||
RID uniform_set;
|
||||
RID second_bounce_uniform_set;
|
||||
RID write_uniform_set;
|
||||
uint32_t level;
|
||||
uint32_t cell_offset;
|
||||
uint32_t cell_count;
|
||||
};
|
||||
Vector<Mipmap> mipmaps;
|
||||
|
||||
struct DynamicMap {
|
||||
RID texture; //color normally, or emission on first pass
|
||||
RID fb_depth; //actual depth buffer for the first pass, float depth for later passes
|
||||
RID depth; //actual depth buffer for the first pass, float depth for later passes
|
||||
RID normal; //normal buffer for the first pass
|
||||
RID albedo; //emission buffer for the first pass
|
||||
RID orm; //orm buffer for the first pass
|
||||
RID fb; //used for rendering, only valid on first map
|
||||
RID uniform_set;
|
||||
uint32_t size;
|
||||
int mipmap; // mipmap to write to, -1 if no mipmap assigned
|
||||
};
|
||||
|
||||
Vector<DynamicMap> dynamic_maps;
|
||||
|
||||
int slot = -1;
|
||||
uint32_t last_probe_version = 0;
|
||||
uint32_t last_probe_data_version = 0;
|
||||
|
||||
//uint64_t last_pass = 0;
|
||||
uint32_t render_index = 0;
|
||||
|
||||
bool has_dynamic_object_data = false;
|
||||
|
||||
Transform transform;
|
||||
|
||||
void update(bool p_update_light_instances, const Vector<RID> &p_light_instances, const PagedArray<RendererSceneRender::GeometryInstance *> &p_dynamic_objects, RendererSceneRenderRD *p_scene_render);
|
||||
void debug(RD::DrawListID p_draw_list, RID p_framebuffer, const CameraMatrix &p_camera_with_transform, bool p_lighting, bool p_emission, float p_alpha);
|
||||
};
|
||||
|
||||
GIProbeLight *gi_probe_lights;
|
||||
uint32_t gi_probe_max_lights;
|
||||
RID gi_probe_lights_uniform;
|
||||
|
||||
enum {
|
||||
GI_PROBE_SHADER_VERSION_COMPUTE_LIGHT,
|
||||
GI_PROBE_SHADER_VERSION_COMPUTE_SECOND_BOUNCE,
|
||||
GI_PROBE_SHADER_VERSION_COMPUTE_MIPMAP,
|
||||
GI_PROBE_SHADER_VERSION_WRITE_TEXTURE,
|
||||
GI_PROBE_SHADER_VERSION_DYNAMIC_OBJECT_LIGHTING,
|
||||
GI_PROBE_SHADER_VERSION_DYNAMIC_SHRINK_WRITE,
|
||||
GI_PROBE_SHADER_VERSION_DYNAMIC_SHRINK_PLOT,
|
||||
GI_PROBE_SHADER_VERSION_DYNAMIC_SHRINK_WRITE_PLOT,
|
||||
GI_PROBE_SHADER_VERSION_MAX
|
||||
};
|
||||
|
||||
GiprobeShaderRD giprobe_shader;
|
||||
RID giprobe_lighting_shader_version;
|
||||
RID giprobe_lighting_shader_version_shaders[GI_PROBE_SHADER_VERSION_MAX];
|
||||
RID giprobe_lighting_shader_version_pipelines[GI_PROBE_SHADER_VERSION_MAX];
|
||||
|
||||
mutable RID_Owner<GIProbeInstance> gi_probe_instance_owner;
|
||||
|
||||
RS::GIProbeQuality gi_probe_quality = RS::GI_PROBE_QUALITY_HIGH;
|
||||
|
||||
enum {
|
||||
GI_PROBE_DEBUG_COLOR,
|
||||
GI_PROBE_DEBUG_LIGHT,
|
||||
GI_PROBE_DEBUG_EMISSION,
|
||||
GI_PROBE_DEBUG_LIGHT_FULL,
|
||||
GI_PROBE_DEBUG_MAX
|
||||
};
|
||||
|
||||
struct GIProbeDebugPushConstant {
|
||||
float projection[16];
|
||||
uint32_t cell_offset;
|
||||
float dynamic_range;
|
||||
float alpha;
|
||||
uint32_t level;
|
||||
int32_t bounds[3];
|
||||
uint32_t pad;
|
||||
};
|
||||
|
||||
GiprobeDebugShaderRD giprobe_debug_shader;
|
||||
RID giprobe_debug_shader_version;
|
||||
RID giprobe_debug_shader_version_shaders[GI_PROBE_DEBUG_MAX];
|
||||
PipelineCacheRD giprobe_debug_shader_version_pipelines[GI_PROBE_DEBUG_MAX];
|
||||
RID giprobe_debug_uniform_set;
|
||||
|
||||
/* SDFGI */
|
||||
|
||||
struct SDFGI {
|
||||
enum {
|
||||
MAX_CASCADES = 8,
|
||||
CASCADE_SIZE = 128,
|
||||
PROBE_DIVISOR = 16,
|
||||
ANISOTROPY_SIZE = 6,
|
||||
MAX_DYNAMIC_LIGHTS = 128,
|
||||
MAX_STATIC_LIGHTS = 1024,
|
||||
LIGHTPROBE_OCT_SIZE = 6,
|
||||
SH_SIZE = 16
|
||||
};
|
||||
|
||||
struct Cascade {
|
||||
struct UBO {
|
||||
float offset[3];
|
||||
float to_cell;
|
||||
int32_t probe_offset[3];
|
||||
uint32_t pad;
|
||||
};
|
||||
|
||||
//cascade blocks are full-size for volume (128^3), half size for albedo/emission
|
||||
RID sdf_tex;
|
||||
RID light_tex;
|
||||
RID light_aniso_0_tex;
|
||||
RID light_aniso_1_tex;
|
||||
|
||||
RID light_data;
|
||||
RID light_aniso_0_data;
|
||||
RID light_aniso_1_data;
|
||||
|
||||
struct SolidCell { // this struct is unused, but remains as reference for size
|
||||
uint32_t position;
|
||||
uint32_t albedo;
|
||||
uint32_t static_light;
|
||||
uint32_t static_light_aniso;
|
||||
};
|
||||
|
||||
RID solid_cell_dispatch_buffer; //buffer for indirect compute dispatch
|
||||
RID solid_cell_buffer;
|
||||
|
||||
RID lightprobe_history_tex;
|
||||
RID lightprobe_average_tex;
|
||||
|
||||
float cell_size;
|
||||
Vector3i position;
|
||||
|
||||
static const Vector3i DIRTY_ALL;
|
||||
Vector3i dirty_regions; //(0,0,0 is not dirty, negative is refresh from the end, DIRTY_ALL is refresh all.
|
||||
|
||||
RID sdf_store_uniform_set;
|
||||
RID sdf_direct_light_uniform_set;
|
||||
RID scroll_uniform_set;
|
||||
RID scroll_occlusion_uniform_set;
|
||||
RID integrate_uniform_set;
|
||||
RID lights_buffer;
|
||||
|
||||
bool all_dynamic_lights_dirty = true;
|
||||
};
|
||||
|
||||
// access to our containers
|
||||
RendererStorageRD *storage;
|
||||
RendererSceneGIRD *gi;
|
||||
|
||||
// used for rendering (voxelization)
|
||||
RID render_albedo;
|
||||
RID render_emission;
|
||||
RID render_emission_aniso;
|
||||
RID render_occlusion[8];
|
||||
RID render_geom_facing;
|
||||
|
||||
RID render_sdf[2];
|
||||
RID render_sdf_half[2];
|
||||
|
||||
// used for ping pong processing in cascades
|
||||
RID sdf_initialize_uniform_set;
|
||||
RID sdf_initialize_half_uniform_set;
|
||||
RID jump_flood_uniform_set[2];
|
||||
RID jump_flood_half_uniform_set[2];
|
||||
RID sdf_upscale_uniform_set;
|
||||
int upscale_jfa_uniform_set_index;
|
||||
RID occlusion_uniform_set;
|
||||
|
||||
uint32_t cascade_size = 128;
|
||||
|
||||
LocalVector<Cascade> cascades;
|
||||
|
||||
RID lightprobe_texture;
|
||||
RID lightprobe_data;
|
||||
RID occlusion_texture;
|
||||
RID occlusion_data;
|
||||
RID ambient_texture; //integrates with volumetric fog
|
||||
|
||||
RID lightprobe_history_scroll; //used for scrolling lightprobes
|
||||
RID lightprobe_average_scroll; //used for scrolling lightprobes
|
||||
|
||||
uint32_t history_size = 0;
|
||||
float solid_cell_ratio = 0;
|
||||
uint32_t solid_cell_count = 0;
|
||||
|
||||
RS::EnvironmentSDFGICascades cascade_mode;
|
||||
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_probes_uniform_set;
|
||||
RID cascades_ubo;
|
||||
|
||||
bool uses_occlusion = false;
|
||||
float bounce_feedback = 0.0;
|
||||
bool reads_sky = false;
|
||||
float energy = 1.0;
|
||||
float normal_bias = 1.1;
|
||||
float probe_bias = 1.1;
|
||||
RS::EnvironmentSDFGIYScale y_scale_mode = RS::ENV_SDFGI_Y_SCALE_DISABLED;
|
||||
|
||||
float y_mult = 1.0;
|
||||
|
||||
uint32_t render_pass = 0;
|
||||
|
||||
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 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 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();
|
||||
|
||||
void debug_draw(const CameraMatrix &p_projection, const Transform &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 pre_process_gi(const Transform &p_transform, RendererSceneRenderRD *p_scene_render);
|
||||
void render_region(RID p_render_buffers, int p_region, const PagedArray<RendererSceneRender::GeometryInstance *> &p_instances, RendererSceneRenderRD *p_scene_render);
|
||||
void render_static_lights(RID p_render_buffers, uint32_t p_cascade_count, const uint32_t *p_cascade_indices, const PagedArray<RID> *p_positional_light_cull_result, RendererSceneRenderRD *p_scene_render);
|
||||
};
|
||||
|
||||
RS::EnvironmentSDFGIRayCount sdfgi_ray_count = RS::ENV_SDFGI_RAY_COUNT_16;
|
||||
RS::EnvironmentSDFGIFramesToConverge sdfgi_frames_to_converge = RS::ENV_SDFGI_CONVERGE_IN_10_FRAMES;
|
||||
RS::EnvironmentSDFGIFramesToUpdateLight sdfgi_frames_to_update_light = RS::ENV_SDFGI_UPDATE_LIGHT_IN_4_FRAMES;
|
||||
|
||||
float sdfgi_solid_cell_ratio = 0.25;
|
||||
Vector3 sdfgi_debug_probe_pos;
|
||||
Vector3 sdfgi_debug_probe_dir;
|
||||
bool sdfgi_debug_probe_enabled = false;
|
||||
Vector3i sdfgi_debug_probe_index;
|
||||
|
||||
struct SDGIShader {
|
||||
enum SDFGIPreprocessShaderVersion {
|
||||
PRE_PROCESS_SCROLL,
|
||||
PRE_PROCESS_SCROLL_OCCLUSION,
|
||||
PRE_PROCESS_JUMP_FLOOD_INITIALIZE,
|
||||
PRE_PROCESS_JUMP_FLOOD_INITIALIZE_HALF,
|
||||
PRE_PROCESS_JUMP_FLOOD,
|
||||
PRE_PROCESS_JUMP_FLOOD_OPTIMIZED,
|
||||
PRE_PROCESS_JUMP_FLOOD_UPSCALE,
|
||||
PRE_PROCESS_OCCLUSION,
|
||||
PRE_PROCESS_STORE,
|
||||
PRE_PROCESS_MAX
|
||||
};
|
||||
|
||||
struct PreprocessPushConstant {
|
||||
int32_t scroll[3];
|
||||
int32_t grid_size;
|
||||
|
||||
int32_t probe_offset[3];
|
||||
int32_t step_size;
|
||||
|
||||
int32_t half_size;
|
||||
uint32_t occlusion_index;
|
||||
int32_t cascade;
|
||||
uint32_t pad;
|
||||
};
|
||||
|
||||
SdfgiPreprocessShaderRD preprocess;
|
||||
RID preprocess_shader;
|
||||
RID preprocess_pipeline[PRE_PROCESS_MAX];
|
||||
|
||||
struct DebugPushConstant {
|
||||
float grid_size[3];
|
||||
uint32_t max_cascades;
|
||||
|
||||
int32_t screen_size[2];
|
||||
uint32_t use_occlusion;
|
||||
float y_mult;
|
||||
|
||||
float cam_extent[3];
|
||||
uint32_t probe_axis_size;
|
||||
|
||||
float cam_transform[16];
|
||||
};
|
||||
|
||||
SdfgiDebugShaderRD debug;
|
||||
RID debug_shader;
|
||||
RID debug_shader_version;
|
||||
RID debug_pipeline;
|
||||
|
||||
enum ProbeDebugMode {
|
||||
PROBE_DEBUG_PROBES,
|
||||
PROBE_DEBUG_VISIBILITY,
|
||||
PROBE_DEBUG_MAX
|
||||
};
|
||||
|
||||
struct DebugProbesPushConstant {
|
||||
float projection[16];
|
||||
|
||||
uint32_t band_power;
|
||||
uint32_t sections_in_band;
|
||||
uint32_t band_mask;
|
||||
float section_arc;
|
||||
|
||||
float grid_size[3];
|
||||
uint32_t cascade;
|
||||
|
||||
uint32_t pad;
|
||||
float y_mult;
|
||||
int32_t probe_debug_index;
|
||||
int32_t probe_axis_size;
|
||||
};
|
||||
|
||||
SdfgiDebugProbesShaderRD debug_probes;
|
||||
RID debug_probes_shader;
|
||||
RID debug_probes_shader_version;
|
||||
|
||||
PipelineCacheRD debug_probes_pipeline[PROBE_DEBUG_MAX];
|
||||
|
||||
struct Light {
|
||||
float color[3];
|
||||
float energy;
|
||||
|
||||
float direction[3];
|
||||
uint32_t has_shadow;
|
||||
|
||||
float position[3];
|
||||
float attenuation;
|
||||
|
||||
uint32_t type;
|
||||
float cos_spot_angle;
|
||||
float inv_spot_attenuation;
|
||||
float radius;
|
||||
|
||||
float shadow_color[4];
|
||||
};
|
||||
|
||||
struct DirectLightPushConstant {
|
||||
float grid_size[3];
|
||||
uint32_t max_cascades;
|
||||
|
||||
uint32_t cascade;
|
||||
uint32_t light_count;
|
||||
uint32_t process_offset;
|
||||
uint32_t process_increment;
|
||||
|
||||
int32_t probe_axis_size;
|
||||
float bounce_feedback;
|
||||
float y_mult;
|
||||
uint32_t use_occlusion;
|
||||
};
|
||||
|
||||
enum {
|
||||
DIRECT_LIGHT_MODE_STATIC,
|
||||
DIRECT_LIGHT_MODE_DYNAMIC,
|
||||
DIRECT_LIGHT_MODE_MAX
|
||||
};
|
||||
SdfgiDirectLightShaderRD direct_light;
|
||||
RID direct_light_shader;
|
||||
RID direct_light_pipeline[DIRECT_LIGHT_MODE_MAX];
|
||||
|
||||
enum {
|
||||
INTEGRATE_MODE_PROCESS,
|
||||
INTEGRATE_MODE_STORE,
|
||||
INTEGRATE_MODE_SCROLL,
|
||||
INTEGRATE_MODE_SCROLL_STORE,
|
||||
INTEGRATE_MODE_MAX
|
||||
};
|
||||
struct IntegratePushConstant {
|
||||
enum {
|
||||
SKY_MODE_DISABLED,
|
||||
SKY_MODE_COLOR,
|
||||
SKY_MODE_SKY,
|
||||
};
|
||||
|
||||
float grid_size[3];
|
||||
uint32_t max_cascades;
|
||||
|
||||
uint32_t probe_axis_size;
|
||||
uint32_t cascade;
|
||||
uint32_t history_index;
|
||||
uint32_t history_size;
|
||||
|
||||
uint32_t ray_count;
|
||||
float ray_bias;
|
||||
int32_t image_size[2];
|
||||
|
||||
int32_t world_offset[3];
|
||||
uint32_t sky_mode;
|
||||
|
||||
int32_t scroll[3];
|
||||
float sky_energy;
|
||||
|
||||
float sky_color[3];
|
||||
float y_mult;
|
||||
|
||||
uint32_t store_ambient_texture;
|
||||
uint32_t pad[3];
|
||||
};
|
||||
|
||||
SdfgiIntegrateShaderRD integrate;
|
||||
RID integrate_shader;
|
||||
RID integrate_pipeline[INTEGRATE_MODE_MAX];
|
||||
|
||||
RID integrate_default_sky_uniform_set;
|
||||
|
||||
} sdfgi_shader;
|
||||
|
||||
/* SDFGI UPDATE */
|
||||
|
||||
int sdfgi_get_lightprobe_octahedron_size() const { return SDFGI::LIGHTPROBE_OCT_SIZE; }
|
||||
|
||||
/* GI */
|
||||
enum {
|
||||
MAX_GIPROBES = 8
|
||||
};
|
||||
|
||||
// Struct for use in render buffer
|
||||
struct RenderBuffersGI {
|
||||
RID giprobe_textures[MAX_GIPROBES];
|
||||
RID giprobe_buffer;
|
||||
|
||||
RID full_buffer;
|
||||
RID full_dispatch;
|
||||
RID full_mask;
|
||||
};
|
||||
|
||||
// struct GI {
|
||||
struct SDFGIData {
|
||||
float grid_size[3];
|
||||
uint32_t max_cascades;
|
||||
|
||||
uint32_t use_occlusion;
|
||||
int32_t probe_axis_size;
|
||||
float probe_to_uvw;
|
||||
float normal_bias;
|
||||
|
||||
float lightprobe_tex_pixel_size[3];
|
||||
float energy;
|
||||
|
||||
float lightprobe_uv_offset[3];
|
||||
float y_mult;
|
||||
|
||||
float occlusion_clamp[3];
|
||||
uint32_t pad3;
|
||||
|
||||
float occlusion_renormalize[3];
|
||||
uint32_t pad4;
|
||||
|
||||
float cascade_probe_size[3];
|
||||
uint32_t pad5;
|
||||
|
||||
struct ProbeCascadeData {
|
||||
float position[3]; //offset of (0,0,0) in world coordinates
|
||||
float to_probe; // 1/bounds * grid_size
|
||||
int32_t probe_world_offset[3];
|
||||
float to_cell; // 1/bounds * grid_size
|
||||
};
|
||||
|
||||
ProbeCascadeData cascades[SDFGI::MAX_CASCADES];
|
||||
};
|
||||
|
||||
struct GIProbeData {
|
||||
float xform[16];
|
||||
float bounds[3];
|
||||
float dynamic_range;
|
||||
|
||||
float bias;
|
||||
float normal_bias;
|
||||
uint32_t blend_ambient;
|
||||
uint32_t texture_slot;
|
||||
|
||||
float anisotropy_strength;
|
||||
float ao;
|
||||
float ao_size;
|
||||
uint32_t mipmaps;
|
||||
};
|
||||
|
||||
struct PushConstant {
|
||||
int32_t screen_size[2];
|
||||
float z_near;
|
||||
float z_far;
|
||||
|
||||
float proj_info[4];
|
||||
float ao_color[3];
|
||||
uint32_t max_giprobes;
|
||||
|
||||
uint32_t high_quality_vct;
|
||||
uint32_t orthogonal;
|
||||
uint32_t pad[2];
|
||||
|
||||
float cam_rotation[12];
|
||||
};
|
||||
|
||||
RID sdfgi_ubo;
|
||||
enum Mode {
|
||||
MODE_GIPROBE,
|
||||
MODE_SDFGI,
|
||||
MODE_COMBINED,
|
||||
MODE_HALF_RES_GIPROBE,
|
||||
MODE_HALF_RES_SDFGI,
|
||||
MODE_HALF_RES_COMBINED,
|
||||
MODE_MAX
|
||||
};
|
||||
|
||||
RID default_giprobe_buffer;
|
||||
|
||||
bool half_resolution = false;
|
||||
GiShaderRD shader;
|
||||
RID shader_version;
|
||||
RID pipelines[MODE_MAX];
|
||||
// } gi;
|
||||
|
||||
RendererSceneGIRD();
|
||||
~RendererSceneGIRD();
|
||||
|
||||
// !BAS! Can we merge these two inits? Possibly, need to check
|
||||
void init_gi(RendererStorageRD *p_storage);
|
||||
void init_sdfgi(RendererSceneSkyRD *p_sky);
|
||||
void free();
|
||||
|
||||
SDFGI *create_sdfgi(RendererSceneEnvironmentRD *p_env, const Vector3 &p_world_position, uint32_t p_requested_history_size);
|
||||
|
||||
void setup_giprobes(RID p_render_buffers, const Transform &p_transform, const PagedArray<RID> &p_gi_probes, uint32_t &r_gi_probes_used, RendererSceneRenderRD *p_scene_render);
|
||||
void process_gi(RID p_render_buffers, RID p_normal_roughness_buffer, RID p_gi_probe_buffer, RID p_environment, const CameraMatrix &p_projection, const Transform &p_transform, const PagedArray<RID> &p_gi_probes, RendererSceneRenderRD *p_scene_render);
|
||||
|
||||
RID gi_probe_instance_create(RID p_base);
|
||||
void debug_giprobe(RID p_gi_probe, 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 */
|
@ -1130,7 +1130,7 @@ void RendererSceneRenderForward::_setup_environment(RID p_environment, RID p_ren
|
||||
//vec2 tex_pixel_size = 1.0 / vec2(ivec2( (OCT_SIZE+2) * params.probe_axis_size * params.probe_axis_size, (OCT_SIZE+2) * params.probe_axis_size ) );
|
||||
//vec3 probe_uv_offset = (ivec3(OCT_SIZE+2,OCT_SIZE+2,(OCT_SIZE+2) * params.probe_axis_size)) * tex_pixel_size.xyx;
|
||||
|
||||
uint32_t oct_size = sdfgi_get_lightprobe_octahedron_size();
|
||||
uint32_t oct_size = gi.sdfgi_get_lightprobe_octahedron_size();
|
||||
|
||||
scene_state.ubo.sdfgi_lightprobe_tex_pixel_size[0] = 1.0 / ((oct_size + 2) * scene_state.ubo.sdfgi_probe_axis_size * scene_state.ubo.sdfgi_probe_axis_size);
|
||||
scene_state.ubo.sdfgi_lightprobe_tex_pixel_size[1] = 1.0 / ((oct_size + 2) * scene_state.ubo.sdfgi_probe_axis_size);
|
||||
@ -1583,6 +1583,7 @@ void RendererSceneRenderForward::_render_scene(RID p_render_buffer, const Transf
|
||||
if (p_render_buffer.is_valid()) {
|
||||
render_buffer = (RenderBufferDataForward *)render_buffers_get_data(p_render_buffer);
|
||||
}
|
||||
RendererSceneEnvironmentRD *env = get_environment(p_environment);
|
||||
|
||||
//first of all, make a new render pass
|
||||
//fill up ubo
|
||||
@ -1729,7 +1730,7 @@ void RendererSceneRenderForward::_render_scene(RID p_render_buffer, const Transf
|
||||
clear_color.b *= bg_energy;
|
||||
if (render_buffers_has_volumetric_fog(p_render_buffer) || environment_is_fog_enabled(p_environment)) {
|
||||
draw_sky_fog_only = true;
|
||||
storage->material_set_param(sky_scene_state.fog_material, "clear_color", Variant(clear_color.to_linear()));
|
||||
storage->material_set_param(sky.sky_scene_state.fog_material, "clear_color", Variant(clear_color.to_linear()));
|
||||
}
|
||||
} break;
|
||||
case RS::ENV_BG_COLOR: {
|
||||
@ -1739,7 +1740,7 @@ void RendererSceneRenderForward::_render_scene(RID p_render_buffer, const Transf
|
||||
clear_color.b *= bg_energy;
|
||||
if (render_buffers_has_volumetric_fog(p_render_buffer) || environment_is_fog_enabled(p_environment)) {
|
||||
draw_sky_fog_only = true;
|
||||
storage->material_set_param(sky_scene_state.fog_material, "clear_color", Variant(clear_color.to_linear()));
|
||||
storage->material_set_param(sky.sky_scene_state.fog_material, "clear_color", Variant(clear_color.to_linear()));
|
||||
}
|
||||
} break;
|
||||
case RS::ENV_BG_SKY: {
|
||||
@ -1767,12 +1768,12 @@ void RendererSceneRenderForward::_render_scene(RID p_render_buffer, const Transf
|
||||
projection = correction * p_cam_projection;
|
||||
}
|
||||
|
||||
_setup_sky(p_environment, p_render_buffer, projection, p_cam_transform, screen_size);
|
||||
sky.setup(env, p_render_buffer, projection, p_cam_transform, screen_size, this);
|
||||
|
||||
RID sky = environment_get_sky(p_environment);
|
||||
if (sky.is_valid()) {
|
||||
_update_sky(p_environment, projection, p_cam_transform);
|
||||
radiance_texture = sky_get_radiance_texture_rd(sky);
|
||||
RID sky_rid = env->sky;
|
||||
if (sky_rid.is_valid()) {
|
||||
sky.update(env, projection, p_cam_transform, time);
|
||||
radiance_texture = sky.sky_get_radiance_texture_rd(sky_rid);
|
||||
} else {
|
||||
// do not try to draw sky if invalid
|
||||
draw_sky = false;
|
||||
@ -1890,7 +1891,7 @@ void RendererSceneRenderForward::_render_scene(RID p_render_buffer, const Transf
|
||||
RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(opaque_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 GIProbes");
|
||||
for (int i = 0; i < (int)p_gi_probes.size(); i++) {
|
||||
_debug_giprobe(p_gi_probes[i], draw_list, opaque_framebuffer, cm, get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_GI_PROBE_LIGHTING, get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_GI_PROBE_EMISSION, 1.0);
|
||||
gi.debug_giprobe(p_gi_probes[i], draw_list, opaque_framebuffer, cm, get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_GI_PROBE_LIGHTING, get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_GI_PROBE_EMISSION, 1.0);
|
||||
}
|
||||
RD::get_singleton()->draw_command_end_label();
|
||||
RD::get_singleton()->draw_list_end();
|
||||
@ -1921,7 +1922,7 @@ void RendererSceneRenderForward::_render_scene(RID p_render_buffer, const Transf
|
||||
projection = correction * p_cam_projection;
|
||||
}
|
||||
RD::get_singleton()->draw_command_begin_label("Draw Sky");
|
||||
_draw_sky(can_continue_color, can_continue_depth, opaque_framebuffer, p_environment, projection, p_cam_transform);
|
||||
sky.draw(env, can_continue_color, can_continue_depth, opaque_framebuffer, projection, p_cam_transform, time);
|
||||
RD::get_singleton()->draw_command_end_label();
|
||||
}
|
||||
|
||||
@ -3346,7 +3347,7 @@ RendererSceneRenderForward::RendererSceneRenderForward(RendererStorageRD *p_stor
|
||||
if (is_using_radiance_cubemap_array()) {
|
||||
defines += "\n#define USE_RADIANCE_CUBEMAP_ARRAY \n";
|
||||
}
|
||||
defines += "\n#define SDFGI_OCT_SIZE " + itos(sdfgi_get_lightprobe_octahedron_size()) + "\n";
|
||||
defines += "\n#define SDFGI_OCT_SIZE " + itos(gi.sdfgi_get_lightprobe_octahedron_size()) + "\n";
|
||||
defines += "\n#define MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS " + itos(get_max_directional_lights()) + "\n";
|
||||
|
||||
{
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1491
servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp
Normal file
1491
servers/rendering/renderer_rd/renderer_scene_sky_rd.cpp
Normal file
File diff suppressed because it is too large
Load Diff
292
servers/rendering/renderer_rd/renderer_scene_sky_rd.h
Normal file
292
servers/rendering/renderer_rd/renderer_scene_sky_rd.h
Normal file
@ -0,0 +1,292 @@
|
||||
/*************************************************************************/
|
||||
/* renderer_scene_sky_rd.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2021 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 RENDERING_SERVER_SCENE_SKY_RD_H
|
||||
#define RENDERING_SERVER_SCENE_SKY_RD_H
|
||||
|
||||
#include "core/templates/rid_owner.h"
|
||||
#include "servers/rendering/renderer_compositor.h"
|
||||
#include "servers/rendering/renderer_rd/renderer_scene_environment_rd.h"
|
||||
#include "servers/rendering/renderer_rd/renderer_storage_rd.h"
|
||||
#include "servers/rendering/renderer_rd/shaders/sky.glsl.gen.h"
|
||||
#include "servers/rendering/renderer_scene_render.h"
|
||||
#include "servers/rendering/rendering_device.h"
|
||||
|
||||
// Forward declare RendererSceneRenderRD so we can pass it into some of our methods, these classes are pretty tightly bound
|
||||
class RendererSceneRenderRD;
|
||||
|
||||
class RendererSceneSkyRD {
|
||||
private:
|
||||
RendererStorageRD *storage;
|
||||
|
||||
public:
|
||||
enum SkySet {
|
||||
SKY_SET_UNIFORMS,
|
||||
SKY_SET_MATERIAL,
|
||||
SKY_SET_TEXTURES,
|
||||
SKY_SET_FOG,
|
||||
SKY_SET_MAX
|
||||
};
|
||||
|
||||
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_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];
|
||||
};
|
||||
|
||||
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;
|
||||
SkyDirectionalLightData *last_frame_directional_lights;
|
||||
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;
|
||||
};
|
||||
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);
|
||||
void create_reflection_fast_filter(RendererStorageRD *p_storage, bool p_use_arrays);
|
||||
void create_reflection_importance_sample(RendererStorageRD *p_storage, bool p_use_arrays, int p_cube_side, int p_base_layer, uint32_t p_sky_ggx_samples_quality);
|
||||
void update_reflection_mipmaps(RendererStorageRD *p_storage, int p_start, int p_end);
|
||||
};
|
||||
|
||||
struct SkyShaderData : public RendererStorageRD::ShaderData {
|
||||
bool valid;
|
||||
RID version;
|
||||
|
||||
PipelineCacheRD pipelines[SKY_VERSION_MAX];
|
||||
Map<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
|
||||
Vector<ShaderCompilerRD::GeneratedCode::Texture> texture_uniforms;
|
||||
|
||||
Vector<uint32_t> ubo_offsets;
|
||||
uint32_t ubo_size;
|
||||
|
||||
String path;
|
||||
String code;
|
||||
Map<StringName, RID> default_texture_params;
|
||||
|
||||
bool uses_time;
|
||||
bool uses_position;
|
||||
bool uses_half_res;
|
||||
bool uses_quarter_res;
|
||||
bool uses_light;
|
||||
|
||||
virtual void set_code(const String &p_Code);
|
||||
virtual void set_default_texture_param(const StringName &p_name, RID p_texture);
|
||||
virtual void get_param_list(List<PropertyInfo> *p_param_list) const;
|
||||
virtual void get_instance_param_list(List<RendererStorage::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();
|
||||
};
|
||||
|
||||
/* Sky shader */
|
||||
|
||||
struct SkyShader {
|
||||
SkyShaderRD shader;
|
||||
ShaderCompilerRD compiler;
|
||||
|
||||
RID default_shader;
|
||||
RID default_material;
|
||||
RID default_shader_rd;
|
||||
} sky_shader;
|
||||
|
||||
struct SkyMaterialData : public RendererStorageRD::MaterialData {
|
||||
uint64_t last_frame;
|
||||
SkyShaderData *shader_data;
|
||||
RID uniform_buffer;
|
||||
RID uniform_set;
|
||||
Vector<RID> texture_cache;
|
||||
Vector<uint8_t> ubo_data;
|
||||
bool uniform_set_updated;
|
||||
|
||||
virtual void set_render_priority(int p_priority) {}
|
||||
virtual void set_next_pass(RID p_pass) {}
|
||||
virtual void update_parameters(const Map<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;
|
||||
Vector3 prev_position;
|
||||
float prev_time;
|
||||
|
||||
void free(RendererStorageRD *p_storage);
|
||||
|
||||
RID get_textures(RendererStorageRD *p_storage, 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(RendererStorageRD *p_storage, 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;
|
||||
|
||||
RendererStorageRD::ShaderData *_create_sky_shader_func();
|
||||
static RendererStorageRD::ShaderData *_create_sky_shader_funcs();
|
||||
|
||||
RendererStorageRD::MaterialData *_create_sky_material_func(SkyShaderData *p_shader);
|
||||
static RendererStorageRD::MaterialData *_create_sky_material_funcs(RendererStorageRD::ShaderData *p_shader);
|
||||
|
||||
RendererSceneSkyRD();
|
||||
|
||||
void init(RendererStorageRD *p_storage);
|
||||
|
||||
void setup(RendererSceneEnvironmentRD *p_env, RID p_render_buffers, const CameraMatrix &p_projection, const Transform &p_transform, const Size2i p_screen_size, RendererSceneRenderRD *p_scene_render);
|
||||
void update(RendererSceneEnvironmentRD *p_env, const CameraMatrix &p_projection, const Transform &p_transform, double p_time);
|
||||
void draw(RendererSceneEnvironmentRD *p_env, bool p_can_continue_color, bool p_can_continue_depth, RID p_fb, const CameraMatrix &p_projection, const Transform &p_transform, double p_time);
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
#endif /* RENDERING_SERVER_SCENE_SKY_RD_H */
|
Loading…
Reference in New Issue
Block a user