Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (775)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [Solved]Calculating Depth Values  (Read 2566 times)
0 Members and 1 Guest are viewing this topic.
Offline JESTERRRRRR
« Posted 2017-01-30 21:46:41 »

When it comes to the depth buffer, this website is often linked to me: https://www.sjbaker.org/steve/omniv/love_your_z_buffer.html

It contains a Z calculator, for which you can input your Far and Near plane values, the Z distance for this fragment (in between the 2), the number of bits, and it calculates a result.

I am hoping someone can confirm I'm understanding them correctly before I start using them - if I put in Z distance = 1000, with far also = 1000, I get 16777215
With 1<<24 (from the formula) =  16777216, does this mean to get correct values I just have to normalize to get them into the 0-1 range?


I ask as I want to load a texture and use that as a sort of pre-computed depth buffer.

EDIT: well it seems they are calculating them as relative to the max, so simple to normalize.
Offline theagentd
« Reply #1 - Posted 2017-01-31 10:34:27 »

That's not how all depth values are calculated.

With orthographic projection, the depth values are indeed linearly distributed. For a given Z-value, it's a simple matter of calculating (Z-min)/(max-min) * 2^depthBits, where depthBits is 24 in your case. If you're using OpenGL, you should just load the 0.0-1.0 float to the depth buffer, as OpenGL will do the quantizing to 16/24/32 bits for you.

With perspective projection, the depth precision is not linearly distributed. They're essentially logarithmically distributed over the view frustum, giving significantly more precision near the camera and much lower precision far away.


Myomyomyo.
Offline JESTERRRRRR
« Reply #2 - Posted 2017-01-31 20:13:07 »

The formula I am using from the website is

(1 << N) * (a + b / z)

a = (zFar/(zFar-zNear))
b/z = (zFar * zNear / (zNear - zFar))/z

The results are non-linear, just it gives me values between 0 and 2^24 (provided I put in 24 bit), so 16777216

The thing is I want to calculate them in Blender using math nodes
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #3 - Posted 2017-01-31 23:39:39 »

Ah, ok. Yeah, that formula looks correct.

Myomyomyo.
Offline JESTERRRRRR
« Reply #4 - Posted 2017-02-01 06:25:43 »

Cool, thanks. I guess ultimately I'll find out when everything runs - it's usually always a disaster first time anyway Tongue
Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (45 views)
2018-11-16 13:46:03

hadezbladez (50 views)
2018-11-16 13:41:33

hadezbladez (29 views)
2018-11-16 13:35:35

hadezbladez (20 views)
2018-11-16 13:32:03

EgonOlsen (1900 views)
2018-06-10 19:43:48

EgonOlsen (1936 views)
2018-06-10 19:43:44

EgonOlsen (1286 views)
2018-06-10 19:43:20

DesertCoockie (1718 views)
2018-05-13 18:23:11

nelsongames (1412 views)
2018-04-24 18:15:36

nelsongames (2043 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!