Saxum/data/shader/skydome.fsh

31 lines
952 B
Plaintext
Raw 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 float farPlane;
uniform vec4 fogColor;
uniform vec3 cameraCenter;
2015-03-04 16:09:46 +00:00
uniform vec3 sunColor;
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() {
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(vec4(texture(uTexture, vTexCoord)), vec4(sunColor, sunIntensity), sunIntensity);
oColor = mix(color, fogColor, fogFactor);
2015-03-04 16:09:46 +00:00
}
else {
oColor = mix(texture(uTexture, vTexCoord), fogColor, fogFactor);
}
2015-03-04 15:08:03 +00:00
}