Fixed pointlight shadows not getting rendered correctly.

This commit is contained in:
Faerbit 2015-06-01 00:57:36 +02:00
parent 4a35c4feba
commit f389aa2f4a
3 changed files with 13 additions and 11 deletions

View File

@ -354,7 +354,7 @@ void Graphics::render(double time)
glm::mat4 depthViewProjectionMatrix_face = depthProjectionMatrix_pointlights * viewMatrix;
std::vector<glm::mat4> viewMatrixVector = std::vector<glm::mat4>();
viewMatrixVector.push_back(viewMatrix);
level->render(depthCubeShader, false, 1, &depthViewProjectionMatrix_face, &viewMatrixVector);
level->render(depthCubeShader, false, closestLights->at(i_pointlight)->getPosition(), 1, &depthViewProjectionMatrix_face, &viewMatrixVector);
if (!framebuffer_cube->isFrameBufferObjectComplete()) {
printf("Framebuffer incomplete, unknown error occured during shadow generation!\n");
}
@ -392,7 +392,7 @@ void Graphics::render(double time)
}
depthViewProjectionMatrices.at(i) = glm::ortho<float>(-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, -1, &depthViewProjectionMatrices.at(i));
level->render(depthShader, false, level->getCameraCenter()->getPosition(), -1, &depthViewProjectionMatrices.at(i));
if (!framebuffer_directional.at(i)->isFrameBufferObjectComplete()) {
printf("Framebuffer incomplete, unknown error occured during shadow generation!\n");
}

View File

@ -52,9 +52,9 @@ void Level::load() {
}
void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
int chunkRenderDistance, glm::mat4* viewProjectionMatrix,
glm::vec3 center, int chunkRenderDistance, glm::mat4* viewProjectionMatrix,
std::vector<glm::mat4>* shadowVPs) {
std::vector<Chunk*> nearChunks = getSurroundingChunks(chunkRenderDistance);
std::vector<Chunk*> nearChunks = getSurroundingChunks(center, chunkRenderDistance);
for(unsigned int i = 0; i<nearChunks.size(); i++) {
nearChunks.at(i)->render(shader, lightingPass, viewProjectionMatrix, shadowVPs);
}
@ -64,14 +64,14 @@ void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
}
void Level::enqueueObjects(Graphics* graphics) {
std::vector<Chunk*> nearChunks = getSurroundingChunks(-1);
std::vector<Chunk*> nearChunks = getSurroundingChunks(cameraCenter->getPosition(), -1);
for(unsigned int i = 0; i<nearChunks.size(); i++) {
graphics->enqueueObjects(nearChunks.at(i)->getSortedObjects());
}
graphics->enqueueObjects(&sortedCrossChunkObjects);
}
std::vector<Chunk*> Level::getSurroundingChunks(int chunkRenderDistance) {
std::vector<Chunk*> Level::getSurroundingChunks(glm::vec3 center, int chunkRenderDistance) {
int renderDistance = 0;
if (chunkRenderDistance < 0) {
if ((int)farPlane % chunkSize == 0) {
@ -84,8 +84,8 @@ std::vector<Chunk*> Level::getSurroundingChunks(int chunkRenderDistance) {
else {
renderDistance = chunkRenderDistance;
}
int xPosition = ((int)cameraCenter->getPosition().x + (terrain.getHeightmapWidth()/2))/chunkSize;
int zPosition = ((int)cameraCenter->getPosition().z + (terrain.getHeightmapHeight()/2))/chunkSize;
int xPosition = ((int)center.x + (terrain.getHeightmapWidth()/2))/chunkSize;
int zPosition = ((int)center.z + (terrain.getHeightmapHeight()/2))/chunkSize;
int xStart = xPosition - renderDistance;
unsigned int xEnd = xPosition + renderDistance;
int zStart = zPosition - renderDistance;

View File

@ -33,7 +33,7 @@ class Level {
void update(float runTimeSinceLastUpdate, float runTime, glm::vec2 mouseDelta,
KeyboardState* keyboardState);
void render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
int chunkRenderDistance, glm::mat4* viewProjectionMatrix,
glm::vec3 center, int chunkRenderDistance, glm::mat4* viewProjectionMatrix,
std::vector<glm::mat4>* shadowVPs=0);
glm::vec3 getAmbientLight();
Light* getDirectionalLight();
@ -67,7 +67,9 @@ class Level {
void setCameraCenter(Object* object);
void addLight(Light light);
void preloadLightPosition(float xPos, float yPos, float zPos);
void addLightByParameters(float redColour, float greenColour, float blueColour, float intensity, float flameYOffset, float flameHeight, float flameWidth);
void addLightByParameters(float redColour, float greenColour,
float blueColour, float intensity, float flameYOffset,
float flameHeight, float flameWidth);
void deleteFourLights();
void addTrigger(Trigger trigger);
lua_State* getLuaState();
@ -86,7 +88,7 @@ class Level {
void sortObjects(int textureCount);
std::vector<shared_ptr<Light>>* getClosestLights();
private:
std::vector<Chunk*> getSurroundingChunks(int chunkRenderDistance);
std::vector<Chunk*> getSurroundingChunks(glm::vec3 center, int chunkRenderDistance);
lua_State* luaState=nullptr;
std::vector<Object*> crossChunkObjects;
std::vector<std::vector<Object*>> sortedCrossChunkObjects;