Added sun to skydome.

This commit is contained in:
Fabian Klemp 2015-03-04 17:09:46 +01:00
parent d273d131e2
commit b7f95ebb40
3 changed files with 17 additions and 1 deletions

View File

@ -2,6 +2,7 @@
in vec2 vTexCoord;
in vec4 fragPosition;
in vec4 sunPosition;
out vec4 oColor;
@ -9,10 +10,17 @@ uniform sampler2D uTexture;
uniform float farPlane;
uniform vec4 fogColor;
uniform vec3 cameraCenter;
uniform vec3 sunColor;
void main() {
float distanceToSun = length(sunPosition - fragPosition);
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);
if (distanceToSun < 20.0) {
oColor = mix(vec4(sunColor, 1.0), fogColor, fogFactor);
}
else {
oColor = mix(texture(uTexture, vTexCoord), fogColor, fogFactor);
}
}

View File

@ -6,12 +6,17 @@ in vec2 aTexCoord;
uniform mat4 modelMatrix;
uniform mat4 modelViewProjectionMatrix;
uniform float skydomeSize;
uniform vec3 directionalVector;
uniform vec3 cameraCenter;
out vec2 vTexCoord;
out vec4 fragPosition;
out vec4 sunPosition;
void main() {
fragPosition = modelMatrix * vec4(aPosition, 1.0);
vTexCoord = aTexCoord;
sunPosition = (normalize(vec4(directionalVector, 0.0)) * skydomeSize) + vec4(cameraCenter, 1.0);
gl_Position = modelViewProjectionMatrix * vec4(aPosition, 1.0);
}

View File

@ -244,8 +244,11 @@ void Graphics::render(double time)
skydomeShader->use();
// set fog Parameters
skydomeShader->setUniform("farPlane", farPlane);
skydomeShader->setUniform("skydomeSize", level->getSkydomeSize());
skydomeShader->setUniform("fogColor", level->getFogColour());
skydomeShader->setUniform("cameraCenter", level->getCameraCenter()->getPosition());
skydomeShader->setUniform("directionalVector", level->getDirectionalLight()->getPosition());
skydomeShader->setUniform("sunColor", level->getDirectionalLight()->getColour());
level->getSkydome()->render(skydomeShader, false, true, &lightingViewProjectionMatrix);
lightingShader->use();