Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / Problem with projective texturing Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
Opioid

March 27, 2005, 07:35 AM

Hello.
I want to use projective texturing to create a spotlight-like effect.
In my test I project from the camera.pos in the direction the camera is facing.
I expect the "spot" exactly in the middle of the screen. But that is not what happens. Depending on wether I use RH or LH matrices or a combination of the two , the spot will appear to the left/right/above/under the middle of the screen.
Apart from that the spot follows the movement of the camera.
I hope I am making myself clear. Any ideas?
Here's some code:

  1.  
  2. cVector3f LookAt = g_Camera.GetPos() + g_Camera.GetViewAxis();
  3.  
  4. D3DXMATRIX LightView, LightProj;
  5. D3DXMatrixLookAtLH(&LightView, &g_Camera.GetPos(), &LookAt, &g_Camera.GetUpAxis());
  6.    
  7. D3DXMatrixPerspectiveFovLH(&LightProj, D3DXToRadian(45.0f), 1.0f, 1.0f, 25.0f);
  8.  
  9. D3DXMATRIX LightViewProj = World * LightView * LightProj;
  10. pD3DXEffect->SetMatrix("g_TexTransform", &LightViewProj);
  11.  
  12. //In the vertex shader
  13. Out.ProjCoord = mul(float4(In.Pos, 1.0f), g_TexTransform);
  14.  
  15. //In the pixel shader
  16. float3 Spot = tex2Dproj(SpotMap, In.ProjCoord).rgb;
  17. //multiply with rest of lighting stuff
  18.  

Thanks for the help.

 
Nico

March 27, 2005, 09:03 AM

When you do projective texturing without vertex/fragment programs, you have to scale your final texcoords by .5 and add .5 to them to transform them from [-1, 1] range (projective space) to [0, 1] (texture space) by multiplying a scale and a translation matrix with LightViewProj. I don't know if tex2Dproj() does this for you already, though.

 
Opioid

March 27, 2005, 09:57 AM

Scaling the texcoords did not change anyting, unfortunately. Thanks.
Hmm, what is to be done?

 
Kain1956

March 27, 2005, 02:34 PM

It sounds like you did not multiple the matrix by a .5 bias in x and y.

 
Opioid

March 28, 2005, 04:20 AM

Yes, that might be the problem. Could you show me how such a bias Matrix would look like? Thanks.

Well, this is what I do now and it seems to work.

  1.  
  2. D3DXMATRIX Bias(0.5, 0.0, 0.0, 0.0,
  3.                 0.0, -0.5, 0.0, 0.0,
  4.                 0.0, 0.0, 0.0, 0.0,
  5.                 0.5, 0.5, 0.0, 1.0);
  6.  

 
This thread contains 5 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.