Added fading to the sun.

This commit is contained in:
Fabian Klemp 2015-03-04 17:47:34 +01:00
parent b7f95ebb40
commit fce73f1285

View File

@ -12,13 +12,17 @@ uniform vec4 fogColor;
uniform vec3 cameraCenter; uniform vec3 cameraCenter;
uniform vec3 sunColor; uniform vec3 sunColor;
const float sunSize = 40.0;
void main() { void main() {
float distanceToSun = length(sunPosition - fragPosition); float distanceToSun = length(sunPosition - fragPosition);
float distanceCameraCenter = distance(cameraCenter, vec3(fragPosition)); float distanceCameraCenter = distance(cameraCenter, vec3(fragPosition));
float fogFactor = clamp((1.0 - ((farPlane - 35.0) -distanceCameraCenter)/30.0), 0.0, 1.0); 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); fogFactor *= clamp((1.0-((fragPosition.y-40.0)/30.0)), 0.0, 1.0);
if (distanceToSun < 20.0) { if (distanceToSun < sunSize) {
oColor = mix(vec4(sunColor, 1.0), fogColor, fogFactor); 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);
} }
else { else {
oColor = mix(texture(uTexture, vTexCoord), fogColor, fogFactor); oColor = mix(texture(uTexture, vTexCoord), fogColor, fogFactor);