   HLSL Projective Texture Artifact
  Hi there I am very-fairly new to HLSL and have been studying techniques alot for DirectX9. I have been looking at some example code for HLSL projective texturing but am getting an artifact with which I am unsure of how to approach at all.I have modified a projective texture piece of code to operate from a look at matrix seperate from the camera and adjusted the falloff to work relative to the central point of the projective texture. However the inverse of the texture is projected out of the back of the point from which the image is projected. There is a (doorway of light affect) which looks like an artifact of the textures orientation when being prepared to be projected onto the wall as its being projected in the direction of all the walls from its origin, as if the image was too big to fit into the box/room and as such has intersected with the colours of the wall.Heres a photo to clarify. Here is the shader so you have a chance at explaining the phenomenon.float4x4 WorldViewProj; //World * View * Projectionfloat4x4 World;    //Worldfloat4x4 TexTransform;  //Texture transformation matrixfloat3 ProjectorPos;    //World position of the projection matrixfloat Ambient = 0.1f;   //Amount of ambient lightfloat LightFalloff;//Range of the lighttexture LightTex;texture ColorTex;//Must be clamped so the light texture shows up only oncesampler LightTexSampler = sampler_state{    Texture = <LightTex>;    MinFilter = LINEAR; MagFilter = LINEAR;    MipFilter = LINEAR;    AddressU  = Clamp;    AddressV  = Clamp;};sampler ColorTexSampler = sampler_state{    Texture = <ColorTex>;    MinFilter = LINEAR; MagFilter = LINEAR;    MipFilter = LINEAR;    AddressU  = Wrap;    AddressV  = Wrap;};////////////////////////////////////////////////////////////// Structures////////////////////////////////////////////////////////////struct MainA2V{    float4 Position : POSITION;    float2 TexCoord0 : TEXCOORD0;};struct MainV2P{    float4 Position  : POSITION;    float2 TexCoord0 : TEXCOORD0;    float4 TexCoord1 : TEXCOORD1;    float3 LightVec  : TEXCOORD2;};////////////////////////////////////////////////////////////// Vertex Shaders////////////////////////////////////////////////////////////void MainVS(in MainA2V IN, out MainV2P OUT){    //Copy color texture coordinates through    OUT.TexCoord0 = IN.TexCoord0;   //First two are the projected texture coordinates    OUT.TexCoord1 = mul(IN.Position, TexTransform);   //Position to light vector    OUT.LightVec = mul(IN.Position.xyz, (float3x3)World) - ProjectorPos;   //Transform model-space vertex position to screen space:    OUT.Position = mul(IN.Position, WorldViewProj);}////////////////////////////////////////////////////////////// Pixel Shader////////////////////////////////////////////////////////////float4 MainPS(in MainV2P IN) : COLOR {    //Read in values for light texture and color texture    float4 Color    = tex2D(ColorTexSampler, IN.TexCoord0);    float4 Light    = tex2Dproj(LightTexSampler, IN.TexCoord1);   //Squared distance from pixel to light    float LenSq = dot(IN.LightVec, IN.LightVec);  //Find the attenuation    float Attn = min(( LightFalloff * LightFalloff ) / LenSq, 1.0f);   //Compute lighting amount    float4 I = (Light * Attn) + Ambient;   //Color of texture * lighting amount    return Color * I;}////////////////////////////////////////////////////////////// Techniques////////////////////////////////////////////////////////////technique ProjectiveTexture{    pass P0    {   VertexShader = compile vs_2_0 MainVS();   PixelShader = compile ps_2_0 MainPS();    }}Here is c++ code relevant to the HLSL effect.//Set the world matrixD3DXMATRIX World;D3DXMatrixIdentity(&World);//Set the texture adjustment matrix offsetsfloat XOffset = 0.5f + (0.5f / (float)256); //Width of the light texturefloat YOffset = 0.5f + (0.5f / (float)256); //Height of the light texture//Create the texture adjustment matrixD3DXMATRIX TexMatrix;ZeroMemory(&TexMatrix, sizeof(D3DXMATRIX));TexMatrix._11 = 0.5f;TexMatrix._22 = -0.5f;TexMatrix._33 = 0.5f;TexMatrix._41 = XOffset;TexMatrix._42 = YOffset;TexMatrix._43 = 0.5f;TexMatrix._44 = 1.0f;//Create the projection matrix for the lightD3DXMATRIX LightProj;D3DXMatrixPerspectiveFovLH( &LightProj, D3DX_PI/4, 1.0f, 0.0f, 250.0f);D3DXMATRIX projectionM;D3DXMatrixLookAtLH(&projectionM, &D3DXVECTOR3(0,8,0),&D3DXVECTOR3(40,8,20), &D3DXVECTOR3(0,1,0));//Set dynamic shader variablesProjTextureEffect->SetTechnique( "ProjectiveTexture" );ProjTextureEffect->SetMatrix( "WorldViewProj", &(World * ActiveCamera->View * Proj) );ProjTextureEffect->SetMatrix( "World", &(World) );ProjTextureEffect->SetMatrix( "TexTransform", &(World * projectionM * LightProj * TexMatrix) );ProjTextureEffect->SetValue( "ProjectorPos", &(projectionM), sizeof(D3DXVECTOR3));ProjTextureEffect->SetTexture( "ColorTex", RoomTexture );ProjTextureEffect->SetTexture( "LightTex", LightTexture );ProjTextureEffect->SetFloat( "LightFalloff", 35.0f );I am not sure how to approach the issue I have tampered with the texture matrix to get a better grip on its operation as theres no real documentation on it but have not found any problems there. The inversion makes sense and probably requires some more concise selection in the HLSL which will involve passing in another value to it although I am unsure of if a fix can be done via a more simple means. The flat projection around the middle of the room is something I am unsure of even when it comes to a cause.Anyone with HLSL knowledge that can clarify what I should try doing would be greatly appreciated :)(Modified because I had run on sentences and spelling mistakes due to fatigue)[Edited by - EnlightenedOne on August 6, 2010 5:20:13 PM]
  Ok I cracked one issue! The unusual doorway effect was me not using border in the .fx file Clamp made the edges expand into infinity along the axis the matrix projected out from, that is now sorted. Has no one a clue of how to make the projection be projected out in one direction? I am hopeful its a sample state issue so I will keep tampering. I am worried this is the wrong section to post this in maybe. [Edited by - EnlightenedOne on August 4, 2010 3:39:38 PM];  Can a Dev move this to graphics programming please? Thanks!   ;  Cracked it thanks to this bit of help on doing if statements in HLSLhttp://www.gamedev.net/community/forums/topic.asp?topic_id=578937AND thanks to this invaluable little gem on projective texturing google helped me find that identified and resolved my problem in one go!http://www2.imm.dtu.dk/visiondag/VD03/grafisk/WolfgangEngel.pdfI had underestimated the flexibility of shaders, lots of coding to do now!Goodluck to anyone slightly behind me who hit this problem!   