What's new

SetPrimDepth

Dave2001

Moderator
We're trying to translate SetPrimDepth z into a z value that we can use like any other vertex's z.

According to docs, SetPrimDepth uses the following equation, with screenZ the value input to SetPrimDepth:
screenZ=(z/w)*0x3fe0 + 0x3fe0

This is kind of a hard question to ask, but we need to know sooo much more about how this equation works.

I believe the place to start is what exactly does w represent for SetPrimDepth? Or does z even represent the z we're trying to find?

[edited to make question much shorter & less history ;)]
 
Last edited:

Gonetz

Plugin Developer (GlideN64)
ok, i think i found solution.

we have screenZ, from above formula we get
z/w = (screenZ-0x3fe0)/0x3fe0, so we know z/w

z = vertex_z*projection[2][2] + projection[3][2]

w = vertex_z*projection[2][3] + projection[3][3]

projection[2][3] usually -1 and projection[3][3] is 0. we use such projection matrix for calculation near and far clipping planes.
so,

w = -vertex_z =>

vertex_z = - (projection[3][2])/(projection[2][2]+z/w)

desired z = w = -vertex_z

DukeNukem64 works correct with this z, hurrah!
 
OP
Dave2001

Dave2001

Moderator
Hmm, that solution seems to work fine with Duke Nukem 64, but Extreme-G 2, with the sky triangle covering the whole screen, gets a z value of 0 with z update enabled...

Good job though :)
 
Last edited:

Top