Only render objects which are visible.

This commit is contained in:
Faerbit 2015-03-10 00:46:50 +01:00
parent 18bda9181f
commit 28c5212a03
4 changed files with 19 additions and 8 deletions

View File

@ -330,7 +330,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, &depthViewProjectionMatrix_face, &viewMatrixVector);
level->render(depthCubeShader, false, &depthViewProjectionMatrix_face, farPlane, &viewMatrixVector);
if (!framebuffer_cube->isFrameBufferObjectComplete()) {
printf("Framebuffer incomplete, unknown error occured during shadow generation!\n");
}
@ -363,7 +363,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, &depthViewProjectionMatrices.at(i));
level->render(depthShader, false, &depthViewProjectionMatrices.at(i), farPlane);
}
if (!framebuffer_directional.at(i)->isFrameBufferObjectComplete()) {
printf("Framebuffer incomplete, unknown error occured during shadow generation!\n");
@ -459,7 +459,7 @@ void Graphics::render(double time)
lightingShader->setUniform("time", (float) time);
// render the level
level->render(lightingShader, true, &lightingViewProjectionMatrix, &depthBiasVPs);
level->render(lightingShader, true, &lightingViewProjectionMatrix, farPlane, &depthBiasVPs);
// draw flames on top
flameShader->use();

View File

@ -56,13 +56,17 @@ void Level::load() {
}
void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
glm::mat4* viewProjectionMatrix, std::vector<glm::mat4>* shadowVPs) {
glm::mat4* viewProjectionMatrix, float farPlane, std::vector<glm::mat4>* shadowVPs) {
for(unsigned int i = 0; i<objects.size(); i++) {
if (lightingPass) {
objects.at(i)->render(shader, lightingPass, true, viewProjectionMatrix, shadowVPs);
if (glm::distance(objects.at(i)->getPosition(), cameraCenter->getPosition()) < farPlane + 5.0f || objects.at(i) == terrainObject) {
objects.at(i)->render(shader, lightingPass, true, viewProjectionMatrix, shadowVPs);
}
}
else {
objects.at(i)->render(shader, lightingPass, false, viewProjectionMatrix, shadowVPs);
if (glm::distance(objects.at(i)->getPosition(), cameraCenter->getPosition()) < farPlane + 5.0f || objects.at(i) == terrainObject) {
objects.at(i)->render(shader, lightingPass, false, viewProjectionMatrix, shadowVPs);
}
}
}
if (lightingPass) {
@ -341,3 +345,8 @@ void Level::activateEndgame(){
void Level::setWaterPlane(Object* water) {
this->waterPlane = water;
}
void Level::addTerrain(Object* terrain) {
this->terrainObject = terrain;
objects.push_back(terrain);
}

View File

@ -28,7 +28,7 @@ class Level {
void update(float runTimeSinceLastUpdate, float runTime, glm::vec2 mouseDelta,bool wPressed, bool aPressed,bool sPressed, bool dPressed, bool kPressed, bool lPressed,
bool f1Pressed, bool f2Pressed, bool f3Pressed, bool f4Pressed );
void render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
glm::mat4* viewProjectionMatrix, std::vector<glm::mat4>* shadowVPs=0);
glm::mat4* viewProjectionMatrix, float farPlane, std::vector<glm::mat4>* shadowVPs=0);
glm::vec3 getAmbientLight();
Light* getDirectionalLight();
std::vector<Light>* getLights();
@ -67,6 +67,7 @@ class Level {
void addTrigger(Trigger trigger);
lua_State* getLuaState();
Terrain* getTerrain();
void addTerrain(Object* terrain);
void resetPlayer();
void movePlayer(float xPosition, float yPosition, float zPosition);
void setPlayerIndex(int index);
@ -94,6 +95,7 @@ class Level {
float strength;
std::string xmlFilePath;
glm::vec3 nextLightPosition;
Object* terrainObject;
};
#endif

View File

@ -86,7 +86,7 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
Object* terrainObject = new Object(terrainModel, terrainMaterial,
glm::vec3(-0.5*((float)level->getTerrain()->getHeightmapHeight()-1), 0.0f, -0.5f*((float)level->getTerrain()->getHeightmapWidth()-1)),
glm::vec3(0.0f, 0.0f, 0.0f), true);
level->addObject(terrainObject);
level->addTerrain(terrainObject);
level->getPhysics()->addTerrain(level->getTerrain()->getHeightmapWidth(), level->getTerrain()->getHeightmapHeight(), level->getTerrain()->getHeightmap());
//load the skydome