0

I have a shader 1 depth map texture attached to it.

glGenFramebuffers(1, &depthMapFrameBuffer);

glGenTextures(1, &depthMapTexture);
glBindTexture(GL_TEXTURE_2D, depthMapTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,depthMapTextureSize, depthMapTextureSize, 0, GL_DEPTH_COMPONENT,  GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);

glBindFramebuffer(GL_FRAMEBUFFER, depthMapFrameBuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMapTexture, 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
App::checkFrameBufferError(__FILE__,__LINE__);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE){
    std::cerr << "Framebuffer not complete!" << std::endl;
}
Scene::debugTextures[5] = depthMapTexture;

#version 400 core
layout (location = 0) in vec3 ModelSpaceVertexPosition;

uniform mat4 LightSpaceMatrix;
uniform mat4 ModelMatrix;
uniform mat4 CameraSpaceTransformMatrix;
//uniform mat4 CameraSpaceScaleMatrix;

void main(){

    //todo bug here.. translate to sorun yok ama scale yara rotasyon olmussa camera space matrixi kayiyor. kameraya gore translate oluyorlar
    gl_Position =  LightSpaceMatrix  * CameraSpaceTransformMatrix *  ModelMatrix * vec4(ModelSpaceVertexPosition, 1.0);
}

Is it possible to have more than 1 depth texture attached to different LightSpaceMatrixes in one shader?

Or should I do it in different frame buffers?

genpfault
  • 51,148
  • 11
  • 85
  • 139
aramok
  • 35
  • 1
  • 1
  • 6

1 Answers1

1

Instead of using the fixed function depth pipeline you could just attach multiple depth maps as color attachments(using an explicitly typed texture format), then you can write various values to the different attachments from within the fragment shader.

However if you wanted to render multiple light sources or e.g. cascades in one go you'd need to transform the same vertex multiple times ... which requires more sophisticated techniques.

LJᛃ
  • 7,655
  • 2
  • 24
  • 35