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
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);
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: