Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Creation of depthmap:
- shadowBufferStruct shadowFrameBufferCreator(GLfloat shadowWidth, GLfloat shadowHeight)
- {
- shadowBufferStruct shadowBuf;
- //Create the FBO and the required textures
- GLuint depthMapFBO;
- glGenFramebuffers(1, &shadowBuf.depthMapFBO);
- //Depth map texture
- GLuint depthMap;
- glGenTextures(1, &shadowBuf.depthMap);
- glBindTexture(GL_TEXTURE_2D, shadowBuf.depthMap);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowWidth, shadowHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glBindFramebuffer(GL_FRAMEBUFFER, shadowBuf.depthMapFBO);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadowBuf.depthMap, 0);
- glDrawBuffer(GL_NONE); //No color buffer needed
- glReadBuffer(GL_NONE);
- if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
- printf("\nFramebuffer is not complete!");
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
- //Create LSMatrix
- GLfloat near_plane = 1.0f;
- GLfloat far_plane = 10.0f;
- glm::mat4 lightProjMat = glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane);
- glm::mat4 lightViewMatrix = glm::lookAt(glm::vec3(-2.0f, 6.0f, -1.0f),
- glm::vec3(0.0f, 0.0f, 0.0f),
- glm::vec3(0.0f, 1.0f, 0.0f));
- shadowBuf.lightSpaceMat = lightProjMat * lightViewMatrix;
- return shadowBuf;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement