struct CameraDirection
{
GLenum CubemapFace;
glm::vec3 Target;
glm::vec3 Up;
};
static const CameraDirection CameraDirections[6] =
{
{ GL_TEXTURE_CUBE_MAP_POSITIVE_X, glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f) },
{ GL_TEXTURE_CUBE_MAP_NEGATIVE_X, glm::vec3(-1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f) },
{ GL_TEXTURE_CUBE_MAP_POSITIVE_Y, glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f) },
{ GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, glm::vec3(0.0f, -1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f) },
{ GL_TEXTURE_CUBE_MAP_POSITIVE_Z, glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.0f, -1.0f, 0.0f) },
{ GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, glm::vec3(0.0f, 0.0f, -1.0f), glm::vec3(0.0f, -1.0f, 0.0f) }
};
void ShadowCube::Update(glm::mat4){
GLint viewPort[4];
glGetIntegerv(GL_VIEWPORT, viewPort);
glViewport(0, 0, shadowMapW, shadowMapH);
glClearColor(FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX);
for(int i = 0; i < 6; i++){
glBindFramebuffer(GL_FRAMEBUFFER, frameBuff.getID());
glBindTexture(GL_TEXTURE_CUBE_MAP, cubeMapBuffer.getID());
viewProjectionMatrix = glm::perspective <float>(glm::radians(90.0f), shadowMapW / shadowMapH, 1.0f, 500.0f) * glm::lookAt(myCenterPos, myCenterPos + CameraDirections[i].Target, CameraDirections[i].Up);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, cubeMapBuffer.getID(), 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//Grab current view before adjusting
glUseProgram(depthProgID.getID());
GLuint vpLoc = glGetUniformLocation(depthProgID.getID(), "depthVP");
glUniformMatrix4fv(vpLoc, 1, GL_FALSE, glm::value_ptr(viewProjectionMatrix));
glUseProgram(skelDepthProgID.getID());
vpLoc = glGetUniformLocation(skelDepthProgID.getID(), "VP");
glUniformMatrix4fv(vpLoc, 1, GL_FALSE, glm::value_ptr(viewProjectionMatrix));
DrawAllEntDepth();
frameBuff.checkFBO();
}
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(viewPort[0], viewPort[1], viewPort[2], viewPort[3]);
}