From 3abc3705c751c455d584fcd909d5552ade4cd73d Mon Sep 17 00:00:00 2001 From: Michael1297 <38764610+Michael1297@users.noreply.github.com> Date: Sat, 29 Apr 2023 20:40:55 +0300 Subject: [PATCH 1/2] fix fog --- shaders/gbuffers_basic.fsh | 19 +++++++++++++------ shaders/gbuffers_clouds.fsh | 19 +++++++++++++------ shaders/gbuffers_damagedblock.fsh | 19 +++++++++++++------ shaders/gbuffers_textured.fsh | 25 ++++++++++++++++--------- 4 files changed, 55 insertions(+), 27 deletions(-) diff --git a/shaders/gbuffers_basic.fsh b/shaders/gbuffers_basic.fsh index 9344816..f0cfea6 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.-exp(-gl_FogFragCoord * gl_Fog.density); + 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..1f2968c 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.-exp(-gl_FogFragCoord * gl_Fog.density); + 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..22c6477 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.-exp(-gl_FogFragCoord * gl_Fog.density); + 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..b0d4cc4 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.-exp(-gl_FogFragCoord * gl_Fog.density); + col.rgb = mix(col.rgb, gl_Fog.color.rgb, fog); + } //Output the result. /*DRAWBUFFERS:0*/ From 7d5c138dcc0c0c499e2fdabba3552433877cad02 Mon Sep 17 00:00:00 2001 From: Michael1297 <38764610+Michael1297@users.noreply.github.com> Date: Mon, 1 May 2023 18:00:19 +0300 Subject: [PATCH 2/2] upd fix --- shaders/gbuffers_basic.fsh | 4 ++-- shaders/gbuffers_clouds.fsh | 4 ++-- shaders/gbuffers_damagedblock.fsh | 4 ++-- shaders/gbuffers_textured.fsh | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/shaders/gbuffers_basic.fsh b/shaders/gbuffers_basic.fsh index f0cfea6..8e623b8 100644 --- a/shaders/gbuffers_basic.fsh +++ b/shaders/gbuffers_basic.fsh @@ -21,8 +21,8 @@ void main() 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.-exp(-gl_FogFragCoord * gl_Fog.density); + } 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); } diff --git a/shaders/gbuffers_clouds.fsh b/shaders/gbuffers_clouds.fsh index 1f2968c..c46f98d 100644 --- a/shaders/gbuffers_clouds.fsh +++ b/shaders/gbuffers_clouds.fsh @@ -27,8 +27,8 @@ void main() 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.-exp(-gl_FogFragCoord * gl_Fog.density); + } 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); } diff --git a/shaders/gbuffers_damagedblock.fsh b/shaders/gbuffers_damagedblock.fsh index 22c6477..8fcaf11 100644 --- a/shaders/gbuffers_damagedblock.fsh +++ b/shaders/gbuffers_damagedblock.fsh @@ -28,8 +28,8 @@ void main() 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.-exp(-gl_FogFragCoord * gl_Fog.density); + } 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); } diff --git a/shaders/gbuffers_textured.fsh b/shaders/gbuffers_textured.fsh index b0d4cc4..148270b 100644 --- a/shaders/gbuffers_textured.fsh +++ b/shaders/gbuffers_textured.fsh @@ -35,8 +35,8 @@ void main() 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.-exp(-gl_FogFragCoord * gl_Fog.density); + } 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); }