60 lines
1.6 KiB
Plaintext
60 lines
1.6 KiB
Plaintext
// ---Фрагментный шейдер (Fragment Shader)
|
|
|
|
varying vec2 TexCoord;
|
|
varying float viewZ;
|
|
varying vec3 pos;
|
|
|
|
uniform sampler2D Texture;
|
|
uniform float uDistanceToPlanetSurface;
|
|
uniform float uCurrentZFar;
|
|
|
|
// Константы для тумана:
|
|
//const vec4 FOG_COLOR = vec4(0.0, 0.3, 0.3, 1.0); // Синий туман
|
|
const vec4 FOG_COLOR = vec4(0.0, 0.5, 1.0, 1.0); // Синий туман
|
|
|
|
varying vec3 worldPosition;
|
|
|
|
uniform vec3 uViewPos;
|
|
|
|
void main()
|
|
{
|
|
|
|
vec4 textureColor = texture2D(Texture, TexCoord);
|
|
vec3 finalColor = textureColor.rgb;
|
|
|
|
float realDist = distance(worldPosition, uViewPos);
|
|
|
|
float fogFactor;
|
|
if (uDistanceToPlanetSurface > 1000)
|
|
{
|
|
gl_FragColor = vec4(finalColor.rgb, 1.0);
|
|
}
|
|
else if (uDistanceToPlanetSurface > 100)
|
|
{
|
|
float t = clamp((uDistanceToPlanetSurface - 100) / 900.0, 0.0, 1.0); // 1 upstairs, 0 downstairs
|
|
|
|
fogFactor = clamp((realDist - 2400) / (300.0*(1 + 10*t)), 0.0, 1.0);
|
|
|
|
gl_FragColor = mix(vec4(finalColor.rgb, 1.0), FOG_COLOR, fogFactor*(1.0 - t));
|
|
}
|
|
else if (uDistanceToPlanetSurface > 40)
|
|
{
|
|
//From 100 to 40:
|
|
//(1000 < realDist < 1800)
|
|
|
|
float t = clamp((uDistanceToPlanetSurface - 40) / 60.0, 0.0, 1.0); // 1 upstairs, 0 downstairs
|
|
|
|
fogFactor = clamp((realDist - 2400) / 300.0, 0.0, 1.0); // old fog factor
|
|
|
|
float fogFactor2 = clamp((realDist - 1000) / 800.0, 0.0, 1.0);
|
|
|
|
gl_FragColor = mix(vec4(finalColor.rgb, 1.0), FOG_COLOR, max(fogFactor, fogFactor2*(1.0 - t)));
|
|
}
|
|
else
|
|
{
|
|
fogFactor = clamp((realDist - 1000) / (800.0), 0.0, 1.0);
|
|
|
|
gl_FragColor = mix(vec4(finalColor.rgb, 1.0), FOG_COLOR, fogFactor);
|
|
}
|
|
|
|
} |