Gave sun rise more different colors.

This commit is contained in:
Faerbit 2015-03-09 00:39:59 +01:00
parent eda952df70
commit 6e8d3c36df
7 changed files with 159 additions and 21 deletions

View File

@ -13056,12 +13056,26 @@
<bColour>1.0</bColour>
</ambientLight>
<fogColour>
<fogColourDay>
<rColour>0.10</rColour>
<gColour>0.14</gColour>
<bColour>0.14</bColour>
<alpha>1.0</alpha>
</fogColour>
</fogColourDay>
<fogColourRise>
<rColour>0.60</rColour>
<gColour>0.14</gColour>
<bColour>0.14</bColour>
<alpha>1.0</alpha>
</fogColourRise>
<fogColourNight>
<rColour>0.05</rColour>
<gColour>0.07</gColour>
<bColour>0.34</bColour>
<alpha>1.0</alpha>
</fogColourNight>
<directionalLight>
<xOffset>-1.0</xOffset>

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -265,7 +265,7 @@ void Graphics::render(double time)
for (unsigned int i = 0; i<framebuffer_directional.size(); i++) {
framebuffer_directional.at(i)->bind();
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

View File

@ -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) {

View File

@ -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<Light> lights;
std::vector<Trigger> triggers;
glm::vec3 ambientLight;
glm::vec4 fogColour;
glm::vec4 fogColourDay;
glm::vec4 fogColourRise;
glm::vec4 fogColourNight;
Light directionalLight;
Object* cameraCenter;
int playerIndex;

View File

@ -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");