Jump to content

View more

Image of the Day

Adding some finishing touches...
Follow us for more
#screenshotsaturday #indiedev... by #MakeGoodGames https://t.co/Otbwywbm3a
IOTD | Top Screenshots

The latest, straight to your Inbox.

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


Sign up now

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

4: Adsense

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.


  • You cannot reply to this topic
8 replies to this topic

#1 Code-R   Members   

136
Like
0Likes
Like

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?

#2 Dave   Members   

2180
Like
0Likes
Like

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

#3 smitty1276   Members   

560
Like
0Likes
Like

Posted 11 March 2006 - 04:57 PM

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



#4 Dave   Members   

2180
Like
0Likes
Like

Posted 11 March 2006 - 04:58 PM

Is it??

How the hell can i not know that lol!


#5 Xai   Members   

1822
Like
0Likes
Like

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.

#6 smitty1276   Members   

560
Like
0Likes
Like

Posted 11 March 2006 - 05:07 PM

Hmm... this snippet
Quote:

The 1/Z buffer

The mapping equation ain't linear anymore:

Z buffer = ( 1/Z - 1/nearZ ) / ( 1/farZ - 1/nearZ )



...came from this page: http://www.gamedev.net/reference/articles/article673.asp

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.



#7 ury   Members   

476
Like
0Likes
Like

Posted 11 March 2006 - 08:59 PM

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

where:
z = your z-buffer value
a = farZ/nearZ

#8 Anonymous Poster_Anonymous Poster_*   Guests   

0Likes

Posted 13 March 2006 - 06:42 PM

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

#9 revel8n   Members   

205
Like
0Likes
Like

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.