PDA

View Full Version : multipass rendering and polygon bleeding



mantesat
01-13-2004, 04:05 AM
Hi all,

I'm trying to create a terrain model by using a rectangular grid as a geometric model and applying many different textures as tiles to cover the entire grid using automatic texture coord generation. Everything goes well, but when the camera goes near the ground it can see polygons that are behind mountains and should not be visible. I know that zNear/zFar values are normal and they don't cause this. Could this happen because of blending, or because of multiple rendering passes? Any ideas?

Oh, I 'm rendering texture tiles using GL_CLAMP_TO_BORDER mode, with transparent border color so as not for an individual tile to spread all over the area. This causes some lines to appear in GL_LINEAR mode, but I don't think there is another way to render two or more textures on the same geometry and on different places, without the one to mix with the other...

Jens Scheddin
01-13-2004, 05:53 AM
Make sure you disable depth buffer writes with glDepthMask(0) and set the depth func to GL_EGUAL with glDepthFunc(GL_EQUAL) for the passes that you blend over the first pass. it's important that the depth buffer is filled by the first pass if you blend other passes onto it.

Hope this helps

mantesat
01-13-2004, 06:18 AM
Uhmmm..this seems to vanish my scene...

This is what I'm doing so far :

//if k passes must be rendered

for(int i=0;i<k;i++){

//bind texture, enable texture, generate coords automatically

if (i==0){
glDisable(GL_BLEND);
}else{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}

if (i<k-1){
glDepthMask(0);
}else{
glDepthMask(1);
}

//draw geometry...

//end of pass
}

Various blending modes have produced the same "bleeding results", but with different colors....I tend to believe that this is caused by poor depth buffer precision? Will stencil/alpha testing help to avoid that? How can stencil/alpha testing be used with multipass rendering?

Jens Scheddin
01-13-2004, 10:19 AM
You are disableing depth buffer writes for every except the last pass but you should enable it for the first pass only and disable it on the others:




if (i<k-1){
glDepthMask(1);
glDepthFunc(GL_LEQUAL);
}else{
glDepthMask(0);
glDepthFunc(GL_EQUAL);
}


This should be the way to render your geometry. Also, make sure you have enabled depth test via glEnable(GL_DEPTH_TEST).

mantesat
01-14-2004, 12:03 AM
Thanks! It now seems to work ...