Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fog when submerged in lava or powdered snow #9

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions shaders/gbuffers_basic.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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*/
Expand Down
19 changes: 13 additions & 6 deletions shaders/gbuffers_clouds.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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*/
Expand Down
19 changes: 13 additions & 6 deletions shaders/gbuffers_damagedblock.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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*/
Expand Down
25 changes: 16 additions & 9 deletions shaders/gbuffers_textured.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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*/
Expand Down