Hand-made fake 3D - problems with rendering
Posted: Thu Feb 18, 2021 9:33 pm
Hello to everybody.
I'm new here, but not so new to Löve.
I recently watched Top Gun so I decided to create something inspired to the old arcade Afterburner with its nice fake 3D.
I've been exploring 3D libraries for Löve, but in the end I decided that I don't want a true 3D environment. I want to retain all the Löve 2D goodness. Being more specific I want to know exactly where pixels are drawn in my window.
This is what I'm doing:
* I use groverburger's G3D matrix functions in order to create the matrices I need (view, projection, model)
* I define geometry in terms of x y z, within the usual bounds of -1, 1 etc.
* therefore I multiply the matrices and the vertices, obtaining a transformed point
* I convert this point to 2D coordinates by dividing by W and remapping to 2D coords
It's like I'm emulating a GPU.
So far, so good: it works.
A problem arise when I have a point that, when transformed by the matrices, get a negative Z. After a certain threshold the "rasterisation" fails, and the point is sent to the other side of the screen, screwing the rendering.
I've tried to put together a single file showcasing the whole contraption, with a 3D grid rendered on screen. I print on screen the coords of the bottom right point of the grid: untransformed, then transformed and finally converted to 2D.
Pressing L and K the camera is rotated on the Y axis.
When doing the same thing with G3D proper, obviously the GPU does the right thing...
I'd like to know if someone has a clue on why this error happens.
Thanks in advance
Carotino
I'm new here, but not so new to Löve.
I recently watched Top Gun so I decided to create something inspired to the old arcade Afterburner with its nice fake 3D.
I've been exploring 3D libraries for Löve, but in the end I decided that I don't want a true 3D environment. I want to retain all the Löve 2D goodness. Being more specific I want to know exactly where pixels are drawn in my window.
This is what I'm doing:
* I use groverburger's G3D matrix functions in order to create the matrices I need (view, projection, model)
* I define geometry in terms of x y z, within the usual bounds of -1, 1 etc.
* therefore I multiply the matrices and the vertices, obtaining a transformed point
* I convert this point to 2D coordinates by dividing by W and remapping to 2D coords
It's like I'm emulating a GPU.
So far, so good: it works.
A problem arise when I have a point that, when transformed by the matrices, get a negative Z. After a certain threshold the "rasterisation" fails, and the point is sent to the other side of the screen, screwing the rendering.
I've tried to put together a single file showcasing the whole contraption, with a 3D grid rendered on screen. I print on screen the coords of the bottom right point of the grid: untransformed, then transformed and finally converted to 2D.
Pressing L and K the camera is rotated on the Y axis.
When doing the same thing with G3D proper, obviously the GPU does the right thing...
I'd like to know if someone has a clue on why this error happens.
Thanks in advance
Carotino