Generally speaking, when there was a need to project screen space coords to world space coords, we were forced to do this by utilising
glReadPixel - after the rendering part was done
glUnproject - with the Z value from glReadPixel
I have my own glUnproject method that is utilising the matrices instead of calling OpenGL - it works great, but as usual i need to pass a Z (depth) value i am currently picking .
I have a perspective projection, my terrain can be rotated and is visible from above but not constantly, it can be zoomed to but you never see the horizon ( see the vid below )
[media]
[/media]
It is time to implement terrain mesh editing stuff into the engine and here comes the trouble - is there any way i can calculate that Z value without calling glReadPixel ?
I mean are we stuck with it or there is something else i can do to calculate it without reading from depth buffer?
Having 'constant' Z value passed to my unproject method isn't a good idea, especially that it isn't that precise as you can see below:
[media]
[/media]
Any other approach or i should go with glReadPixel and there's nothing i can do - which means, everybody uses this method.
As my scene is not yet fully detailed it might sound reasonable to use glReadPixel - but i am afraid of the consequences later on when i'll use several FBOs / with or without depth buffers attached..
Any suggestions?