Jump to content
  • Advertisement
Sign in to follow this  
deks

Deffered lighting

This topic is 4949 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'm trying to only store the distance of the pixel in view space to save render target space, and I have some problems constructing back the pixel view space coordinate. In the following picture, you can see on the left the reconstructed view space position, and on the right the original view space coordinates: The pixel shader looks like this:
float4 PixelShader(const VS_OUTPUT v) : COLOR
{
    float3 screenpos = float3(v.texcoord.x * 2.0f - 1.0f, (1.0f - v.texcoord.y) * 2.0f - 1.0f, 1.0f);
    float tanfov_x = tan(90.0f * 0.5f) * (screenpos.x) / fAspectRatio;
    float tanfov_y = tan(90.0f * 0.5f) * (screenpos.y);
    float screenpos_dist = tex2D(Texture, v.texcoord).r; // Stored viewspace distance
    float3 viewspace_pos = float3(tanfov_x * screenpos_dist, tanfov_y * screenpos_dist, screenpos_dist);
    
    return float4(viewspace_pos, 1);
}



As you can see from the code, texture coordinates are scaled to be in the [-1..1], then I construct the view space ray with the distance stored before in the deferred rendering phase. Anything wrong? =[dEkS]=

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!