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; glm::mat4 depthViewProjectionMatrix_face = depthProjectionMatrix_pointlights * viewMatrix;
std::vector<glm::mat4> viewMatrixVector = std::vector<glm::mat4>(); std::vector<glm::mat4> viewMatrixVector = std::vector<glm::mat4>();
viewMatrixVector.push_back(viewMatrix); 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()) { if (!framebuffer_cube->isFrameBufferObjectComplete()) {
printf("Framebuffer incomplete, unknown error occured during shadow generation!\n"); 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) * 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)); 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()) { if (!framebuffer_directional.at(i)->isFrameBufferObjectComplete()) {
printf("Framebuffer incomplete, unknown error occured during shadow generation!\n"); 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, 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<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++) { for(unsigned int i = 0; i<nearChunks.size(); i++) {
nearChunks.at(i)->render(shader, lightingPass, viewProjectionMatrix, shadowVPs); 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) { 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++) { for(unsigned int i = 0; i<nearChunks.size(); i++) {
graphics->enqueueObjects(nearChunks.at(i)->getSortedObjects()); graphics->enqueueObjects(nearChunks.at(i)->getSortedObjects());
} }
graphics->enqueueObjects(&sortedCrossChunkObjects); graphics->enqueueObjects(&sortedCrossChunkObjects);
} }
std::vector<Chunk*> Level::getSurroundingChunks(int chunkRenderDistance) { std::vector<Chunk*> Level::getSurroundingChunks(glm::vec3 center, int chunkRenderDistance) {
int renderDistance = 0; int renderDistance = 0;
if (chunkRenderDistance < 0) { if (chunkRenderDistance < 0) {
if ((int)farPlane % chunkSize == 0) { if ((int)farPlane % chunkSize == 0) {
@ -84,8 +84,8 @@ std::vector<Chunk*> Level::getSurroundingChunks(int chunkRenderDistance) {
else { else {
renderDistance = chunkRenderDistance; renderDistance = chunkRenderDistance;
} }
int xPosition = ((int)cameraCenter->getPosition().x + (terrain.getHeightmapWidth()/2))/chunkSize; int xPosition = ((int)center.x + (terrain.getHeightmapWidth()/2))/chunkSize;
int zPosition = ((int)cameraCenter->getPosition().z + (terrain.getHeightmapHeight()/2))/chunkSize; int zPosition = ((int)center.z + (terrain.getHeightmapHeight()/2))/chunkSize;
int xStart = xPosition - renderDistance; int xStart = xPosition - renderDistance;
unsigned int xEnd = xPosition + renderDistance; unsigned int xEnd = xPosition + renderDistance;
int zStart = zPosition - renderDistance; int zStart = zPosition - renderDistance;

View File

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