hi.
i’ve tried to read the pixel value(into a texture),
when I perform my pixel shader.I would want read this value in the same coords where the pixel shader is executed.
I make it in this way:
Vertex-Frogram ------
struct Out{
float4 HPOS : POSITION;
float2 LookUp : TEXCOORD0;
};
Temp=mul(ModelViewProj,IN.position_main)
Temp.x=Temp.x/Temp.z;
Temp.y=Temp.y/Temp.z;
Out.LookUp.x=(Temp.x*0.5+0.5)640;
Out.LookUp.y=(Temp.y0.5+0.5)*480;
Fragment Program -----
struct Inputs{
float4 HPOS : POSITION;
float2 LookUp : TEXCOORD0;
};
struct Outputs{
float4 Color : COLOR;
};
Out main(uniform sampler2D Texure)
{
Out.Color=tex2D(Texure,LookUp.xy);
};
is this the correct way to perform this task?
thanks in advance Sandro
Hello,
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.
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).
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
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.