any linear alg/opengl experts can just tell me how to do this?

if i have screen coords and world y, how can i calculate a z-buffer value? (assuming an orthographic view matrix)?

I'm doing an experiment in 2.5d with prerendered backgrounds and can't pre-calculate depth values, but I can easily access world-y.

· · Web · 1 · 0 · 0

@kelseyfrog IIRC for orthographic cameras the math just linearly maps the z coordinate between near/far planes onto (-1, 1). For perspective cameras it's sort of a 1/x curve? So you lose precision near the far plane and can get z-fighting.

Also, I'm probably misunderstanding what you're doing here, but... usually the camera transforms world-space vectors into the -1,+1 cube that gets drawn (Normalized Device Coordinates: NDC?) and then the depth buffer is set and/or tested based on the z-coordinate of each point on the triangle. a pixel shader you can set the color or discard the pixel entirely, but you can't move it around, in z or any of the other axes.

So I don't understand how you're even able to calculate and write a z-buffer value? Are you writing a height map in a separate pass? Or am I just out of date on opengl?

Sign in to participate in the conversation
Frog Camp

Just a place for frogs on the internet