PDA

View Full Version : weird problem concerning pbuffer and projective texture



991060
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:
|1|2|
|3|4|
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:
http://img23.exs.cx/img23/976/Clip3.jpg

Only if I move very close to the quad can I get the content of pbuffer, but it's still distorted:
http://img22.exs.cx/img22/9636/Clip_2.jpg

But if I use a texture read from HD file, it looks correct:
http://img22.exs.cx/img22/7598/Clip_4.jpg

I've checked the projective texcoord, seems no problem at all(s in red channel, t in green channel):
http://img22.exs.cx/img22/9829/Clip_3.jpg

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

Humus
07-25-2004, 02:28 PM
Originally posted by 991060:
http://img22.exs.cx/img22/9636/Clip_2.jpg
Looks like a mipmapping issue. Are you allocating mipmaps, but never rendering to them, or never turn SGIS_GENERATE_MIPMAPS on?

991060
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:
http://img51.exs.cx/img51/3789/Clip_5.jpg

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:
http://img51.exs.cx/img51/6355/Clip_7.jpg

Humus
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;