Skip to content

Commit 779d2c5

Browse files
lhofhanslparamat
authored andcommittedOct 24, 2016
Shaders: Harmonize Irrlicht and shader fog calculations
1 parent 74eb7f5 commit 779d2c5

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed
 

‎client/shaders/nodes_shader/opengl_fragment.glsl

+4-4
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,14 @@ void main(void)
197197
#if MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT
198198
float alpha = gl_Color.a;
199199
if (fogDistance != 0.0) {
200-
float d = max(0.0, min(length(eyeVec) / fogDistance * 1.5 - 0.6, 1.0));
201-
alpha = mix(alpha, 0.0, d);
200+
float d = clamp((fogDistance - length(eyeVec)) / (fogDistance * 0.6), 0.0, 1.0);
201+
alpha = mix(0.0, alpha, d);
202202
}
203203
col = vec4(col.rgb, alpha);
204204
#else
205205
if (fogDistance != 0.0) {
206-
float d = max(0.0, min(length(eyeVec) / fogDistance * 1.5 - 0.6, 1.0));
207-
col = mix(col, skyBgColor, d);
206+
float d = clamp((fogDistance - length(eyeVec)) / (fogDistance * 0.6), 0.0, 1.0);
207+
col = mix(skyBgColor, col, d);
208208
}
209209
col = vec4(col.rgb, base.a);
210210
#endif

‎client/shaders/water_surface_shader/opengl_fragment.glsl

+4-4
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,14 @@ vec4 base = texture2D(baseTexture, uv).rgba;
153153
#if MATERIAL_TYPE == TILE_MATERIAL_LIQUID_TRANSPARENT || MATERIAL_TYPE == TILE_MATERIAL_LIQUID_OPAQUE
154154
float alpha = gl_Color.a;
155155
if (fogDistance != 0.0) {
156-
float d = max(0.0, min(length(eyeVec) / fogDistance * 1.5 - 0.6, 1.0));
157-
alpha = mix(alpha, 0.0, d);
156+
float d = clamp((fogDistance - length(eyeVec)) / (fogDistance * 0.6), 0.0, 1.0);
157+
alpha = mix(0.0, alpha, d);
158158
}
159159
col = vec4(col.rgb, alpha);
160160
#else
161161
if (fogDistance != 0.0) {
162-
float d = max(0.0, min(length(eyeVec) / fogDistance * 1.5 - 0.6, 1.0));
163-
col = mix(col, skyBgColor, d);
162+
float d = clamp((fogDistance - length(eyeVec)) / (fogDistance * 0.6), 0.0, 1.0);
163+
col = mix(skyBgColor, col, d);
164164
}
165165
col = vec4(col.rgb, base.a);
166166
#endif

‎client/shaders/wielded_shader/opengl_fragment.glsl

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ void main(void)
107107
vec4 col = vec4(color.rgb, base.a);
108108
col *= gl_Color;
109109
if (fogDistance != 0.0) {
110-
float d = max(0.0, min(length(eyeVec) / fogDistance * 1.5 - 0.6, 1.0));
111-
col = mix(col, skyBgColor, d);
110+
float d = clamp((fogDistance - length(eyeVec)) / (fogDistance * 0.6), 0.0, 1.0);
111+
col = mix(skyBgColor, col, d);
112112
}
113113
gl_FragColor = vec4(col.rgb, base.a);
114114
}

0 commit comments

Comments
 (0)
Please sign in to comment.