greggman / wgpu-matrix

Fast WebGPU 3d math library
https://wgpu-matrix.org
MIT License
312 stars 16 forks source link

Provide a reverse z perspective matrix function #29

Closed stefnotch closed 6 months ago

stefnotch commented 6 months ago

It would be amazing if this library included a variation of the perspective matrix function for reverse depth.

greggman commented 6 months ago

Which one?

stefnotch commented 6 months ago

Are there multiple choices?

(Other than right handed vs left handed)

greggman commented 6 months ago

apparently infinite z vs finite at least? can add both I guess. I actually haven't done much with reverse z although it seems better in every way.

stefnotch commented 6 months ago

How interesting, I wasn't even aware of finite reverse z. From what I can find online, having an infinite far plane with reverse z is the usual option? (There's only a tiny loss in precision compared to finite reverse z.)

greggman commented 6 months ago

added in 2.9.0

https://wgpu-matrix.org/docs/functions/mat4.perspectiveReverseZ.html

stefnotch commented 6 months ago

That's awesome, thank you very much!

greggman commented 6 months ago

(There's only a tiny loss in precision compared to finite reverse z.)

There's alays precision loss. There's only 32bits so 4 billion values. If you're drawing atoms, 4 billion atoms is not that far. If you're drawing stars it's much further.