Linearize Depth

April 16, 2007 at 2:55 am (Tips & Tricks)

I was just working on something in which I needed linearized depth values. I couldn’t remember how to do this off of the top of my head. Turns out you just take into account w, which makes complete sense now that I’ve seen it (doesn’t it always work that way?):

float4 vPos = mul(Input.Pos,worldViewProj);
vPos.z = vPos.z * vPos.w / Far;
Output.Pos = vPos;

This was poached from Robert Dunlop’s page

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: