From b7f95ebb4030ced1190f4f5f05fd4ba5c3b67adf Mon Sep 17 00:00:00 2001 From: Fabian Klemp Date: Wed, 4 Mar 2015 17:09:46 +0100 Subject: [PATCH] Added sun to skydome. --- data/shader/skydome.fsh | 10 +++++++++- data/shader/skydome.vsh | 5 +++++ graphics.cc | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/data/shader/skydome.fsh b/data/shader/skydome.fsh index aa8b140..227a0e8 100644 --- a/data/shader/skydome.fsh +++ b/data/shader/skydome.fsh @@ -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); - oColor = mix(texture(uTexture, vTexCoord), fogColor, fogFactor); + if (distanceToSun < 20.0) { + oColor = mix(vec4(sunColor, 1.0), fogColor, fogFactor); + } + else { + oColor = mix(texture(uTexture, vTexCoord), fogColor, fogFactor); + } } diff --git a/data/shader/skydome.vsh b/data/shader/skydome.vsh index 594040e..2dc7b65 100644 --- a/data/shader/skydome.vsh +++ b/data/shader/skydome.vsh @@ -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); } diff --git a/graphics.cc b/graphics.cc index bfa7707..2e70ce5 100644 --- a/graphics.cc +++ b/graphics.cc @@ -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();