Sign in to follow this  

Deffered lighting

This topic is 4730 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

This topic is 4730 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this