View Full Version : weird problem concerning pbuffer and projective texture

07-25-2004, 12:38 AM
Hi all:
I'm working on a water rendering demo which needs projective texturing. Let me first explain my program window layout:
section 1 has no use for now.
section 2 is a preview shot of pbuffer1(including the black region)
section 3 is a preview shot of pbuffer2(also including the black region)
section 4 has a quad in it, to which I want to project pbuffer1 or pbuffer2's content.
My problem is that once I project the texture generated from pbuffer, section 4 is completely messed up, it looks like this:

Only if I move very close to the quad can I get the content of pbuffer, but it's still distorted:

But if I use a texture read from HD file, it looks correct:

I've checked the projective texcoord, seems no problem at all(s in red channel, t in green channel):

Does anyone know what causes the artifacts on pbuffer generated texture?

07-25-2004, 02:28 PM
Originally posted by 991060:
Looks like a mipmapping issue. Are you allocating mipmaps, but never rendering to them, or never turn SGIS_GENERATE_MIPMAPS on?

07-25-2004, 05:27 PM
yeah, you're right humus, it's the mipmapping issue.
Now here's another problem, it seems there's sth wrong with my texcoord calculation. The generated texcoord should never exceed [0,1], but:

This is how I did the projective texturing:

in vertex program:
OUT.refractionCoord = mul(MVP, v) * 0.5 + 0.5;
in fragment program:
OUT.color = tex2Dproj(refractionTex, IN.refractionCoord );
tex2Dproj is a Cg macro, which is equal to:
float2 texcoord = float2(IN.refractionCoord.x, IN.refractionCoord.y)/IN.refractionCoord.w;
OUT.color = tex2D(refractionTex, texcoord);
And this is the visulization of s in red channel and t in green channel:

07-26-2004, 12:50 AM
When you do *0.5 + 0.5, are you doing that to all components? If so, then the effect of *0.5 goes away since you're also dividing with half as big value. The fastest way to do the scale and bias thing is like this:

vec4 sPos = MVP * pos;
oProjCoord = sPos.xyz + sPos.zzz;