Only render objects which are visible.
This commit is contained in:
parent
18bda9181f
commit
28c5212a03
@ -330,7 +330,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, &depthViewProjectionMatrix_face, &viewMatrixVector);
|
level->render(depthCubeShader, false, &depthViewProjectionMatrix_face, farPlane, &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");
|
||||||
}
|
}
|
||||||
@ -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) *
|
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, &depthViewProjectionMatrices.at(i));
|
level->render(depthShader, false, &depthViewProjectionMatrices.at(i), farPlane);
|
||||||
}
|
}
|
||||||
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");
|
||||||
@ -459,7 +459,7 @@ void Graphics::render(double time)
|
|||||||
lightingShader->setUniform("time", (float) time);
|
lightingShader->setUniform("time", (float) time);
|
||||||
|
|
||||||
// render the level
|
// render the level
|
||||||
level->render(lightingShader, true, &lightingViewProjectionMatrix, &depthBiasVPs);
|
level->render(lightingShader, true, &lightingViewProjectionMatrix, farPlane, &depthBiasVPs);
|
||||||
|
|
||||||
// draw flames on top
|
// draw flames on top
|
||||||
flameShader->use();
|
flameShader->use();
|
||||||
|
15
level.cc
15
level.cc
@ -56,13 +56,17 @@ void Level::load() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
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++) {
|
for(unsigned int i = 0; i<objects.size(); i++) {
|
||||||
if (lightingPass) {
|
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 {
|
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) {
|
if (lightingPass) {
|
||||||
@ -341,3 +345,8 @@ void Level::activateEndgame(){
|
|||||||
void Level::setWaterPlane(Object* water) {
|
void Level::setWaterPlane(Object* water) {
|
||||||
this->waterPlane = water;
|
this->waterPlane = water;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Level::addTerrain(Object* terrain) {
|
||||||
|
this->terrainObject = terrain;
|
||||||
|
objects.push_back(terrain);
|
||||||
|
}
|
||||||
|
4
level.hh
4
level.hh
@ -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,
|
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 );
|
bool f1Pressed, bool f2Pressed, bool f3Pressed, bool f4Pressed );
|
||||||
void render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
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();
|
glm::vec3 getAmbientLight();
|
||||||
Light* getDirectionalLight();
|
Light* getDirectionalLight();
|
||||||
std::vector<Light>* getLights();
|
std::vector<Light>* getLights();
|
||||||
@ -67,6 +67,7 @@ class Level {
|
|||||||
void addTrigger(Trigger trigger);
|
void addTrigger(Trigger trigger);
|
||||||
lua_State* getLuaState();
|
lua_State* getLuaState();
|
||||||
Terrain* getTerrain();
|
Terrain* getTerrain();
|
||||||
|
void addTerrain(Object* terrain);
|
||||||
void resetPlayer();
|
void resetPlayer();
|
||||||
void movePlayer(float xPosition, float yPosition, float zPosition);
|
void movePlayer(float xPosition, float yPosition, float zPosition);
|
||||||
void setPlayerIndex(int index);
|
void setPlayerIndex(int index);
|
||||||
@ -94,6 +95,7 @@ class Level {
|
|||||||
float strength;
|
float strength;
|
||||||
std::string xmlFilePath;
|
std::string xmlFilePath;
|
||||||
glm::vec3 nextLightPosition;
|
glm::vec3 nextLightPosition;
|
||||||
|
Object* terrainObject;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -86,7 +86,7 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
|
|||||||
Object* terrainObject = new Object(terrainModel, terrainMaterial,
|
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.5*((float)level->getTerrain()->getHeightmapHeight()-1), 0.0f, -0.5f*((float)level->getTerrain()->getHeightmapWidth()-1)),
|
||||||
glm::vec3(0.0f, 0.0f, 0.0f), true);
|
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());
|
level->getPhysics()->addTerrain(level->getTerrain()->getHeightmapWidth(), level->getTerrain()->getHeightmapHeight(), level->getTerrain()->getHeightmap());
|
||||||
|
|
||||||
//load the skydome
|
//load the skydome
|
||||||
|
Loading…
Reference in New Issue
Block a user