PDA

View Full Version : texture problems when doing multiple passes



MrRolf
07-27-2003, 08:07 AM
Anyone want to take a shot at why my texture is doing this? I'm trying to bumpmap and shadow projection in multiple passes:
first, drawing from the camera's POV.
second, drawing the model and floor normally. The model is bumpmapped, using register combiners and vertex program.
third, draw the floor and model with shadows. enabling blending.
http://www.prism.gatech.edu/~gte810p/sshot3.jpg http://www.prism.gatech.edu/~gte810p/sshot4.jpg

titan
07-27-2003, 12:43 PM
Do you output valid texture coordinates to all texture units?

OneSadCookie
07-27-2003, 01:52 PM
Could be z-fighting. Make sure your z comparison function passes on equality.

MrRolf
07-27-2003, 02:46 PM
titan: I believe I have valid text coords for all units. The quad that the model is on (the floor) renders fine. It is only on the model that I get the artifact. I'll keep looking through to make sure though.

OneSadCookie: I have glDepthFunc(GL_LEQUAL). Is that what you mean? The other depth function I use is SGIX for the shadow mapping, and that's set to GL_TEXTURE_LEQUAL_R_SGIX.

Thanks for the ideas.

rgpc
07-27-2003, 03:53 PM
Originally posted by MrRolf:
OneSadCookie: I have glDepthFunc(GL_LEQUAL). Is that what you mean?

I think OneSadCookie meant that you should make sure that you're not doing something that would make your geometry lose it's positional invariance in your second pass. ie. Some state changes (and methods of sending your geometry to Opengl) will cause your geometry to be in a slightly different position between passes.

However, your images look a little too uniform for z-fighting (but you never know). Do each of the passes render OK if done on their own?

MrRolf
07-27-2003, 05:10 PM
yes, both passes render OK seperately.

I don't do anything to the geometry between passes. Here are the state changes I do though:

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
//... Let ogl do some matrix math for me here
glGetFloatv(GL_MODELVIEW_MATRIX, m);
glLoadIdentity();
glPopMatrix();


glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, shadowTex);
glEnable(GL_TEXTURE_2D);

glTexParameterf(GL_TEXTURE_2D, GL_SHADOW_AMBIENT_SGIX, 0.5);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_SGIX, GL_TRUE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_OPERATOR_SGIX, GL_TEXTURE_LEQUAL_R_SGIX);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

//Do this for S, T, R, Q
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_S, GL_EYE_PLANE, objPlaneS);
glEnable(GL_TEXTURE_GEN_S);

//
//Repeat above for GL_TEXTURE1_ARB
//

glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
glDepthMask(GL_FALSE);
glEnable(GL_LIGHTING);
glBlendEquationEXT(GL_MAX_EXT);

[This message has been edited by MrRolf (edited 07-27-2003).]

dorbie
07-27-2003, 08:13 PM
When you do depth texture shadows you're supposed to include an offset to stop depth aliasing like this.

The other solution (for solid objects only) is to draw the backfacing objects and cull the frunt faces when you render the depth texture.

SirKnight
07-27-2003, 08:27 PM
Do you use glPolygonOffset before you render the scene from the light's view?

-SirKnight

MrRolf
07-27-2003, 08:32 PM
dorbie: I enable GL_POLYGON_OFFSET_FILL and call glPolygonOffset with appropriate numbers before I draw to the shadow map. I varied the factor from 1.1 to 40.0, and the units from 1.0 to 80.0. This unfortunately did not help my problem.

I enabled front face culling, and it had no affect on the texture problem.

Thanks

MrRolf
07-27-2003, 08:41 PM
If I disable bumpmapping on the model, it works fine.
I use 4 texture units, 2 2D and 2 cubemap, to bump mapp. I also use register combiners and a vertex program. Could these somehow be interfering with the shadowed texture? Is there some special way that I need to blend this?

Thanks

dorbie
07-27-2003, 08:52 PM
OK, based on experience this still looks like a problem with the depth shadow test. It's very strange that you'd get this with front face culling when drawing the shadow map. Perhaps there's a format incompatibility of some sort and we're seeing some kind of LSB overflow.

Very strange.

Do you touch the depth fragment out in the bump map shader?

[This message has been edited by dorbie (edited 07-27-2003).]

MrRolf
07-27-2003, 09:06 PM
I'm using VP1.0. I touch/use OPOS, HPOS, NRML, TEX0, TEX1, TEX2 C[0-5], R0-R3.

If I disable the VP, the shadow texture works fine. So I assume somewhere in the VP I'm messing up. Where in those varibles could the depth component be?

MrRolf
07-27-2003, 09:29 PM
I think I know where the problem is now (thanks dorbie). In the VP I do:
DP4 o[HPOS].x, c[0], v[OPOS];
DP4 o[HPOS].y, c[1], v[OPOS];
DP4 o[HPOS].z, c[2], v[OPOS];
DP4 o[HPOS].w, c[3], v[OPOS];

This is computing the resulting vertex position. Maybe the precision or rounding is off and it's giving me the depthmap problems. Now the hard part.. how to correct/compensate for this.

harsman
07-28-2003, 01:56 AM
You're aware that vertex programs aren't invariant with fixed function transforms, right? If you do multiple passes and need the vertex program depth to be invariant with the fixed function depth use the position invariant option (se ARB_vertex_program specs).

Mazy
07-28-2003, 02:45 AM
That code looks like NV vertex program, then iirc you set the invariant opption with a glCall instead of writing it into the program.

But if you dont make anything special for NV i suggest you take a look at ARB_vertex_program, then the programs works on ATI cards as well.

MrRolf
07-28-2003, 03:57 AM
I just assumed the position would be the same. After putting in the NV_position_invariant option (and taking out the DP4) it works fine.

Thanks to all that helped out!

Mazy: I'll look into converting the program to be non NV specific.