🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Screen space view positions in orthographic camera

Started by
1 comment, last by hplus0603 3 years ago

I have a depth texture and I'm trying to output the view space positions on the screen.

I'm using an orthographic camera. as you see there is a plane and a red mesh, what I get is a quad and I don't see the vertices in view positions in color.

here is the result

enter image description here
float3 position_in_view_space(float2 uv)
{
    float z = depth_tex.SampleLevel(depth_sampler, uv, 0.0f).x;
    // Get x/w and y/w from the viewport position
    float x = uv.x * 2 - 1;
    float y = (1 - uv.y) * 2 - 1;
    float4 vProjectedPos = float4(x, y, z, 1.0f);
    // Transform by the inverse projection matrix
    float4 vPositionVS = mul(vProjectedPos, inv_proj);  
    // Divide by w to get the view-space position
    return vPositionVS.xyz / vPositionVS.w;  
    
}

float3 position_from =position_in_view_space(tex_coord.xy);
output.color = float4(position_from, 1.0);
return output;


Game Programming is the process of converting dead pictures to live ones .
Advertisement

You're seeing color clamping. The view space X position is much larger than 1 towards the right, and the view space Y position is much larger than 1 towards the bottom, so you get “red clamped to 1 on the right” and “green clamped to 1 towards the bottom.”

Also, to the left of center, you get values below 0, which clamp to 0, which ends up being black.

Figure out what viewspace-to-color scaling value you want to use, and apply it. Start with maybe 0.01 and go from there.

enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement