Fix the height fog effect

This commit is contained in:
Brian Semrau 2021-10-14 03:52:10 -04:00
parent 5f33cc0f0e
commit a62e240260
4 changed files with 9 additions and 7 deletions

View File

@ -101,8 +101,10 @@
If [code]true[/code], fog effects are enabled.
</member>
<member name="fog_height" type="float" setter="set_fog_height" getter="get_fog_height" default="0.0">
The height at which the height fog effect begins.
</member>
<member name="fog_height_density" type="float" setter="set_fog_height_density" getter="get_fog_height_density" default="0.0">
The density used to increase fog as height decreases. To make fog increase as height increases, use a negative value.
</member>
<member name="fog_light_color" type="Color" setter="set_fog_light_color" getter="get_fog_light_color" default="Color(0.5, 0.6, 0.7, 1)">
</member>

View File

@ -1291,7 +1291,7 @@ void Environment::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fog_density", PROPERTY_HINT_RANGE, "0,16,0.0001"), "set_fog_density", "get_fog_density");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fog_aerial_perspective", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_fog_aerial_perspective", "get_fog_aerial_perspective");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fog_height", PROPERTY_HINT_RANGE, "-1024,1024,0.01,or_lesser,or_greater"), "set_fog_height", "get_fog_height");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fog_height_density", PROPERTY_HINT_RANGE, "0,128,0.001,or_greater"), "set_fog_height_density", "get_fog_height_density");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fog_height_density", PROPERTY_HINT_RANGE, "-16,16,0.0001,or_lesser,or_greater"), "set_fog_height_density", "get_fog_height_density");
ClassDB::bind_method(D_METHOD("set_volumetric_fog_enabled", "enabled"), &Environment::set_volumetric_fog_enabled);
ClassDB::bind_method(D_METHOD("is_volumetric_fog_enabled"), &Environment::is_volumetric_fog_enabled);

View File

@ -526,12 +526,12 @@ vec4 fog_process(vec3 vertex) {
float fog_amount = 1.0 - exp(min(0.0, -length(vertex) * scene_data.fog_density));
if (abs(scene_data.fog_height_density) > 0.001) {
if (abs(scene_data.fog_height_density) >= 0.0001) {
float y = (scene_data.camera_matrix * vec4(vertex, 1.0)).y;
float y_dist = scene_data.fog_height - y;
float y_dist = y - scene_data.fog_height;
float vfog_amount = clamp(exp(y_dist * scene_data.fog_height_density), 0.0, 1.0);
float vfog_amount = clamp(1.0 - exp(y_dist * scene_data.fog_height_density), 0.0, 1.0);
fog_amount = max(vfog_amount, fog_amount);
}

View File

@ -552,12 +552,12 @@ vec4 fog_process(vec3 vertex) {
float fog_amount = 1.0 - exp(min(0.0, -length(vertex) * scene_data.fog_density));
if (abs(scene_data.fog_height_density) > 0.001) {
if (abs(scene_data.fog_height_density) >= 0.0001) {
float y = (scene_data.camera_matrix * vec4(vertex, 1.0)).y;
float y_dist = scene_data.fog_height - y;
float y_dist = y - scene_data.fog_height;
float vfog_amount = clamp(exp(y_dist * scene_data.fog_height_density), 0.0, 1.0);
float vfog_amount = clamp(1.0 - exp(y_dist * scene_data.fog_height_density), 0.0, 1.0);
fog_amount = max(vfog_amount, fog_amount);
}