Did a little bit of cleanup.

This commit is contained in:
Faerbit 2015-02-04 22:54:40 +01:00
parent 2e90ac57d8
commit 10082466cf
4 changed files with 13 additions and 48 deletions

View File

@ -8,5 +8,4 @@ out float gl_FragDepth;
void main() { void main() {
gl_FragDepth = length(fragPosition)/farPlane; gl_FragDepth = length(fragPosition)/farPlane;
//gl_FragDepth = 1.5f;
} }

View File

@ -96,14 +96,12 @@ void Graphics::render(double time)
// render depth textures for point lights // render depth textures for point lights
glViewport(0, 0, cube_size, cube_size); glViewport(0, 0, cube_size, cube_size);
glm::mat4 depthProjectionMatrix_pointlights = glm::perspective(1.571f, (float)cube_size/(float)cube_size, 0.1f, farPlane); glm::mat4 depthProjectionMatrix_pointlights = glm::perspective(1.571f, (float)cube_size/(float)cube_size, 0.1f, farPlane);
glm::vec3 looking_directions[6] = {glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(-1.0f, 0.0f, 0.0f), glm::normalize(glm::vec3(0.0f, 1.0f, 0.0f)), glm::vec3 looking_directions[6] = {glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(-1.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f),
glm::normalize(glm::vec3(0.0f, -1.0f, 0.0f)), glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.0f, 0.0f, -1.0f)}; glm::vec3(0.0f, -1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.0f, 0.0f, -1.0f)};
glm::vec3 upvectors[6] = {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 upvectors[6] = {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, 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();
static bool printed = false;
glm::mat4 reproduceMatrix;
//for (unsigned int i_pointlight = 0; i_pointlight<level->getLights()->size(); i_pointlight++) { //for (unsigned int i_pointlight = 0; i_pointlight<level->getLights()->size(); i_pointlight++) {
for (unsigned int i_pointlight = 0; i_pointlight<1 && i_pointlight<level->getLights()->size(); i_pointlight++) { for (unsigned int i_pointlight = 0; i_pointlight<1 && i_pointlight<level->getLights()->size(); i_pointlight++) {
// render each side of the cube // render each side of the cube
@ -116,32 +114,13 @@ void Graphics::render(double time)
glm::mat4 viewMatrix = glm::lookAt(level->getLights()->at(i_pointlight).getPosition(), glm::mat4 viewMatrix = glm::lookAt(level->getLights()->at(i_pointlight).getPosition(),
level->getLights()->at(i_pointlight).getPosition() + looking_directions[i_face], upvectors[i_face]); level->getLights()->at(i_pointlight).getPosition() + looking_directions[i_face], upvectors[i_face]);
glm::mat4 depthViewProjectionMatrix_face = depthProjectionMatrix_pointlights * viewMatrix; glm::mat4 depthViewProjectionMatrix_face = depthProjectionMatrix_pointlights * viewMatrix;
if (i_face == 0) { std::vector<glm::mat4> viewMatrixVector = std::vector<glm::mat4>();
reproduceMatrix = depthViewProjectionMatrix_face; viewMatrixVector.push_back(viewMatrix);
} level->render(depthShader, false, &depthViewProjectionMatrix_face, &viewMatrixVector);
if (!printed) { level->render(depthShader, false, &viewMatrix);
printf("\n\nView matrix:\n %2.10f, %2.10f, %2.10f, %2.10f\n%2.10f, %2.10f, %2.10f, %2.10f\n%2.10f, %2.10f, %2.10f, %2.10f\n%2.10f, %2.10f, %2.10f, %2.10f\n\n\n",
viewMatrix[0][0], viewMatrix[1][0], viewMatrix[2][0], viewMatrix[3][0],
viewMatrix[0][1], viewMatrix[1][1], viewMatrix[2][1], viewMatrix[3][1],
viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2], viewMatrix[3][2],
viewMatrix[0][3], viewMatrix[1][3], viewMatrix[2][3], viewMatrix[3][3]
);
//std::cout<<"View matrix:" <<std::endl << glm::to_string(viewMatrix) << std::endl;
}
std::vector<glm::mat4> foovector = std::vector<glm::mat4>();
foovector.push_back(viewMatrix);
level->render(depthShader, false, &depthViewProjectionMatrix_face, &foovector);
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");
} }
if (saveDepthBufferBool && i_face == 3) {
saveDepthBufferToDisk(3, "face.png");
saveDepthBufferBool = false;
}
}
if (!printed) {
printed = true;
} }
} }
// render depth texture for sun // render depth texture for sun
@ -208,7 +187,6 @@ void Graphics::render(double time)
// render the level // render the level
level->render(lightingShader, true, &lightingViewProjectionMatrix, &shadowVPs); level->render(lightingShader, true, &lightingViewProjectionMatrix, &shadowVPs);
//level->render(lightingShader, true, &reproduceMatrix, &shadowVPs);
} }
void Graphics::updateLights() { void Graphics::updateLights() {
@ -257,20 +235,8 @@ glm::mat4 Graphics::buildViewMatrix(Level* level) {
//construct lookAt (cameraPosition = cameraCenter + cameraVector) //construct lookAt (cameraPosition = cameraCenter + cameraVector)
//return glm::lookAt(level->getCamera()->getPosition(), level->getCamera()->getPosition() + level->getCamera()->getDirection(), glm::vec3(0.0f, 1.0f, 0.0f)); //return glm::lookAt(level->getCamera()->getPosition(), level->getCamera()->getPosition() + level->getCamera()->getDirection(), glm::vec3(0.0f, 1.0f, 0.0f));
glm::mat4 depthViewProjectionMatrix_face = glm::lookAt((level->getCameraCenter()->getPosition() + level->getCamera()->getVector()), return glm::lookAt((level->getCameraCenter()->getPosition() + level->getCamera()->getVector()),
level->getCameraCenter()->getPosition(), glm::vec3(0.0f, 1.0f, 0.0f)); level->getCameraCenter()->getPosition(), glm::vec3(0.0f, 1.0f, 0.0f));
static int i = 5;
if (i == 0) {
printf("\n\nView matrix Camera:\n %2.2f, %2.2f, %2.2f, %2.2f\n%2.2f, %2.2f, %2.2f, %2.2f\n%2.2f, %2.2f, %2.2f, %2.2f\n%2.2f, %2.2f, %2.2f, %2.2f\n\n\n",
depthViewProjectionMatrix_face[0][0], depthViewProjectionMatrix_face[0][1], depthViewProjectionMatrix_face[0][2], depthViewProjectionMatrix_face[0][3],
depthViewProjectionMatrix_face[1][0], depthViewProjectionMatrix_face[1][1], depthViewProjectionMatrix_face[1][2], depthViewProjectionMatrix_face[1][3],
depthViewProjectionMatrix_face[2][0], depthViewProjectionMatrix_face[2][1], depthViewProjectionMatrix_face[2][2], depthViewProjectionMatrix_face[2][3],
depthViewProjectionMatrix_face[3][0], depthViewProjectionMatrix_face[3][1], depthViewProjectionMatrix_face[3][2], depthViewProjectionMatrix_face[3][3]
);
}
i--;
return depthViewProjectionMatrix_face;
} }
float Graphics::getFarPlane() { float Graphics::getFarPlane() {

View File

@ -13,7 +13,7 @@ Object::~Object() {
} }
void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
glm::mat4* viewProjectionMatrix, std::vector<glm::mat4>* shadowVPs) { glm::mat4* viewProjectionMatrix, std::vector<glm::mat4>* additionalMatrices) {
glm::mat4 modelMatrix = glm::translate(getPosition()) * getRotation() * glm::scale<float>(glm::vec3(model.getScale())); glm::mat4 modelMatrix = glm::translate(getPosition()) * getRotation() * glm::scale<float>(glm::vec3(model.getScale()));
if (lightingPass) { if (lightingPass) {
// set lightning parameters for this object // set lightning parameters for this object
@ -26,15 +26,15 @@ void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
shader->setUniform("modelMatrix", modelMatrix); shader->setUniform("modelMatrix", modelMatrix);
// set shadowMVPs // set shadowMVPs
glm::mat4 shadowMVPs[5]; glm::mat4 shadowMVPs[5];
for(unsigned int i = 0; (i<shadowVPs->size() && i<5); i++) { for(unsigned int i = 0; (i<additionalMatrices->size() && i<5); i++) {
shadowMVPs[i] = shadowVPs->at(i) * modelMatrix; shadowMVPs[i] = additionalMatrices->at(i) * modelMatrix;
} }
glUniformMatrix4fv(shader->getUniformLocation("shadowMVPs"), glUniformMatrix4fv(shader->getUniformLocation("shadowMVPs"),
sizeof(shadowMVPs), false, (GLfloat*) shadowMVPs); sizeof(shadowMVPs), false, (GLfloat*) shadowMVPs);
} }
else { else {
if (shadowVPs) { if (additionalMatrices) {
shader->setUniform("modelViewMatrix", shadowVPs->at(0) * modelMatrix); shader->setUniform("modelViewMatrix", additionalMatrices->at(0) * modelMatrix);
} }
} }
glm::mat4 mvp = (*viewProjectionMatrix) * modelMatrix; glm::mat4 mvp = (*viewProjectionMatrix) * modelMatrix;

View File

@ -16,7 +16,7 @@ class Object : public Entity {
Object(); Object();
~Object(); ~Object();
void render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, void render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
glm::mat4* viewProjcetionMatrix, std::vector<glm::mat4>* shadowVPs); glm::mat4* viewProjcetionMatrix, std::vector<glm::mat4>* additionalMatrices);
private: private:
Model model; Model model;
Material material; Material material;