1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

Add optional depth fog

This commit is contained in:
Eidolon
2022-09-18 00:31:43 -05:00
committed by Rafael Correa
parent 9283d0d65c
commit 08f4560e69
27 changed files with 406 additions and 33 deletions

View File

@@ -656,6 +656,7 @@ layout(constant_id = 9) const uint sc_directional_penumbra_shadow_samples = 4;
layout(constant_id = 10) const bool sc_decal_use_mipmaps = true;
layout(constant_id = 11) const bool sc_projector_use_mipmaps = true;
layout(constant_id = 12) const bool sc_use_depth_fog = false;
// not used in clustered renderer but we share some code with the mobile renderer that requires this.
const float sc_luminance_multiplier = 1.0;
@@ -848,7 +849,15 @@ vec4 fog_process(vec3 vertex) {
}
}
float fog_amount = 1.0 - exp(min(0.0, -length(vertex) * scene_data_block.data.fog_density));
float fog_amount = 0.0;
if (sc_use_depth_fog) {
float fog_z = smoothstep(scene_data_block.data.fog_depth_begin, scene_data_block.data.fog_depth_end, length(vertex));
float fog_quad_amount = pow(fog_z, scene_data_block.data.fog_depth_curve) * scene_data_block.data.fog_density;
fog_amount = fog_quad_amount;
} else {
fog_amount = 1 - exp(min(0.0, -length(vertex) * scene_data_block.data.fog_density));
}
if (abs(scene_data_block.data.fog_height_density) >= 0.0001) {
float y = (scene_data_block.data.inv_view_matrix * vec4(vertex, 1.0)).y;

View File

@@ -525,6 +525,7 @@ layout(constant_id = 12) const bool sc_disable_directional_lights = false;
layout(constant_id = 7) const bool sc_decal_use_mipmaps = true;
layout(constant_id = 13) const bool sc_disable_decals = false;
layout(constant_id = 14) const bool sc_disable_fog = false;
layout(constant_id = 16) const bool sc_use_depth_fog = false;
#endif //!MODE_RENDER_DEPTH
@@ -690,7 +691,15 @@ vec4 fog_process(vec3 vertex) {
}
}
float fog_amount = 1.0 - exp(min(0.0, -length(vertex) * scene_data_block.data.fog_density));
float fog_amount = 0.0;
if (sc_use_depth_fog) {
float fog_z = smoothstep(scene_data_block.data.fog_depth_begin, scene_data_block.data.fog_depth_end, length(vertex));
float fog_quad_amount = pow(fog_z, scene_data_block.data.fog_depth_curve) * scene_data_block.data.fog_density;
fog_amount = fog_quad_amount;
} else {
fog_amount = 1 - exp(min(0.0, -length(vertex) * scene_data_block.data.fog_density));
}
if (abs(scene_data_block.data.fog_height_density) >= 0.0001) {
float y = (scene_data_block.data.inv_view_matrix * vec4(vertex, 1.0)).y;

View File

@@ -49,24 +49,29 @@ struct SceneData {
mediump float opaque_prepass_threshold;
bool fog_enabled;
uint fog_mode;
highp float fog_density;
highp float fog_height;
highp float fog_height_density;
mediump vec3 fog_light_color;
mediump float fog_sun_scatter;
highp float fog_depth_curve;
highp float pad;
highp float fog_depth_begin;
mediump vec3 fog_light_color;
highp float fog_depth_end;
mediump float fog_sun_scatter;
mediump float fog_aerial_perspective;
highp float time;
mediump float reflection_multiplier; // one normally, zero when rendering reflections
bool material_uv2_mode;
vec2 taa_jitter;
bool material_uv2_mode;
float emissive_exposure_normalization;
float IBL_exposure_normalization;
float IBL_exposure_normalization;
bool pancake_shadows;
uint camera_visible_layers;
float pass_alpha_multiplier;
uint pad3;
};