Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  FBO depth texture not working properly  (Read 2781 times)
0 Members and 1 Guest are viewing this topic.
Offline epicbo

Senior Newbie





« Posted 2012-05-05 23:32:22 »

So, im trying to implement shadow mapping into my game and I can't seem to render to the depth texture properly (which is attached to a FBO). I don't know what part of the code that causes this problem so I wont post code for now. Anyway, here's a screenshot from my game. It has nothing to do with the problem, I posted it so you could see how it looks like.



Anyway, so instead of rendering the actual textures, I rendered the depth map instead. This is the result:



Yeah, that's not how it should look like. There appears to be a lot of tiny point everywhere and if you look closley, you can see that theres a line where every edge of the triangle is. However, look at the quad to the right. The depthmap seems to be correct for that quad.

I increased the depth texture dimensions and it now looks like this:



More and smaller points, not very surprising. I'm completly lost now. It's probably something really simple, but I can't just figure out what it is. Oh, and by the way, the depth texture is not rendered from the lights POV, but the cameras. I did this to make it more simple.

Any ideas on why this could be happening?

Edit: It appears to work the way it should if the size of the depth texture is less than or equal to 32x32. This doesn't make me less confused though.

Offline theagentd
« Reply #1 - Posted 2012-05-06 08:38:16 »

You´re having the depth texture bound while rendering to it? AH. You forgot to set the viewport! xD

Myomyomyo.
Offline epicbo

Senior Newbie





« Reply #2 - Posted 2012-05-06 10:50:48 »

The depth texture is not bound while rendering to it. This is my depth map rendering method (simplified)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
public void createDepthMap(Light light) {
     
   glBindFramebuffer(GL_FRAMEBUFFER, light.getShadowMapFBO());
     
   glClear(GL_DEPTH_BUFFER_BIT);
     
   glPushAttrib(GL_VIEWPORT_BIT);
   glViewport(0,0,Constants.SHADOW_MAP_WIDTH, Constants.SHADOW_MAP_HEIGHT);
   glColorMask(false, false, false, false);
   
   for (Renderable r : renderableEntities)
         r.render();
     
   glColorMask(true, true, true, true);
   glPopAttrib();
   glBindFramebuffer(GL_FRAMEBUFFER, 0);
     
   glActiveTexture(GL_TEXTURE7);
   glBindTexture(GL_TEXTURE_2D,light.getShadowMapTexture());
   glActiveTexture(GL_TEXTURE0);
   
}


Here's my FBO generation method if it makes any difference

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
public void initFBO() {

      depthTexture = glGenTextures();
      glBindTexture(GL_TEXTURE_2D, depthTexture);
     
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
      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_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
      glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
     
      glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, Constants.SHADOW_MAP_WIDTH, Constants.SHADOW_MAP_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, (ByteBuffer)null);
     
      glBindTexture(GL_TEXTURE_2D, 0);
     
      fbo = glGenFramebuffers();
      glBindFramebuffer(GL_FRAMEBUFFER,fbo);
      glDrawBuffer(GL_NONE);
      glReadBuffer(GL_NONE);
     
      glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D, depthTexture, 0);
     
      int FBOstatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
        if(FBOstatus != GL_FRAMEBUFFER_COMPLETE)
           System.out.println("GL_FRAMEBUFFER_COMPLETE failed, CANNOT use FBO\n");

        glBindFramebuffer(GL_FRAMEBUFFER, 0);

   }
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #3 - Posted 2012-05-06 11:02:04 »

Shader problem? You're also not changing to the light's matrix when rendering the shadow map.

Myomyomyo.
Offline epicbo

Senior Newbie





« Reply #4 - Posted 2012-05-06 11:46:32 »

Could definitly be a shader problem. Ill try to remove all unrelated code in my shaders and post them here later today.

The reason why im not changing to the lights matrix is because right now I'm rendering the depth texture from the cameras POV.
Offline theagentd
« Reply #5 - Posted 2012-05-06 11:48:18 »

You might still need to at least update the projection matrix since you have a new aspect ratio. Frankly I´m at quite a loss here...

Myomyomyo.
Offline epicbo

Senior Newbie





« Reply #6 - Posted 2012-05-07 15:32:06 »

I finally managed to solve it! All I had to do was to disable textures when rendering the depth map.

Still not sure why. It worked when I did this:

1  
2  
3  
4  
5  
// Works
glBindTexture(GL_TEXTURE_2D, tex1)
object1.render();
object2.render();
...


But if I bound another texture it stopped working:

1  
2  
3  
4  
5  
6  
// Doesn't work
glBindTexture(GL_TEXTURE_2D, tex1)
object1.render();
glBindTexture(GL_TEXTURE_2D, tex2)
object2.render();
...


Really weird. Anyway, I'm really happy I finally got it working.

Also,

You might still need to at least update the projection matrix since you have a new aspect ratio. Frankly I´m at quite a loss here...

Thanks for this. I actually forgot to make a new projection matrix. Perhaps not a huge deal, but it probably would've given me some bugs to fix later on.

Now I gotta post some smileys to express my happiness:

 Grin Grin Smiley Cheesy Grin Cool Tongue Smiley Grin
Offline theagentd
« Reply #7 - Posted 2012-05-07 15:38:47 »

... which is why I hate the fixed functionality pipeline. You know what happens if you call glColor(...)? ALL following vertices will have the same color. What do you think happens if you have a texture bound but no texture coordinates? It uses the same coordinates (the ones last specified) for every vertex and samples the texture with it! =D Go go OGL3!

Myomyomyo.
Offline ra4king

JGO Kernel


Medals: 342
Projects: 2
Exp: 5 years


I'm the King!


« Reply #8 - Posted 2012-05-07 15:57:04 »

You know what happens if you call glColor(...)? ALL following vertices will have the same color.
How is this bad? O_o

What do you think happens if you have a texture bound but no texture coordinates? It uses the same coordinates (the ones last specified) for every vertex and samples the texture with it!
Shocked I could imagine that to lead to some really weird bugs! Grin

Offline epicbo

Senior Newbie





« Reply #9 - Posted 2012-05-07 16:00:36 »

I agree. Starting to use VBOs and writing my own shaders was the best decision ever. Not only is it easier to achieve what you want to, it also gives you a much better understanding of basicly everything related to graphics programming.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #10 - Posted 2012-05-07 16:10:51 »

You know what happens if you call glColor(...)? ALL following vertices will have the same color.
How is this bad? O_o

What do you think happens if you have a texture bound but no texture coordinates? It uses the same coordinates (the ones last specified) for every vertex and samples the texture with it!
Shocked I could imagine that to lead to some really weird bugs! Grin
How is that good?! It´s ridiculously easy to forget one of them. glClearColor, glEnable(over 9000 different values), glColor, glTexCoord, glSecondaryColor, glBlendMode, e.t.c. If you don´t want texturing you have to disable it or unbind any texture. With OpenGL 3 it doesn´t matter since your shader won´t read the texture. OpenGL reduces the number settings to a managable number, partly by deprecating a lot and partly by forcing you to use things like VAOs, shaders, e.t.c. You can´t leak glClientEnable() stuff since you have VAOs, you can´t leak vertex attributes since everything has to be in buffers, only a very small number of glEnables exist so it´s easy to keep track of them.

Not to mention better performance with instancing and geometry shaders. Oh, and texturing that makes sense. Sampler objects should´ve been there in OGL 0.1, and the pre-shader multitexturing controls are a complete joke.

Myomyomyo.
Offline epicbo

Senior Newbie





« Reply #11 - Posted 2012-05-07 16:38:32 »

It's a shame that a lot of computers doesn't support OpenGL 3+ yet. That's why im limiting myself to OpenGL 2 for now.

Anyway, here's a off-topic question. Are loops supported in GLSL 1.20? The shader doesn't work on my old computer (which supports glsl 1.2 and opengl 2.1). It compiles without any errors but everything is just black. If I remove the loop and just copy everything inside it a few times, it will work. 
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (26 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (13 views)
2014-07-29 10:59:34

E.R. Fleming (34 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (44 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!