Quote:

Thanks Rigoletto (you must excuse because thats the first shader I'm triing to program and it's very hard to learn with my bad english )

So here is my 2nd try

<code omitted>

Now I get an error with the position in the vs and i can't understand why.





You need to do just that, write out the position coordinates.

Code:
 material material_test
{
effect
"
float4x4 matWorldViewProj;
texture entSkin1;

sampler ScreenProjSampler = sampler_state
{
texture = <entSkin1>;
magfilter = LINEAR;
minfilter = LINEAR;
mipfilter = LINEAR;
};

struct VS_OUT
{
float4 pos : POSITION;
float3 tex0 : TEXCOORD0;
};

VS_OUT mainVS(float4 Pos : POSITION0)
{
VS_OUT outStruct;
outStruct.pos = mul(Pos,matWorldViewProj);
float4 toScreen = mul(float4(Pos.xyz,1),matWorldViewProj);
outStruct.tex0.x = 0.5f * (toScreen.z+toScreen.x);
outStruct.tex0.y = 0.5f * (toScreen.z-toScreen.y);
outStruct.tex0.z = 1.0f * toScreen.w;

return outStruct;
}

float4 mainPS(float3 tex0 : TEXCOORD0) : COLOR0
{
float2 screenCoords;
screenCoords.x = tex0.x/tex0.z;
screenCoords.y = tex0.y/tex0.z;
float4 ScreenSpaceSample = tex2D(ScreenProjSampler,screenCoords.xy);

return ScreenSpaceSample;
}

technique test
{
pass p0
{
VertexShader = compile vs_2_0 mainVS();
PixelShader = compile ps_2_0 mainPS();
}

}
";
}



This shader however, transforms the texture to be displayed flat on a 3d object, not flatten out the polys of a 3d object (alike to a sprite) and face it to the camera, that would be a bit different.

-Rhuarc


I no longer post on these forums, keep in touch with me via:
Linkedin.com
My MSDN blog