Hi, All.
After success reworking CSM from separated textures to texture array, I want to do similar refactoring with shadow cube of point lights.
So, I try to use GL_TEXTURE_CUBE_MAP_ARRAY instead several GL_TEXTURE_CUBE_MAP.
When I use one point light it is looks fine, but when I try to it with two there is some mess with cube faces:
one:
[ATTACH=CONFIG]1626[/ATTACH]
two:
[ATTACH=CONFIG]1627[/ATTACH]
I,m using OpenGl 4.0, lwjgl (java opengl library)
CubeShadowBuffer:
depthMapFBO = glGenFramebuffers();
depthMap = new CubeTexture(shadowMapWidth, shadowMapHeight, GL_DEPTH_COMPONENT, lightsNumber);
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthMap.getId(), 0, 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
int status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) {
// number of problem from enum
throw new IllegalStateException("Could not create FrameBuffer: " + (status - GL_FRAMEBUFFER_COMPLETE));
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
CubeTexture:
id = glGenTextures();
glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, id);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0, GL_DEPTH_COMPONENT, width, height, 6 * lightsNumber, 0, GL_DEPTH_COMPONENT, GL_FLOAT, (ByteBuffer) null);
glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, 0);
Cycle of rendering:
public void render(Display display, Camera camera, Scene scene, Transformation transformation, IHud hud) {
glViewport(0, 0, SHADOW_MAP_WIDTH, SHADOW_MAP_HEIGHT);
for (int cnt = 0; cnt < MAX_POINT_LIGHTS; cnt++) {
Matrix4f viewMatrix = camera.updateViewMatrix();
update(display, viewMatrix, scene, cnt);
depthShaderProgram.bind();
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
glCullFace(GL_BACK);
glClearColor(Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE);
renderCubeFace(shadowBuffer, pointLightShadowBox.getRightMap(), 0 + cnt, scene, transformation);
renderCubeFace(shadowBuffer, pointLightShadowBox.getLeftMap(), 1 + cnt, scene, transformation);
renderCubeFace(shadowBuffer, pointLightShadowBox.getTopMap(), 2 + cnt, scene, transformation);
renderCubeFace(shadowBuffer, pointLightShadowBox.getBottomMap(), 3 + cnt, scene, transformation);
renderCubeFace(shadowBuffer, pointLightShadowBox.getRearMap(), 4 + cnt, scene, transformation);
renderCubeFace(shadowBuffer, pointLightShadowBox.getFrontMap(), 5 + cnt, scene, transformation);
depthShaderProgram.unbind();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDrawBuffer(GL_BACK);
glReadBuffer(GL_BACK);
}
}
private void renderCubeFace(CubeShadowBuffer shadowBuffer, ShadowMap shadowMap, int face, Scene scene, Transformation transformation) {
depthShaderProgram.setUniform("projectionMatrix", shadowMap.getProjectionMatrix());
depthShaderProgram.setUniform("lightViewMatrix", shadowMap.getLightViewMatrix());
glBindFramebuffer(GL_FRAMEBUFFER, shadowBuffer.getDepthMapFBO());
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, shadowBuffer.getDepthMapTexture().getId(), 0, face);
glDrawBuffer(GL_DEPTH_ATTACHMENT);
glClear(GL_DEPTH_BUFFER_BIT);
renderMeshes(scene, transformation);
}
Thank you for help!