1
0
2025-09-09 14:29:46 -05:00

65 lines
1.8 KiB
GLSL

#version 330
// Input vertex attributes (from vertex shader)
in vec3 fragPosition;
in vec2 fragTexCoord;
in vec4 fragColor;
in vec3 fragNormal;
in vec3 worldPos;
// Input uniform values
uniform sampler2D texture0;
uniform vec4 colDiffuse;
// Custom uniforms for sky
uniform vec3 horizonColor;
uniform vec3 zenithColor;
uniform vec3 sunDirection;
uniform vec3 sunColor;
uniform float sunIntensity;
// Output fragment color
out vec4 finalColor;
void main()
{
// Normalize the world position to get direction from center
vec3 direction = normalize(worldPos);
// Calculate gradient based on Y component (height)
float gradientFactor = smoothstep(-0.5, 1.0, direction.y);
// Interpolate between horizon and zenith colors
vec3 skyColor = mix(horizonColor, zenithColor, gradientFactor);
// Calculate sun contribution
vec3 sunDir = normalize(sunDirection);
float sunDot = dot(direction, sunDir);
// Sun rendering
vec3 color = skyColor;
// Only render sun if it's above horizon and has intensity
if (sunDir.y > 0.0 && sunIntensity > 0.1) {
// Sun disc with soft edges
float sunSize = 0.99; // Smaller value = larger sun
float sunEdge = 0.98;
if (sunDot > sunSize) {
// Bright sun core
color = mix(sunColor, vec3(1.0, 1.0, 0.95), 0.8);
} else if (sunDot > sunEdge) {
// Soft edge
float edge = smoothstep(sunEdge, sunSize, sunDot);
color = mix(skyColor, sunColor, edge);
}
// Sun glow
if (sunDot > 0.85) {
float glow = pow(max(0.0, (sunDot - 0.85) / 0.15), 2.0) * sunIntensity;
color = mix(color, sunColor, glow * 0.5);
}
}
finalColor = vec4(color, 1.0);
}