OK It works, but I have a problem ... The projected image is distorted on the edges.

How can I solve this problem?

screeny:


my code:

Code:

//--------------------------------------------------------------
// Texture Projection Shader HLSL
//
// © by zSteam
//
// date: 19.10.2007
// -------------------------------------------------------------

float4x4 matWorldViewProj;
float4x4 matMtl;

struct VS_OUTPUT
{
float4 oPos : POSITION;
float2 oTex0 : TEXCOORD0;
float2 oTex1 : TEXCOORD1;
};

VS_OUTPUT mainVS( float4 Pos : POSITION, float2 Tex : TEXCOORD0 )
{
float2 tps;

VS_OUTPUT Out = (VS_OUTPUT) 0;

Out.oPos = mul(Pos, matWorldViewProj);

tps = mul(Pos, matMtl) * 0.01f;
tps = (tps * 0.5f) + 0.5f;

Out.oTex0.xy = tps.xy;
Out.oTex1.xy = Tex.xy;

return Out;
}

texture entSkin1;
texture mtlSkin1;

sampler ColorMapSampler = sampler_state
{
Texture = <entSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};

sampler ProjTex = sampler_state
{
Texture = <mtlSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = Clamp; // don't wrap around edges
AddressV = Clamp; // don't wrap around edges
};

float4 mainPS(float2 Tex0 : TEXCOORD0, float2 Tex1 : TEXCOORD1 ) : COLOR
{
float4 base = tex2D(ColorMapSampler, Tex1);
float4 proj = tex2D(ProjTex, Tex0)*4;

return (base*proj);
}

technique projector
{
pass p1
{
VertexShader = compile vs_1_1 mainVS();
PixelShader = compile ps_1_1 mainPS();
}
}

technique fallback { pass one { } }