diff --git a/shaders/gbuffers_basic.fsh b/shaders/gbuffers_basic.fsh index 9344816..8e623b8 100644 --- a/shaders/gbuffers_basic.fsh +++ b/shaders/gbuffers_basic.fsh @@ -2,6 +2,11 @@ // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. +//Fog mode +uniform int fogMode; +const int GL_LINEAR = 9729; +const int GL_EXP = 2048; + //0 = default, 1 = water, 2 = lava. uniform int isEyeInWater; @@ -12,12 +17,14 @@ void main() { vec4 col = color; - //Calculate fog intensity in or out of water. - float fog = (isEyeInWater>0) ? 1.-exp(-gl_FogFragCoord * gl_Fog.density): - clamp((gl_FogFragCoord-gl_Fog.start) * gl_Fog.scale, 0., 1.); - - //Apply the fog. - col.rgb = mix(col.rgb, gl_Fog.color.rgb, fog); + //Calculate and apply fog intensity. + if(fogMode == GL_LINEAR){ + float fog = clamp((gl_FogFragCoord-gl_Fog.start) * gl_Fog.scale, 0., 1.); + col.rgb = mix(col.rgb, gl_Fog.color.rgb, fog); + } else if(fogMode == GL_EXP || isEyeInWater >= 1){ + float fog = 1.-clamp(exp(-gl_FogFragCoord * gl_Fog.density), 0., 1.); + col.rgb = mix(col.rgb, gl_Fog.color.rgb, fog); + } //Output the result. /*DRAWBUFFERS:0*/ diff --git a/shaders/gbuffers_clouds.fsh b/shaders/gbuffers_clouds.fsh index b6a7667..c46f98d 100644 --- a/shaders/gbuffers_clouds.fsh +++ b/shaders/gbuffers_clouds.fsh @@ -5,6 +5,11 @@ //Diffuse (color) texture. uniform sampler2D texture; +//Fog mode +uniform int fogMode; +const int GL_LINEAR = 9729; +const int GL_EXP = 2048; + //0 = default, 1 = water, 2 = lava. uniform int isEyeInWater; @@ -18,12 +23,14 @@ void main() //Sample texture times Visibility. vec4 col = color * texture2D(texture,coord0); - //Calculate fog intensity in or out of water. - float fog = (isEyeInWater>0) ? 1.-exp(-gl_FogFragCoord * gl_Fog.density): - clamp((gl_FogFragCoord-gl_Fog.start) * gl_Fog.scale, 0., 1.); - - //Apply the fog. - col.rgb = mix(col.rgb, gl_Fog.color.rgb, fog); + //Calculate and apply fog intensity. + if(fogMode == GL_LINEAR){ + float fog = clamp((gl_FogFragCoord-gl_Fog.start) * gl_Fog.scale, 0., 1.); + col.rgb = mix(col.rgb, gl_Fog.color.rgb, fog); + } else if(fogMode == GL_EXP || isEyeInWater >= 1){ + float fog = 1.-clamp(exp(-gl_FogFragCoord * gl_Fog.density), 0., 1.); + col.rgb = mix(col.rgb, gl_Fog.color.rgb, fog); + } //Output the result. /*DRAWBUFFERS:0*/ diff --git a/shaders/gbuffers_damagedblock.fsh b/shaders/gbuffers_damagedblock.fsh index b57b7a4..8fcaf11 100644 --- a/shaders/gbuffers_damagedblock.fsh +++ b/shaders/gbuffers_damagedblock.fsh @@ -7,6 +7,11 @@ uniform sampler2D texture; //Lighting from day/night + shadows + light sources. uniform sampler2D lightmap; +//Fog mode +uniform int fogMode; +const int GL_LINEAR = 9729; +const int GL_EXP = 2048; + //0 = default, 1 = water, 2 = lava. uniform int isEyeInWater; @@ -19,12 +24,14 @@ void main() //Sample texture vec4 col = texture2D(texture,coord0); - //Calculate fog intensity in or out of water. - float fog = (isEyeInWater>0) ? 1.-exp(-gl_FogFragCoord * gl_Fog.density): - clamp((gl_FogFragCoord-gl_Fog.start) * gl_Fog.scale, 0., 1.); - - //Apply the fog. - col.rgb = mix(col.rgb, gl_Fog.color.rgb, fog); + //Calculate and apply fog intensity. + if(fogMode == GL_LINEAR){ + float fog = clamp((gl_FogFragCoord-gl_Fog.start) * gl_Fog.scale, 0., 1.); + col.rgb = mix(col.rgb, gl_Fog.color.rgb, fog); + } else if(fogMode == GL_EXP || isEyeInWater >= 1){ + float fog = 1.-clamp(exp(-gl_FogFragCoord * gl_Fog.density), 0., 1.); + col.rgb = mix(col.rgb, gl_Fog.color.rgb, fog); + } //Output the result. /*DRAWBUFFERS:0*/ diff --git a/shaders/gbuffers_textured.fsh b/shaders/gbuffers_textured.fsh index b89aec0..148270b 100644 --- a/shaders/gbuffers_textured.fsh +++ b/shaders/gbuffers_textured.fsh @@ -9,6 +9,12 @@ uniform sampler2D lightmap; //RGB/intensity for hurt entities and flashing creepers. uniform vec4 entityColor; + +//Fog mode +uniform int fogMode; +const int GL_LINEAR = 9729; +const int GL_EXP = 2048; + //0 = default, 1 = water, 2 = lava. uniform int isEyeInWater; @@ -19,19 +25,20 @@ varying vec2 coord0; varying vec2 coord1; void main() -{ - vec3 light = texture2D(lightmap,coord1).rgb; +{ //Sample texture times lighting. - vec4 col = color * vec4(light,1) * texture2D(texture,coord0); + vec4 col = color * texture2D(lightmap,coord1) * texture2D(texture,coord0); //Apply entity flashes. col.rgb = mix(col.rgb,entityColor.rgb,entityColor.a); - //Calculate fog intensity in or out of water. - float fog = (isEyeInWater>0) ? 1.-exp(-gl_FogFragCoord * gl_Fog.density): - clamp((gl_FogFragCoord-gl_Fog.start) * gl_Fog.scale, 0., 1.); - - //Apply the fog. - col.rgb = mix(col.rgb, gl_Fog.color.rgb, fog); + //Calculate and apply fog intensity. + if(fogMode == GL_LINEAR){ + float fog = clamp((gl_FogFragCoord-gl_Fog.start) * gl_Fog.scale, 0., 1.); + col.rgb = mix(col.rgb, gl_Fog.color.rgb, fog); + } else if(fogMode == GL_EXP || isEyeInWater >= 1){ + float fog = 1.-clamp(exp(-gl_FogFragCoord * gl_Fog.density), 0., 1.); + col.rgb = mix(col.rgb, gl_Fog.color.rgb, fog); + } //Output the result. /*DRAWBUFFERS:0*/