I have the same problem : I want to do a multipass rendering (front to back).

Thus I would like to read a texture (pbuffer) that represents the former pass while I am drawing some polygons.

And so I need to convert the fragment position to texture/screen coordinates.

I want to have the maximal performance so I do not want to perform this at the fragment level but at the vertex level:
- Vertex program converts position (after transformation) to texture coordinates for my screen aligned pbuffer.
- In the fragment program a "simple" TXP instruction performs the texture sampling.

I do not achieve this because I am mixing lots of matrices and I cannot figure out how to perform the convenient rescaling at the vertex level and to combine this with projective mapping.

Paul

PS I am still using fragment and vertex programs.

CoinCoin

07-07-2004, 12:29 PM

Hello,
You can get the current fragment coordinates in screen pixels, declaring a WPOS parameter directly in your fragment shader (however, this requires to run shader 2.0 or more, or this won't be available).

Sandruzzo

07-07-2004, 10:17 PM

i tryed to declare wpos,but doens't work.this is my shader

struct Inputs{
float4 HPOS : WPOS;
float3 Normal : TEXCOORD1;
};

Outputs main(Inputs IN,
uniform samplerRECT Buffer)
{
Outputs OUT;

OUT.Color=0.1f+texRECT(Buffer,IN.HPOS.xy);

}

is correct it?

thanks
sandro

Jared

07-07-2004, 10:37 PM

Originally posted by CoinCoin:
Hello,
You can get the current fragment coordinates in screen pixels, declaring a WPOS parameter directly in your fragment shader (however, this requires to run shader 2.0 or more, or this won't be available).dont know if this is any better in glsl (somehow i doubt it), but accessing the fragment position in a fragment program turned out to be slow as hell for me (so in fact storing the transformation result in a second attribute and calculating it myself was a ton faster).. might of course be completely different on nvidia hardware ,-)

CoinCoin

07-08-2004, 05:45 AM

Hello,
Accessing WPOS did not cause any perf issue, but I only did test that on NVidia hardware...
Sandruzzo, your texture sampling at the current pixel seems correct to me.