• FEATURED
• FEATURED
• FEATURED
• FEATURED
• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Converting Z-Buffer [0.0, 1.0] value to W-buffer linear [0.0,1.0] value

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

8 replies to this topic

### #1Code-R  Members

Posted 11 March 2006 - 03:40 PM

How can I convert a z-buffer value, read in a fragment shader, into a linear w-buffer-like value that varies LINEARLY from the near plane to the far plane?

### #2Dave  Members

Posted 11 March 2006 - 04:51 PM

If both ranges are the same, as in the thread title, then why do you have to do anything?

Dave

### #3smitty1276  Members

Posted 11 March 2006 - 04:57 PM

He wants a linear range. Z buffer is non linear.

### #4Dave  Members

Posted 11 March 2006 - 04:58 PM

Is it??

How the hell can i not know that lol!

### #5Xai  Members

Posted 11 March 2006 - 05:06 PM

I personally don't know 3D coding well so I don't know what the zbuffer is, but I have done many function conversion, you just apply the inverse of the range you have - sometimes with some pre and post domain adjustment to fit the piece of the curve you want / have.

For instance I have a slider class which generates a linear 0.0 to 1.0 range of values, and I convert it to an logrithmic 0.0 to 1.0 range of values for use as a volume (which is logrithmic to the ear) - the forula for that (in C#) is:

public static double Log(double input)
{
return System.Math.Log10(input * 9.0 + 1.0);
}

or you might need to go the other way:

public static double Exponential(double input)
{
return ((System.Math.Pow(input, 10) - 1.0) / 9.0);
}

obviously you will need to use C++ versions of the log and power functions if you are not in .NET (I assume you are not).

hope that gets you started.

### #6smitty1276  Members

Posted 11 March 2006 - 05:07 PM

Hmm... this snippet
Quote:
 The 1/Z bufferThe mapping equation ain't linear anymore: Z buffer = ( 1/Z - 1/nearZ ) / ( 1/farZ - 1/nearZ )

I, like Dave, had completely forgotten that the z-buffer was non-linear (until I read your post), let alone how it is calculated. If the above snippet is correct, then maybe you can solve for z and get what you are wanting.

### #7ury  Members

Posted 11 March 2006 - 08:59 PM

You could use:
f(z) = z/(a - (a-1)z),

where:
a = farZ/nearZ

### #8Anonymous Poster_Anonymous Poster_*  Guests

Posted 13 March 2006 - 06:42 PM

Why can't you use w itself by passing it to the pixel shader?

### #9revel8n  Members

Posted 14 March 2006 - 07:04 AM

http://www.mvps.org/directx/articles/linear_z/linearz.htm

Hope that helps.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.