Jump to content
  • Advertisement
Sign in to follow this  
dhanji

HLSL texture sampling

This topic is 5392 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!