Saxum/data/shader/skydome.fsh

43 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

2015-03-04 15:08:03 +00:00
#version 150
in vec2 vTexCoord;
in vec4 fragPosition;
2015-03-04 16:09:46 +00:00
in vec4 sunPosition;
2015-03-04 15:08:03 +00:00
out vec4 oColor;
uniform sampler2D uTexture;
uniform sampler2D nightTexture;
2015-03-04 15:08:03 +00:00
uniform float farPlane;
uniform vec4 fogColor;
uniform vec3 cameraCenter;
2015-03-04 16:09:46 +00:00
uniform vec3 sunColor;
uniform vec3 directionalVector;
2015-03-04 15:08:03 +00:00
2015-03-04 16:47:34 +00:00
const float sunSize = 40.0;
2015-03-04 15:08:03 +00:00
void main() {
vec4 textureColor = vec4(0.0, 0.0, 0.0, 1.0);
float sunAngle = -dot(normalize(directionalVector), vec3(0.0, 1.0, 0.0));
vec4 dayColor = texture(uTexture, vTexCoord);
if (sunAngle >= 0.0) {
textureColor = mix(dayColor, texture(nightTexture, vTexCoord), sunAngle);
textureColor = mix(vec4(0.0, 0.0, 0.0, 1.0), textureColor, 1.0 - sunAngle);
}
else {
textureColor = dayColor;
}
2015-03-04 16:09:46 +00:00
float distanceToSun = length(sunPosition - fragPosition);
2015-03-04 15:08:03 +00:00
float distanceCameraCenter = distance(cameraCenter, vec3(fragPosition));
float fogFactor = clamp((1.0 - ((farPlane - 35.0) -distanceCameraCenter)/30.0), 0.0, 1.0);
fogFactor *= clamp((1.0-((fragPosition.y-40.0)/30.0)), 0.0, 1.0);
2015-03-04 16:47:34 +00:00
if (distanceToSun < sunSize) {
float sunIntensity = clamp(0.3*exp(1/(distanceToSun/sunSize))-exp(1.0)*0.3, 0.0, 1.0);
vec4 color = mix(textureColor, vec4(sunColor, sunIntensity), sunIntensity);
2015-03-04 16:47:34 +00:00
oColor = mix(color, fogColor, fogFactor);
2015-03-04 16:09:46 +00:00
}
else {
oColor = mix(textureColor, fogColor, fogFactor);
2015-03-04 16:09:46 +00:00
}
2015-03-04 15:08:03 +00:00
}