summaryrefslogtreecommitdiff
path: root/drivers/gles3
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gles3')
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.cpp5
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.h6
-rw-r--r--drivers/gles3/shaders/scene.glsl9
3 files changed, 16 insertions, 4 deletions
diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp
index fcb68f44fe..7df9e137e1 100644
--- a/drivers/gles3/rasterizer_scene_gles3.cpp
+++ b/drivers/gles3/rasterizer_scene_gles3.cpp
@@ -934,13 +934,14 @@ void RasterizerSceneGLES3::environment_set_fog(RID p_env, bool p_enable, const C
env->fog_sun_amount = p_sun_amount;
}
-void RasterizerSceneGLES3::environment_set_fog_depth(RID p_env, bool p_enable, float p_depth_begin, float p_depth_curve, bool p_transmit, float p_transmit_curve) {
+void RasterizerSceneGLES3::environment_set_fog_depth(RID p_env, bool p_enable, float p_depth_begin, float p_depth_end, float p_depth_curve, bool p_transmit, float p_transmit_curve) {
Environment *env = environment_owner.getornull(p_env);
ERR_FAIL_COND(!env);
env->fog_depth_enabled = p_enable;
env->fog_depth_begin = p_depth_begin;
+ env->fog_depth_end = p_depth_end;
env->fog_depth_curve = p_depth_curve;
env->fog_transmit_enabled = p_transmit;
env->fog_transmit_curve = p_transmit_curve;
@@ -2568,6 +2569,7 @@ void RasterizerSceneGLES3::_setup_environment(Environment *env, const CameraMatr
state.ubo_data.fog_color_enabled[1] = linear_fog.g;
state.ubo_data.fog_color_enabled[2] = linear_fog.b;
state.ubo_data.fog_color_enabled[3] = (!p_no_fog && env->fog_enabled) ? 1.0 : 0.0;
+ state.ubo_data.fog_density = linear_fog.a;
Color linear_sun = env->fog_sun_color.to_linear();
state.ubo_data.fog_sun_color_amount[0] = linear_sun.r;
@@ -2576,6 +2578,7 @@ void RasterizerSceneGLES3::_setup_environment(Environment *env, const CameraMatr
state.ubo_data.fog_sun_color_amount[3] = env->fog_sun_amount;
state.ubo_data.fog_depth_enabled = env->fog_depth_enabled;
state.ubo_data.fog_depth_begin = env->fog_depth_begin;
+ state.ubo_data.fog_depth_end = env->fog_depth_end;
state.ubo_data.fog_depth_curve = env->fog_depth_curve;
state.ubo_data.fog_transmit_enabled = env->fog_transmit_enabled;
state.ubo_data.fog_transmit_curve = env->fog_transmit_curve;
diff --git a/drivers/gles3/rasterizer_scene_gles3.h b/drivers/gles3/rasterizer_scene_gles3.h
index 4b4a0b9303..f3157d5a46 100644
--- a/drivers/gles3/rasterizer_scene_gles3.h
+++ b/drivers/gles3/rasterizer_scene_gles3.h
@@ -145,6 +145,8 @@ public:
uint32_t fog_depth_enabled;
float fog_depth_begin;
+ float fog_depth_end;
+ float fog_density;
float fog_depth_curve;
uint32_t fog_transmit_enabled;
float fog_transmit_curve;
@@ -438,6 +440,7 @@ public:
bool fog_depth_enabled;
float fog_depth_begin;
+ float fog_depth_end;
float fog_depth_curve;
bool fog_transmit_enabled;
float fog_transmit_curve;
@@ -518,6 +521,7 @@ public:
fog_depth_enabled = true;
fog_depth_begin = 10;
+ fog_depth_end = 0;
fog_depth_curve = 1;
fog_transmit_enabled = true;
@@ -555,7 +559,7 @@ public:
virtual void environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, RID p_ramp);
virtual void environment_set_fog(RID p_env, bool p_enable, const Color &p_color, const Color &p_sun_color, float p_sun_amount);
- virtual void environment_set_fog_depth(RID p_env, bool p_enable, float p_depth_begin, float p_depth_curve, bool p_transmit, float p_transmit_curve);
+ virtual void environment_set_fog_depth(RID p_env, bool p_enable, float p_depth_begin, float p_depth_end, float p_depth_curve, bool p_transmit, float p_transmit_curve);
virtual void environment_set_fog_height(RID p_env, bool p_enable, float p_min_height, float p_max_height, float p_height_curve);
virtual bool is_environment(RID p_env);
diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl
index 91ab34f775..ef36978258 100644
--- a/drivers/gles3/shaders/scene.glsl
+++ b/drivers/gles3/shaders/scene.glsl
@@ -98,6 +98,8 @@ layout(std140) uniform SceneData { // ubo:0
bool fog_depth_enabled;
highp float fog_depth_begin;
+ highp float fog_depth_end;
+ mediump float fog_density;
highp float fog_depth_curve;
bool fog_transmit_enabled;
highp float fog_transmit_curve;
@@ -675,6 +677,8 @@ layout(std140) uniform SceneData {
bool fog_depth_enabled;
highp float fog_depth_begin;
+ highp float fog_depth_end;
+ mediump float fog_density;
highp float fog_depth_curve;
bool fog_transmit_enabled;
highp float fog_transmit_curve;
@@ -2033,10 +2037,11 @@ FRAGMENT_SHADER_CODE
//apply fog
if (fog_depth_enabled) {
+ float fog_far = fog_depth_end > 0 ? fog_depth_end : z_far;
- float fog_z = smoothstep(fog_depth_begin, z_far, length(vertex));
+ float fog_z = smoothstep(fog_depth_begin, fog_far, length(vertex));
- fog_amount = pow(fog_z, fog_depth_curve);
+ fog_amount = pow(fog_z, fog_depth_curve) * fog_density;
if (fog_transmit_enabled) {
vec3 total_light = emission + ambient_light + specular_light + diffuse_light;
float transmit = pow(fog_z, fog_transmit_curve);