HLSL texture sampling

Started by
-1 comments, last by dhanji 19 years, 6 months ago
Hi I am trying to figure out how to sample my shadow mask in the pixelshader. My problem is generating texture coordinates that apply correctly to the shadow mask. here's my procedure: -Render scene of casters to shadow mask from light's view -Save Light's VP matrix -Render scene from camera's view, projecting each pixel using the saved Light VP -Use the projected pixel xy to sample the shadow mask texture my problem is converting the projected pixel into texture coordinates. Currently the scene shadow is offset and thus appears incorrect. Here is the address shader which calculates the texture coordinates:

  //transform position and calculate pixel depth
    float4 tPos = mul( float4(InPos, 1), World );

    //project pixel into appropriate light-plane
    tPos = mul(tPos, LightViewProjection);
    Out.TextureUV.xy = tPos.xy * (-1) ;
    
    //clamp to prevent wrapped samples
    Out.TextureUV = saturate(Out.TextureUV);
    
    //calculate pixel position for camera
    float3 Pos = mul( float4(InPos, 1), (float4x3)World );
    Out.Pos = mul(float4(Pos,1), ViewProjection);

And based on whether or not there is a colored texel sampled I shade the pixel lit or unlit. I guess what Im really asking is how to convert from the output position from a WVP transform to 0..1 texture coordinate space. I have tried dividing by the viewport width and height (Projection._11 and Projection._22) but this just shifts my projected shadow to a different (more erroneous) position. Any help? PS: Also can u tell me how to figure out what the first pixel (top left) and the last pixel (bottom right) to the backbuffer is in Out.Pos.x,y? If I knew that I could shade my texture coordinates manually.
________________
"I'm starting to think that maybe it's wrong to put someone who thinks they're a Vietnamese prostitute on a bull"       -- Stan from South Park
Lab74 Entertainment | Project Razor Online: the Future of Racing (flashsite preview)

This topic is closed to new replies.

Advertisement