mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 01:53:45 +01:00
Fix unexplained shader issue (glsl compiler bug??) (#4757)
This commit is contained in:
parent
8e61c1dfd9
commit
5f0dc8e78a
@ -19,6 +19,8 @@ bool normalTexturePresent = false;
|
|||||||
|
|
||||||
const float e = 2.718281828459;
|
const float e = 2.718281828459;
|
||||||
const float BS = 10.0;
|
const float BS = 10.0;
|
||||||
|
const float fogStart = 0.4;
|
||||||
|
const float fogShadingParameter = 1 / ( 1 - fogStart);
|
||||||
|
|
||||||
#ifdef ENABLE_TONE_MAPPING
|
#ifdef ENABLE_TONE_MAPPING
|
||||||
|
|
||||||
@ -199,8 +201,18 @@ void main(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fogDistance != 0.0) {
|
if (fogDistance != 0.0) {
|
||||||
float d = clamp((fogDistance - length(eyeVec)) / (fogDistance * 0.6), 0.0, 1.0);
|
// Due to a bug in some (older ?) graphics stacks (possibly in the glsl compiler ?),
|
||||||
col = mix(skyBgColor, col, d);
|
// the fog will only be rendered correctly if the last operation before the
|
||||||
|
// clamp() is an addition. Else, the clamp() seems to be ignored.
|
||||||
|
// E.g. the following won't work:
|
||||||
|
// float clarity = clamp(fogShadingParameter
|
||||||
|
// * (fogDistance - length(eyeVec)) / fogDistance), 0.0, 1.0);
|
||||||
|
// As additions usually come for free following a multiplication, the new formula
|
||||||
|
// should be more efficient as well.
|
||||||
|
// Note: clarity = (1 - fogginess)
|
||||||
|
float clarity = clamp(fogShadingParameter
|
||||||
|
- fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0);
|
||||||
|
col = mix(skyBgColor, col, clarity);
|
||||||
}
|
}
|
||||||
col = vec4(col.rgb, base.a);
|
col = vec4(col.rgb, base.a);
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@ bool texSeamless = false;
|
|||||||
|
|
||||||
const float e = 2.718281828459;
|
const float e = 2.718281828459;
|
||||||
const float BS = 10.0;
|
const float BS = 10.0;
|
||||||
|
const float fogStart = 0.4;
|
||||||
|
const float fogShadingParameter = 1 / ( 1 - fogStart);
|
||||||
|
|
||||||
#ifdef ENABLE_TONE_MAPPING
|
#ifdef ENABLE_TONE_MAPPING
|
||||||
|
|
||||||
@ -155,8 +157,18 @@ vec4 base = texture2D(baseTexture, uv).rgba;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fogDistance != 0.0) {
|
if (fogDistance != 0.0) {
|
||||||
float d = clamp((fogDistance - length(eyeVec)) / (fogDistance * 0.6), 0.0, 1.0);
|
// Due to a bug in some (older ?) graphics stacks (possibly in the glsl compiler ?),
|
||||||
col = mix(skyBgColor, col, d);
|
// the fog will only be rendered correctly if the last operation before the
|
||||||
|
// clamp() is an addition. Else, the clamp() seems to be ignored.
|
||||||
|
// E.g. the following won't work:
|
||||||
|
// float clarity = clamp(fogShadingParameter
|
||||||
|
// * (fogDistance - length(eyeVec)) / fogDistance), 0.0, 1.0);
|
||||||
|
// As additions usually come for free following a multiplication, the new formula
|
||||||
|
// should be more efficient as well.
|
||||||
|
// Note: clarity = (1 - fogginess)
|
||||||
|
float clarity = clamp(fogShadingParameter
|
||||||
|
- fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0);
|
||||||
|
col = mix(skyBgColor, col, clarity);
|
||||||
}
|
}
|
||||||
col = vec4(col.rgb, base.a);
|
col = vec4(col.rgb, base.a);
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@ bool texSeamless = false;
|
|||||||
|
|
||||||
const float e = 2.718281828459;
|
const float e = 2.718281828459;
|
||||||
const float BS = 10.0;
|
const float BS = 10.0;
|
||||||
|
const float fogStart = 0.4;
|
||||||
|
const float fogShadingParameter = 1 / ( 1 - fogStart);
|
||||||
|
|
||||||
void get_texture_flags()
|
void get_texture_flags()
|
||||||
{
|
{
|
||||||
@ -107,8 +109,18 @@ void main(void)
|
|||||||
vec4 col = vec4(color.rgb, base.a);
|
vec4 col = vec4(color.rgb, base.a);
|
||||||
col *= gl_Color;
|
col *= gl_Color;
|
||||||
if (fogDistance != 0.0) {
|
if (fogDistance != 0.0) {
|
||||||
float d = clamp((fogDistance - length(eyeVec)) / (fogDistance * 0.6), 0.0, 1.0);
|
// Due to a bug in some (older ?) graphics stacks (possibly in the glsl compiler ?),
|
||||||
col = mix(skyBgColor, col, d);
|
// the fog will only be rendered correctly if the last operation before the
|
||||||
|
// clamp() is an addition. Else, the clamp() seems to be ignored.
|
||||||
|
// E.g. the following won't work:
|
||||||
|
// float clarity = clamp(fogShadingParameter
|
||||||
|
// * (fogDistance - length(eyeVec)) / fogDistance), 0.0, 1.0);
|
||||||
|
// As additions usually come for free following a multiplication, the new formula
|
||||||
|
// should be more efficient as well.
|
||||||
|
// Note: clarity = (1 - fogginess)
|
||||||
|
float clarity = clamp(fogShadingParameter
|
||||||
|
- fogShadingParameter * length(eyeVec) / fogDistance, 0.0, 1.0);
|
||||||
|
col = mix(skyBgColor, col, clarity);
|
||||||
}
|
}
|
||||||
gl_FragColor = vec4(col.rgb, base.a);
|
gl_FragColor = vec4(col.rgb, base.a);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user