Jump to content
  • Advertisement
Sign in to follow this  
virtual_bug

gl_texture_2d_array, FBO and shadowmaps

This topic is 2307 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]

Hi everybody, [/font]

[font=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]

I'm switching from regular 2D textures to 2D texture arrays. [/font]There is ok with one single texture2D, and now I'm trying to generate each shadowmap (for each light) on one layer of TEXTURE_2D_ARRAY, but i have some difficulties ! To initialize shadowmaps, i proceed like that :


void initShadows(GLAutoDrawable drawable)
{
GL3 gl = (GL3)drawable.getGL().getGL3();
shadow_tex = Buffers.newDirectIntBuffer(1);
gl.glGenTextures(1, shadow_tex);
this.shadow_fbo = Buffers.newDirectIntBuffer(1);
gl.glGenFramebuffers(1, shadow_fbo);

gl.glActiveTexture(GL2.GL_TEXTURE2);
gl.glGenTextures(1, shadow_tex);
gl.glBindTexture(GL2.GL_TEXTURE_2D_ARRAY, shadow_tex.get(0));
gl.glTexParameteri(GL2.GL_TEXTURE_2D_ARRAY, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST);
gl.glTexParameteri(GL2.GL_TEXTURE_2D_ARRAY, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST);
gl.glTexParameteri(GL2.GL_TEXTURE_2D_ARRAY, GL2.GL_TEXTURE_WRAP_S, GL2.GL_CLAMP_TO_BORDER );
gl.glTexParameteri(GL2.GL_TEXTURE_2D_ARRAY, GL2.GL_TEXTURE_WRAP_T, GL2.GL_CLAMP_TO_BORDER );
gl.glTexParameteri(GL2.GL_TEXTURE_2D_ARRAY, GL2.GL_TEXTURE_COMPARE_MODE, GL2.GL_COMPARE_REF_TO_TEXTURE);
gl.glTexParameteri(GL2.GL_TEXTURE_2D_ARRAY, GL2.GL_TEXTURE_COMPARE_FUNC, GL2.GL_LESS);
gl.glTexParameterfv(GL2.GL_TEXTURE_2D_ARRAY, GL2.GL_TEXTURE_BORDER_COLOR, white, 0);
gl.glTexImage3D(GL2.GL_TEXTURE_2D_ARRAY, 0, GL2.GL_DEPTH_COMPONENT32, (int)shadowTexSizeX, (int)shadowTexSizeY, (int)spotLights.size(), 0, GL2.GL_DEPTH_COMPONENT, GL2.GL_UNSIGNED_BYTE, null);
gl.glBindTexture(GL2.GL_TEXTURE_2D_ARRAY, 0);
gl.glBindFramebuffer(GL2.GL_DRAW_FRAMEBUFFER, this.shadow_fbo.get(0));
gl.glFramebufferTexture(GL2.GL_DRAW_FRAMEBUFFER, GL3.GL_DEPTH_ATTACHMENT, this.shadow_tex.get(0), 0);
}




and to draw on the light point of view, on each layer of the texture :



gl.glBindFramebuffer(GL2.GL_DRAW_FRAMEBUFFER, shadow_fbo.get(0));
gl.glClear(GL2.GL_DEPTH_BUFFER_BIT);
gl.glColorMask(false, false, false, false);
gl.glDisable(GL2.GL_BLEND);
glFw.pushProjectionMatrix();
glFw.pushViewMatrix();
for(int i=0; i<spotLights.size(); i++)
{
gl.glViewport(0, 0, (int)shadowTexSizeX, (int)shadowTexSizeY);
//last i parameter for the layer of the texture array
gl.glFramebufferTextureLayer(GL2.GL_DRAW_FRAMEBUFF ER, GL2.GL_DEPTH_ATTACHMENT, this.shadow_tex.get(0), 0, i);
.....
//set point of view for each light and draw scene




and, my fragment shader for final rendering with shadowmaps :


uniform sampler2DArrayShadow texShadow;
vec4 shadowCoordinateWdivide = shadowCoord / shadowCoord.w;
for(i=0; i< nbSpotLight; i++)
// i for layer
float shadow = texture(texShadow, vec4(shadowCoordinateWdivide.xyz, i));
... light calculation ponderate by shadow


is it something wrong ? I'm blocked for few days on that, i need your help please ! Ask me if you need some precision about code, or something else. Thanks. Edited by virtual_bug

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!