diff --git a/data/levels/Level1.xml b/data/levels/Level1.xml index 307d580..ebde9c3 100644 --- a/data/levels/Level1.xml +++ b/data/levels/Level1.xml @@ -13056,12 +13056,26 @@ 1.0 - + 0.10 0.14 0.14 1.0 - + + + + 0.60 + 0.14 + 0.14 + 1.0 + + + + 0.05 + 0.07 + 0.34 + 1.0 + -1.0 diff --git a/data/shader/phong.fsh b/data/shader/phong.fsh index a44f9d7..8b62892 100644 --- a/data/shader/phong.fsh +++ b/data/shader/phong.fsh @@ -39,7 +39,9 @@ uniform vec3 lightColors[32]; uniform float lightIntensities[32]; uniform bool isFlame[32]; uniform float farPlane; -uniform vec4 fogColor; +uniform vec4 fogColorDay; +uniform vec4 fogColorRise; +uniform vec4 fogColorNight; uniform vec3 cameraCenter; uniform bool movingTexture; uniform vec2 movement; @@ -68,6 +70,38 @@ float flickerFunction(int index) { return 0.7*pow(sin(20.0*time + lightSources[index].x*lightSources[index].z), 2) + 0.3; } +vec4 fogColor(float dot) { + float riseFactor = 0.0; + float dayFactor = 0.0; + + if(dot<-0.52) { + riseFactor = 0.0; + } + else if (dot>0.52) { + riseFactor = 0.0; + } + else { + riseFactor = cos(3*dot); + } + + if(dot<0.0) { + dayFactor = 0.0; + } + else if(dot>0.51) { + dayFactor = 1.0; + } + else { + dayFactor = sin(3*dot); + } + if (dot <0.0) { + return mix(fogColorNight, fogColorRise, riseFactor); + } + else { + return mix(fogColorRise, fogColorDay, dayFactor); + } + +} + float sampleDirectionalShadow(sampler2DShadow shadowMap, vec4 shadowCoord, float maxBias ) { float visibility = 1.0; const float stretching = 650.0; @@ -112,9 +146,11 @@ void main() // direction lighting + float sunAngle = -1.0; if(length(directionalLightVector)>0.0f) { vec3 directionalVector = normalize(directionalLightVector); - if (dot(vec3(0.0, 1.0, 0.0), directionalVector) > 0.0) { + sunAngle = dot(vec3(0.0, 1.0, 0.0), directionalVector); + if ( sunAngle > -0.5) { float directionalVisibility = 1.0f; if (distanceToBorder(shadowCoord1.xy) <= 0.5 && distanceToBorder(shadowCoord1.xy) > 0.2) { if (distanceToBorder(shadowCoord0.xy) <= 0.5 && distanceToBorder(shadowCoord0.xy) > 0.2) { @@ -215,5 +251,5 @@ void main() textureColor = texture(uTexture, vTexCoord).rgba; } oColor = vec4(finalColor, 1.0f)*textureColor; - oColor = mix(oColor, fogColor, fogFactor); + oColor = mix(oColor, fogColor(sunAngle), fogFactor); } diff --git a/data/shader/skydome.fsh b/data/shader/skydome.fsh index 3ea54ca..ce5174e 100644 --- a/data/shader/skydome.fsh +++ b/data/shader/skydome.fsh @@ -9,13 +9,61 @@ out vec4 oColor; uniform sampler2D uTexture; uniform sampler2D nightTexture; uniform float farPlane; -uniform vec4 fogColor; +uniform vec4 fogColorDay; +uniform vec4 fogColorRise; +uniform vec4 fogColorNight; uniform vec3 cameraCenter; uniform vec3 sunColor; uniform vec3 directionalVector; const float sunSize = 20.0; +vec4 fogColor(float dot) { + float riseFactor = 0.0; + float dayFactor = 0.0; + + if(dot<-0.52) { + riseFactor = 0.0; + } + else if (dot>0.52) { + riseFactor = 0.0; + } + else { + riseFactor = cos(3*dot); + } + + if(dot<0.0) { + dayFactor = 0.0; + } + else if(dot>0.77) { + dayFactor = 1.0; + } + else { + dayFactor = sin(2*dot); + } + if (dot <0.0) { + return mix(fogColorNight, fogColorRise, riseFactor); + } + else { + return mix(fogColorRise, fogColorDay, dayFactor); + } + +} + +vec3 sunColorFunc(float dot) { + float riseFactor = 0.0; + if(dot<-0.79) { + riseFactor = 0.0; + } + else if (dot>0.876) { + riseFactor = 0.0; + } + else { + riseFactor = cos(2*dot); + } + return mix(sunColor, vec3(fogColorRise), riseFactor); +} + 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)); @@ -32,10 +80,10 @@ void main() { fogFactor *= clamp((1.0-((fragPosition.y-40.0)/30.0)), 0.0, 1.0); 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); - oColor = mix(color, fogColor, fogFactor); + vec4 color = mix(textureColor, vec4(sunColorFunc(sunAngle), sunIntensity), sunIntensity); + oColor = mix(color, fogColor(-sunAngle), fogFactor); } else { - oColor = mix(textureColor, fogColor, fogFactor); + oColor = mix(textureColor, fogColor(-sunAngle), fogFactor); } } diff --git a/graphics.cc b/graphics.cc index dab7afa..a01fc1f 100644 --- a/graphics.cc +++ b/graphics.cc @@ -265,7 +265,7 @@ void Graphics::render(double time) for (unsigned int i = 0; ibind(); glClear(GL_DEPTH_BUFFER_BIT); - if (sunAngle > 0.0f) { + if (sunAngle > -0.5f) { float projection_size = 0.0f; switch(i) { case 0: @@ -302,7 +302,9 @@ void Graphics::render(double time) // set fog Parameters skydomeShader->setUniform("farPlane", farPlane); skydomeShader->setUniform("skydomeSize", level->getSkydomeSize()); - skydomeShader->setUniform("fogColor", level->getFogColour()); + skydomeShader->setUniform("fogColorDay", level->getFogColourDay()); + skydomeShader->setUniform("fogColorRise", level->getFogColourRise()); + skydomeShader->setUniform("fogColorNight", level->getFogColourNight()); skydomeShader->setUniform("cameraCenter", level->getCameraCenter()->getPosition()); skydomeShader->setUniform("directionalVector", level->getDirectionalLight()->getPosition()); skydomeShader->setUniform("sunColor", level->getDirectionalLight()->getColour()); @@ -332,7 +334,9 @@ void Graphics::render(double time) lightingShader->setUniform("farPlane", farPlane); // set fog Parameters - lightingShader->setUniform("fogColor", level->getFogColour()); + lightingShader->setUniform("fogColorDay", level->getFogColourDay()); + lightingShader->setUniform("fogColorRise", level->getFogColourRise()); + lightingShader->setUniform("fogColorNight", level->getFogColourNight()); lightingShader->setUniform("cameraCenter", level->getCameraCenter()->getPosition()); // set Material Parameters diff --git a/level.cc b/level.cc index 76332f7..574d5cd 100644 --- a/level.cc +++ b/level.cc @@ -151,8 +151,16 @@ Light* Level::getDirectionalLight() { return &directionalLight; } -glm::vec4 Level::getFogColour() { - return fogColour; +glm::vec4 Level::getFogColourDay() { + return fogColourDay; +} + +glm::vec4 Level::getFogColourRise() { + return fogColourRise; +} + +glm::vec4 Level::getFogColourNight() { + return fogColourNight; } glm::vec3 Level::getCameraPosition() { @@ -227,8 +235,16 @@ void Level::setAmbientLight(glm::vec3 colour) { this->ambientLight = colour; } -void Level::setFogColour(glm::vec4 colour) { - this->fogColour = colour; +void Level::setFogColourDay(glm::vec4 colour) { + this->fogColourDay = colour; +} + +void Level::setFogColourRise(glm::vec4 colour) { + this->fogColourRise = colour; +} + +void Level::setFogColourNight(glm::vec4 colour) { + this->fogColourNight = colour; } void Level::setDirectionalLight(Light light) { diff --git a/level.hh b/level.hh index f9fd910..7d55e9d 100644 --- a/level.hh +++ b/level.hh @@ -34,7 +34,9 @@ class Level { Object* getCameraCenter(); Camera* getCamera(); glm::vec3 getCameraPosition(); - glm::vec4 getFogColour(); + glm::vec4 getFogColourDay(); + glm::vec4 getFogColourRise(); + glm::vec4 getFogColourNight(); void setSkydomeSize(float size); float getSkydomeSize(); Skydome* getSkydome(); @@ -47,7 +49,9 @@ class Level { void addObject(Object* object); void addPhysicsObject(Object* object); void setAmbientLight(glm::vec3 colour); - void setFogColour(glm::vec4 colour); + void setFogColourDay(glm::vec4 colour); + void setFogColourRise(glm::vec4 colour); + void setFogColourNight(glm::vec4 colour); void setDirectionalLight(Light light); void setSunDirection(float x, float y, float z); Physics* getPhysics(); @@ -73,7 +77,9 @@ class Level { std::vector lights; std::vector triggers; glm::vec3 ambientLight; - glm::vec4 fogColour; + glm::vec4 fogColourDay; + glm::vec4 fogColourRise; + glm::vec4 fogColourNight; Light directionalLight; Object* cameraCenter; int playerIndex; diff --git a/loader.cc b/loader.cc index 273fe06..b9b588c 100644 --- a/loader.cc +++ b/loader.cc @@ -158,13 +158,27 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa bColour = queryFloat(ambientElement, "bColour"); level->setAmbientLight(glm::vec3(rColour,gColour,bColour)); - XMLElement* fogElement = doc->FirstChildElement("fogColour"); + XMLElement* fogElement = doc->FirstChildElement("fogColourDay"); rColour = queryFloat(fogElement, "rColour"); gColour = queryFloat(fogElement, "gColour"); bColour = queryFloat(fogElement, "bColour"); alpha = queryFloat(fogElement, "alpha"); - level->setFogColour(glm::vec4(rColour,gColour,bColour, alpha)); + level->setFogColourDay(glm::vec4(rColour,gColour,bColour, alpha)); + fogElement = doc->FirstChildElement("fogColourRise"); + rColour = queryFloat(fogElement, "rColour"); + gColour = queryFloat(fogElement, "gColour"); + bColour = queryFloat(fogElement, "bColour"); + alpha = queryFloat(fogElement, "alpha"); + level->setFogColourRise(glm::vec4(rColour,gColour,bColour, alpha)); + + fogElement = doc->FirstChildElement("fogColourNight"); + rColour = queryFloat(fogElement, "rColour"); + gColour = queryFloat(fogElement, "gColour"); + bColour = queryFloat(fogElement, "bColour"); + alpha = queryFloat(fogElement, "alpha"); + level->setFogColourNight(glm::vec4(rColour,gColour,bColour, alpha)); + XMLElement* directionalElement = doc->FirstChildElement("directionalLight"); xOffset = queryFloat(directionalElement, "xOffset"); yOffset = queryFloat(directionalElement, "yOffset");