diff --git a/data/levels/Level1.xml b/data/levels/Level1.xml
index 601fa7a..8dde83d 100644
--- a/data/levels/Level1.xml
+++ b/data/levels/Level1.xml
@@ -13259,7 +13259,7 @@
1.0
1.0
0.9
- 0.6
+ 0.7
diff --git a/data/shader/phong.fsh b/data/shader/phong.fsh
index a705865..6ec710a 100644
--- a/data/shader/phong.fsh
+++ b/data/shader/phong.fsh
@@ -33,7 +33,7 @@ uniform int lightCount;
uniform int maxShadowRenderCount;
uniform vec3 directionalLightVector;
uniform vec3 directionalColor;
-uniform float directionalIntensity;
+uniform float targetDirectionalIntensity;
uniform vec3 lightSources[32];
uniform vec3 lightColors[32];
uniform float lightIntensities[32];
@@ -121,21 +121,25 @@ vec3 sunColor(float dot){
return mix(directionalColor, vec3(fogColorRise), riseFactor);
}
-float sampleDirectionalShadow(sampler2DShadow shadowMap, vec4 shadowCoord, float maxBias ) {
+float sunIntensity(float dot) {
+ return targetDirectionalIntensity * sin(2*dot);
+}
+
+float sampleDirectionalShadow(sampler2DShadow shadowMap, vec4 shadowCoord, float maxBias, float intensity) {
float visibility = 1.0;
const float stretching = 650.0;
float bias = 0.001*tan(acos(clamp(dot(vNormal, -directionalLightVector), 0.0, 1.0)));
bias = clamp(bias, 0.0, maxBias);
for (int i=0; i<4; i++) {
- visibility -= directionalIntensity/16*(1.0-texture(shadowMap, vec3(shadowCoord.xy + poissonDisk[i]/stretching, shadowCoord.z - bias)));
+ visibility -= intensity/16*(1.0-texture(shadowMap, vec3(shadowCoord.xy + poissonDisk[i]/stretching, shadowCoord.z - bias)));
}
- if (visibility == 1.0-(directionalIntensity/16)*4)
+ if (visibility == 1.0-(intensity/16)*4)
{
- visibility = 1.0-directionalIntensity;
+ visibility = 1.0-intensity;
}
else if (visibility != 1.0) {
for (int i=0; i<12; i++) {
- visibility -= directionalIntensity/16*(1.0-texture(shadowMap, vec3(shadowCoord.xy + poissonDisk[i]/stretching, shadowCoord.z - bias)));
+ visibility -= intensity/16*(1.0-texture(shadowMap, vec3(shadowCoord.xy + poissonDisk[i]/stretching, shadowCoord.z - bias)));
}
}
return visibility;
@@ -170,28 +174,29 @@ void main()
if(length(directionalLightVector)>0.0f) {
vec3 directionalVector = normalize(directionalLightVector);
sunAngle = dot(vec3(0.0, 1.0, 0.0), directionalVector);
- if ( sunAngle > -0.6) {
+ if ( sunAngle > 0.0) {
float directionalVisibility = 1.0f;
+ float directionalIntensity = sunIntensity(sunAngle);
if (distanceToBorder(shadowCoord1.xy) <= 0.5 && distanceToBorder(shadowCoord1.xy) > 0.2) {
if (distanceToBorder(shadowCoord0.xy) <= 0.5 && distanceToBorder(shadowCoord0.xy) > 0.2) {
- directionalVisibility = sampleDirectionalShadow(shadowMap_directional0, shadowCoord0, 0.001);
+ directionalVisibility = sampleDirectionalShadow(shadowMap_directional0, shadowCoord0, 0.001, directionalIntensity);
}
else if (distanceToBorder(shadowCoord0.xy) <= 0.5 && distanceToBorder(shadowCoord0.xy) > 0.0) {
- float directionalVisibility0 = sampleDirectionalShadow(shadowMap_directional0, shadowCoord0, 0.001);
- float directionalVisibility1 = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1, 0.002);
+ float directionalVisibility0 = sampleDirectionalShadow(shadowMap_directional0, shadowCoord0, 0.001, directionalIntensity);
+ float directionalVisibility1 = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1, 0.002, directionalIntensity);
directionalVisibility = mix(directionalVisibility0, directionalVisibility1, distanceToBorder(shadowCoord0.xy) * 5);
}
else {
- directionalVisibility = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1, 0.002);
+ directionalVisibility = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1, 0.002, directionalIntensity);
}
}
else if (distanceToBorder(shadowCoord1.xy) <= 0.5 && distanceToBorder(shadowCoord1.xy) > 0.0) {
- float directionalVisibility1 = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1, 0.01);
- float directionalVisibility2 = sampleDirectionalShadow(shadowMap_directional2, shadowCoord2, 0.01);
+ float directionalVisibility1 = sampleDirectionalShadow(shadowMap_directional1, shadowCoord1, 0.002, directionalIntensity);
+ float directionalVisibility2 = sampleDirectionalShadow(shadowMap_directional2, shadowCoord2, 0.01, directionalIntensity);
directionalVisibility = mix(directionalVisibility1, directionalVisibility2, distanceToBorder(shadowCoord1.xy) * 5);
}
else {
- directionalVisibility = sampleDirectionalShadow(shadowMap_directional2, shadowCoord2, 0.01);
+ directionalVisibility = sampleDirectionalShadow(shadowMap_directional2, shadowCoord2, 0.01, directionalIntensity);
}
diffuseColor += clamp(dot(normalize(vNormal), directionalVector)
*diffuseFactor*directionalIntensity*sunColor(sunAngle), 0.0, 1.0)*directionalVisibility;
diff --git a/game/graphics.cc b/game/graphics.cc
index c94b7ea..6fb923e 100644
--- a/game/graphics.cc
+++ b/game/graphics.cc
@@ -197,6 +197,14 @@ void Graphics::init(Level* level) {
lightingShader->setUniform("fogColorRise", level->getFogColourRise());
lightingShader->setUniform("fogColorNight", level->getFogColourNight());
lightingShader->setUniform("ambientColor", level->getAmbientLight());
+ if(level->getDirectionalLight()) {
+ lightingShader->setUniform("directionalLightVector",
+ level->getDirectionalLight()->getPosition());
+ lightingShader->setUniform("directionalColor",
+ level->getDirectionalLight()->getColour());
+ lightingShader->setUniform("targetDirectionalIntensity",
+ level->getDirectionalLight()->getIntensity());
+ }
level->sortObjects(Material::getAllTextures()->size());
#ifdef SAXUM_DEBUG
@@ -379,7 +387,7 @@ void Graphics::render(double time)
glm::mat4 depthViewProjectionMatrix_face = depthProjectionMatrix_pointlights * viewMatrix;
std::vector viewMatrixVector = std::vector();
viewMatrixVector.push_back(viewMatrix);
- level->render(depthCubeShader, false, &depthViewProjectionMatrix_face, &viewMatrixVector);
+ level->render(depthCubeShader, false, 1, &depthViewProjectionMatrix_face, &viewMatrixVector);
if (!framebuffer_cube->isFrameBufferObjectComplete()) {
printf("Framebuffer incomplete, unknown error occured during shadow generation!\n");
}
@@ -397,7 +405,7 @@ void Graphics::render(double time)
for (unsigned int i = 0; ibind();
glClear(GL_DEPTH_BUFFER_BIT);
- if (sunAngle > -0.6f) {
+ if (sunAngle > 0.0f) {
float projection_size = 0.0f;
switch(i) {
case 0:
@@ -412,7 +420,7 @@ void Graphics::render(double time)
}
depthViewProjectionMatrices.at(i) = glm::ortho(-projection_size, projection_size, -projection_size, projection_size, -farPlane/1.5f, farPlane/1.5f) *
glm::lookAt(sunVector, level->getCameraCenter()->getPosition(), glm::vec3(0,1,0));
- level->render(depthShader, false, &depthViewProjectionMatrices.at(i));
+ level->render(depthShader, false, -1, &depthViewProjectionMatrices.at(i));
if (!framebuffer_directional.at(i)->isFrameBufferObjectComplete()) {
printf("Framebuffer incomplete, unknown error occured during shadow generation!\n");
}
@@ -481,6 +489,10 @@ void Graphics::render(double time)
// set fog Parameters
lightingShader->setUniform("cameraCenter", level->getCameraCenter()->getPosition());
+ if(level->getDirectionalLight()) {
+ lightingShader->setUniform("directionalLightVector",
+ level->getDirectionalLight()->getPosition());
+ }
// set Material Parameters
lightingShader->setUniform("camera", level->getPhysics()->getCameraPosition());
@@ -655,14 +667,6 @@ void Graphics::updateLights() {
sizeof(lightIntensities), (GLfloat*) lightIntensities);
}
// set directional Light
- if(level->getDirectionalLight()) {
- lightingShader->setUniform("directionalLightVector",
- level->getDirectionalLight()->getPosition());
- lightingShader->setUniform("directionalColor",
- level->getDirectionalLight()->getColour());
- lightingShader->setUniform("directionalIntensity",
- level->getDirectionalLight()->getIntensity());
- }
bool isFlame[closestLights.size()];
closestFlames = std::vector();
for (unsigned int i = 0; icamera = Camera(glm::vec2(-0.8f, 0.0f), 3.0f);
}
-void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
- glm::mat4* viewProjectionMatrix, std::vector* shadowVPs) {
+void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
+ int chunkRenderDistance, glm::mat4* viewProjectionMatrix,
+ std::vector* shadowVPs) {
int renderDistance = 0;
- if ((int)farPlane % chunkSize == 0) {
- renderDistance = (((int)skydomeSize)+chunkSize/2)/chunkSize;
+ if (chunkRenderDistance < 0) {
+ if ((int)farPlane % chunkSize == 0) {
+ renderDistance = (((int)skydomeSize)+chunkSize/2)/chunkSize;
+ }
+ else {
+ renderDistance = ((((int)skydomeSize)+chunkSize/2)/chunkSize) + 1;
+ }
}
else {
- renderDistance = ((((int)skydomeSize)+chunkSize/2)/chunkSize) + 1;
- }
- if(!lightingPass) {
- renderDistance = 1;
+ renderDistance = chunkRenderDistance;
}
int xPosition = ((int)cameraCenter->getPosition().x + (terrain.getHeightmapWidth()/2))/chunkSize;
int zPosition = ((int)cameraCenter->getPosition().z + (terrain.getHeightmapHeight()/2))/chunkSize;
diff --git a/game/level.hh b/game/level.hh
index 9642697..84c9c06 100644
--- a/game/level.hh
+++ b/game/level.hh
@@ -33,7 +33,8 @@ class Level {
void update(float runTimeSinceLastUpdate, float runTime, glm::vec2 mouseDelta,
KeyboardState* keyboardState);
void render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
- glm::mat4* viewProjectionMatrix, std::vector* shadowVPs=0);
+ int chunkRenderDistance, glm::mat4* viewProjectionMatrix,
+ std::vector* shadowVPs=0);
glm::vec3 getAmbientLight();
Light* getDirectionalLight();
std::vector* getLights();