Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Pass fog distance to shaders

  • Loading branch information...
commit 71901c2ae330fc6d0d1123a75b02029a2ee63058 1 parent 918ccdb
@celeron55 authored
View
7 client/shaders/test_shader_1/opengl_fragment.glsl
@@ -1,6 +1,7 @@
uniform sampler2D myTexture;
uniform vec4 skyBgColor;
+uniform float fogDistance;
varying vec3 vPosition;
@@ -16,7 +17,9 @@ void main (void)
col.g = 1.0 - exp(1.0 - col.g) / exp(1.0);
col.b = 1.0 - exp(1.0 - col.b) / exp(1.0);
col = sqrt(col); // Linear -> SRGB
- float d = max(0.0, min(vPosition.z / 800.0 - 0.8, 1.0));
- col = mix(col, skyBgColor, d);
+ if(fogDistance != 0.0){
+ float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));
+ col = mix(col, skyBgColor, d);
+ }
gl_FragColor = vec4(col.r, col.g, col.b, a);
}
View
9 client/shaders/test_shader_2/opengl_fragment.glsl
@@ -1,5 +1,6 @@
uniform sampler2D myTexture;
+uniform float fogDistance;
varying vec3 vPosition;
@@ -14,7 +15,9 @@ void main (void)
col.g = 1.0 - exp(1.0 - col.g) / exp(1.0);
col.b = 1.0 - exp(1.0 - col.b) / exp(1.0);
col = sqrt(col); // Linear -> SRGB
- float d = max(0.0, min(vPosition.z / 800.0 - 0.8, 1.0));
- a = mix(a, 0.0, d);
- gl_FragColor = vec4(col.r, col.g, col.b, a);
+ if(fogDistance != 0.0){
+ float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0));
+ a = mix(a, 0.0, d);
+ }
+ gl_FragColor = vec4(col.r, col.g, col.b, a);
}
View
30 src/game.cpp
@@ -839,10 +839,15 @@ class GameOnDemandSoundFetcher: public OnDemandSoundFetcher
class GameGlobalShaderConstantSetter : public IShaderConstantSetter
{
Sky *m_sky;
+ bool *m_force_fog_off;
+ f32 *m_fog_range;
public:
- GameGlobalShaderConstantSetter(Sky *sky):
- m_sky(sky)
+ GameGlobalShaderConstantSetter(Sky *sky, bool *force_fog_off,
+ f32 *fog_range):
+ m_sky(sky),
+ m_force_fog_off(force_fog_off),
+ m_fog_range(fog_range)
{}
~GameGlobalShaderConstantSetter() {}
@@ -852,6 +857,7 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
if(!is_highlevel)
return;
+ // Background color
video::SColor bgcolor = m_sky->getBgColor();
video::SColorf bgcolorf(bgcolor);
float bgcolorfa[4] = {
@@ -861,6 +867,12 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
bgcolorf.a,
};
services->setPixelShaderConstant("skyBgColor", bgcolorfa, 4);
+
+ // Fog distance
+ float fog_distance = *m_fog_range;
+ if(*m_force_fog_off)
+ fog_distance = 10000*BS;
+ services->setPixelShaderConstant("fogDistance", &fog_distance, 1);
}
private:
@@ -1178,12 +1190,6 @@ void the_game(
}
/*
- Shader constants
- */
- shsrc->addGlobalConstantSetter(
- new GameGlobalShaderConstantSetter(sky));
-
- /*
A copy of the local inventory
*/
Inventory local_inventory(itemdef);
@@ -1288,6 +1294,7 @@ void the_game(
bool show_hud = true;
bool show_chat = true;
bool force_fog_off = false;
+ f32 fog_range = 100*BS;
bool disable_camera_update = false;
bool show_debug = g_settings->getBool("show_debug");
bool show_profiler_graph = false;
@@ -1298,6 +1305,12 @@ void the_game(
float time_of_day_smooth = 0;
/*
+ Shader constants
+ */
+ shsrc->addGlobalConstantSetter(
+ new GameGlobalShaderConstantSetter(sky, &force_fog_off, &fog_range));
+
+ /*
Main loop
*/
@@ -2471,7 +2484,6 @@ void the_game(
Fog range
*/
- f32 fog_range;
if(farmesh)
{
fog_range = BS*farmesh_range;
Please sign in to comment.
Something went wrong with that request. Please try again.