ok thanks .. it works....

but now my next problem:

the projected picture must be smaller in the near than in the far distance like a flashlight.
how can i solve this problem?

screenshot:


the code:
Code:
 

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

float4x4 matWorldViewProj;
float4x4 matMtl;

struct VS_OUTPUT
{
float4 Pos : POSITION;
float2 texCoord : TEXCOORD0;
float3 lightVec : TEXCOORD1;
};

VS_OUTPUT mainVS( float4 Pos : POSITION, float2 texCoord : TEXCOORD0 )
{
VS_OUTPUT Out = (VS_OUTPUT) 0;

Out.Pos = mul(Pos, matWorldViewProj);

float2 tps = (mul(Pos, matMtl) * 0.005f) + 0.5f; // ? und korrektur der position des projizierten bildes

Out.texCoord = tps;
Out.lightVec.xy = texCoord.xy;

return Out;
}

texture entSkin1;
texture mtlSkin1;

sampler BaseTex = sampler_state
{
Texture = <entSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = wrap;
AddressV = wrap;
};

sampler ProjTex = sampler_state
{
Texture = <mtlSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = clamp;
AddressV = clamp;
};

float4 mainPS(float2 texCoord : TEXCOORD0, float2 lightVec : TEXCOORD1 ) : COLOR
{
float4 base = tex2D( BaseTex, lightVec );
float4 proj = tex2D( ProjTex, texCoord ) * 4;

return (base + 0.1 * proj);
}

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

technique fallback { pass one { } }