32 lines
823 B
GLSL
32 lines
823 B
GLSL
#version 430 core
|
|
|
|
out vec4 FragColor;
|
|
in vec2 fragUV;
|
|
in vec3 fragPos;
|
|
in float lighting;
|
|
|
|
uniform sampler2D uTexture;
|
|
uniform vec3 cameraPosition;
|
|
|
|
void main()
|
|
{
|
|
// Use squared distance
|
|
vec3 delta = cameraPosition - fragPos;
|
|
float distSq = dot(delta, delta);
|
|
|
|
// Precomputed fog parameters
|
|
const float fogEndSq = 16384.0; // 128^2
|
|
const float fogStartSq = 1024.0; // 32^2
|
|
const float fogRangeInv = 1.0 / (fogEndSq - fogStartSq);
|
|
|
|
float fogFactor = (fogEndSq - distSq) * fogRangeInv;
|
|
fogFactor = clamp(fogFactor, 0.0, 1.0);
|
|
|
|
// Texture and lighting
|
|
vec4 texColor = texture(uTexture, fragUV);
|
|
texColor.rgb *= lighting;
|
|
|
|
// Fog blend
|
|
const vec3 fogColor = vec3(0.8, 0.8, 0.8);
|
|
FragColor = vec4(mix(fogColor, texColor.rgb, fogFactor), texColor.a);
|
|
} |