Finally fog is working
This commit is contained in:
1 parent
7287f4b619
commit
1af829bf49
15 files changed
+476
-60
No files matched your search
@@ -0,0 +1,90 @@
|
||||
varying vec2 TexCoord;
|
||||
varying vec3 vViewDirTangent;
|
||||
|
||||
uniform sampler2D Texture;
|
||||
uniform float uHeightScale;
|
||||
uniform float uDistanceToPlanetSurface;
|
||||
uniform float uCurrentZFar;
|
||||
//varying float realDist;
|
||||
varying vec3 worldPosition;
|
||||
|
||||
uniform vec3 uViewPos;
|
||||
const vec4 FOG_COLOR = vec4(0.0, 0.5, 1.0, 1.0); // Синий туман
|
||||
|
||||
void main() {
|
||||
vec3 viewDir = normalize(vViewDirTangent);
|
||||
|
||||
// Получаем высоту из альфа-канала запеченной текстуры
|
||||
float height = texture2D(Texture, TexCoord).a;
|
||||
|
||||
// Смещение. Знак минус используется, если мы хотим "вдавить" камни
|
||||
// Деление на viewDir.z помогает избежать сильных искажений под углом
|
||||
//vec2 p = viewDir.xy * (height * uHeightScale) / viewDir.z;
|
||||
vec2 p = vec2(viewDir.x, -viewDir.y) * (height * uHeightScale);
|
||||
//vec2 p = vec2(0,0);
|
||||
vec2 finalTexCoord = TexCoord + p;
|
||||
|
||||
float realDist = distance(worldPosition, uViewPos);
|
||||
|
||||
vec4 finalColor = texture2D(Texture, finalTexCoord);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
if (realDist < 500)
|
||||
{
|
||||
gl_FragColor = vec4(0.5, 0.0, 0.0, 1.0);
|
||||
}
|
||||
else if (realDist < 1000)
|
||||
{
|
||||
gl_FragColor = vec4(1.0, 0.2, 0.0, 1.0);
|
||||
}
|
||||
else if (realDist < 1800)
|
||||
{
|
||||
gl_FragColor = vec4(1.0, 0.7, 0.0, 1.0);
|
||||
}
|
||||
else if (realDist < 2400)
|
||||
{
|
||||
gl_FragColor = vec4(1.0, 0.7, 0.5, 1.0);
|
||||
}
|
||||
else if (realDist < 2700)
|
||||
{
|
||||
gl_FragColor = vec4(1.0, 0.7, 1.0, 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
}*/
|
||||
}
|
||||
Reference in new issue
Block a user