Added maxShadowRenderCount. Controls how many shadows get rendered.

This commit is contained in:
Fabian Klemp 2015-02-13 16:20:22 +01:00
parent 30284977da
commit d7d45682a0
6 changed files with 19 additions and 5 deletions

View File

@ -5,7 +5,7 @@ Application::Application() {
Loader loader = Loader(); Loader loader = Loader();
//load the config.xml //load the config.xml
loader.loadConfig(this); loader.loadConfig(this);
graphics = Graphics(glm::uvec2(windowWidth, windowHeight), 0.1f, farPlane, shadowCubeSize); graphics = Graphics(glm::uvec2(windowWidth, windowHeight), 0.1f, farPlane, shadowCubeSize, maxShadowRenderCount);
} }
void Application::init() void Application::init()
@ -122,3 +122,7 @@ void Application::setHeightmapPath(std::string heightmapPath) {
void Application::setLevelXmlPath(std::string levelXmlPath) { void Application::setLevelXmlPath(std::string levelXmlPath) {
this->levelXmlPath = levelXmlPath; this->levelXmlPath = levelXmlPath;
} }
void Application::setMaxShadowRenderCount(int count) {
this->maxShadowRenderCount = count;
}

View File

@ -22,6 +22,7 @@ class Application {
void setWindowHeight(int windowHeight); void setWindowHeight(int windowHeight);
void setShadowCubeSize(int shadowCubeSize); void setShadowCubeSize(int shadowCubeSize);
void setFarPlane(float farPlane); void setFarPlane(float farPlane);
void setMaxShadowRenderCount(int count);
void setCompositionsPath(std::string compositionsPath); void setCompositionsPath(std::string compositionsPath);
void setShaderPath(std::string shaderPath); void setShaderPath(std::string shaderPath);
void setGeometryPath(std::string geometryPath); void setGeometryPath(std::string geometryPath);
@ -38,6 +39,7 @@ class Application {
int windowWidth; int windowWidth;
int windowHeight; int windowHeight;
int shadowCubeSize; int shadowCubeSize;
int maxShadowRenderCount;
float farPlane; float farPlane;
std::string compositionsPath; std::string compositionsPath;
std::string shaderPath; std::string shaderPath;

View File

@ -7,6 +7,8 @@
<farPlane>150.0</farPlane> <farPlane>150.0</farPlane>
<maxShadowRenderCount>10</maxShadowRenderCount>
<compositionsPath>../Levels/ObjectSetups/Compositions.xml</compositionsPath> <compositionsPath>../Levels/ObjectSetups/Compositions.xml</compositionsPath>
<shaderPath>Shader/</shaderPath> <shaderPath>Shader/</shaderPath>

View File

@ -11,11 +11,14 @@ using namespace ACGL::OpenGL;
const double lightUpdateDelay = 0.5f; const double lightUpdateDelay = 0.5f;
Graphics::Graphics(glm::uvec2 windowSize, float nearPlane, float farPlane, int cube_size) { Graphics::Graphics(glm::uvec2 windowSize, float nearPlane,
float farPlane, int cube_size,
unsigned int maxShadowRenderCount) {
this->windowSize = windowSize; this->windowSize = windowSize;
this->nearPlane = nearPlane; this->nearPlane = nearPlane;
this->farPlane = farPlane; this->farPlane = farPlane;
this->cube_size = cube_size; this->cube_size = cube_size;
this->maxShadowRenderCount = maxShadowRenderCount;
} }
Graphics::Graphics() { Graphics::Graphics() {
@ -109,7 +112,7 @@ void Graphics::render(double time)
glm::vec3(0.0f, 0.0f, -1.0f),glm::vec3(0.0f, -1.0f, 0.0f),glm::vec3(0.0f, -1.0f, 0.0f)}; glm::vec3(0.0f, 0.0f, -1.0f),glm::vec3(0.0f, -1.0f, 0.0f),glm::vec3(0.0f, -1.0f, 0.0f)};
framebuffer_cube->bind(); framebuffer_cube->bind();
for (unsigned int i_pointlight = 0; i_pointlight<closestLights->size(); i_pointlight++) { for (unsigned int i_pointlight = 0; i_pointlight<closestLights->size() && i_pointlight < maxShadowRenderCount; i_pointlight++) {
// render each side of the cube // render each side of the cube
for (int i_face = 0; i_face<6; i_face++) { for (int i_face = 0; i_face<6; i_face++) {
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i_face, depth_cubeMaps.at(i_pointlight)->getObjectName(), 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i_face, depth_cubeMaps.at(i_pointlight)->getObjectName(), 0);

View File

@ -10,7 +10,7 @@
class Graphics { class Graphics {
public: public:
Graphics(glm::uvec2 windowSize, float nearPlane, float farPlane, int cube_size); Graphics(glm::uvec2 windowSize, float nearPlane, float farPlane, int cube_size, unsigned int maxShadowRenderCount);
Graphics(); Graphics();
void init(Level* level); void init(Level* level);
void render(double time); void render(double time);
@ -38,6 +38,7 @@ class Graphics {
std::vector<ACGL::OpenGL::SharedTextureCubeMap> depth_cubeMaps; std::vector<ACGL::OpenGL::SharedTextureCubeMap> depth_cubeMaps;
ACGL::OpenGL::SharedFrameBufferObject framebuffer_cube; ACGL::OpenGL::SharedFrameBufferObject framebuffer_cube;
int cube_size; int cube_size;
unsigned int maxShadowRenderCount;
Level* level; Level* level;
int number_of_texture_units = 0; int number_of_texture_units = 0;
}; };

View File

@ -5,7 +5,7 @@ Loader::Loader() {
} }
void Loader::loadConfig(Application* application) { void Loader::loadConfig(Application* application) {
int windowWidth, windowHeight, shadowCubeSize; int windowWidth, windowHeight, shadowCubeSize, maxShadowRenderCount;
float farPlane; float farPlane;
std::string compositionsPath, shaderPath, geometryPath, texturePath, scriptPath, heightmapPath, levelXmlPath; std::string compositionsPath, shaderPath, geometryPath, texturePath, scriptPath, heightmapPath, levelXmlPath;
XMLDocument* config = new XMLDocument(); XMLDocument* config = new XMLDocument();
@ -20,6 +20,7 @@ void Loader::loadConfig(Application* application) {
errorCheck(resolution->FirstChildElement("height")->QueryIntText(&windowHeight)); errorCheck(resolution->FirstChildElement("height")->QueryIntText(&windowHeight));
errorCheck(config->FirstChildElement("shadowCubeSize")->QueryIntText(&shadowCubeSize)); errorCheck(config->FirstChildElement("shadowCubeSize")->QueryIntText(&shadowCubeSize));
errorCheck(config->FirstChildElement("farPlane")->QueryFloatText(&farPlane)); errorCheck(config->FirstChildElement("farPlane")->QueryFloatText(&farPlane));
errorCheck(config->FirstChildElement("maxShadowRenderCount")->QueryIntText(&maxShadowRenderCount));
const char* charCompositionsPath = config->FirstChildElement("compositionsPath")->GetText(); const char* charCompositionsPath = config->FirstChildElement("compositionsPath")->GetText();
if(charCompositionsPath == NULL){ if(charCompositionsPath == NULL){
@ -74,6 +75,7 @@ void Loader::loadConfig(Application* application) {
application->setWindowHeight(windowHeight); application->setWindowHeight(windowHeight);
application->setShadowCubeSize(shadowCubeSize); application->setShadowCubeSize(shadowCubeSize);
application->setFarPlane(farPlane); application->setFarPlane(farPlane);
application->setMaxShadowRenderCount(maxShadowRenderCount);
application->setCompositionsPath(compositionsPath); application->setCompositionsPath(compositionsPath);
application->setShaderPath(shaderPath); application->setShaderPath(shaderPath);
application->setGeometryPath(geometryPath); application->setGeometryPath(geometryPath);