1

I need to make spherical billboards (i.e., setting depth), but taking into account perspective projection--ideally including off-center frusta.

I wasn't able to find any references to anyone succeeding at this--although there are plenty of explanations as to why standard billboards don't have perspective distortions. Unfortunately, for my application, the lack isn't a cosmetic defect; it's actually important to the algorithm.

I did a bit of investigation on my own:

The math gets pretty messy rather quickly. The obvious approaches don't work: for example, you can't orient the billboard perpendicular to a viewing ray because tangential rays wouldn't intersect the billboard at right angles.

Probably the most promising approach I found was to render the billboard parallel to the near clipping plane, stretching it with a vertex shader into an ellipse. This only handles perturbations along one axis (so e.g. it won't handle spheres rendered in a corner of the view), but the main obstacle is calculating depth correctly; you can't compute it as you would for an undistorted sphere because the "sphere" is occluding itself.

Point of fact, I didn't find a good solution, and I couldn't find anyone who has. Anyone have an idea?

Community
  • 1
  • 1
geometrian
  • 14,775
  • 10
  • 56
  • 132
  • I don't get your question completely. An obvious approach is to map the content as a texture onto a sphere to be rendered. Or do you want to do the trick in pure 2D ? –  Jan 22 '14 at 08:29
  • This needs to be purely 2D. The problem is deliberately introducing perspective distortion near edges. – geometrian Feb 02 '14 at 06:11
  • There are different ways of achieving a distortion effect. One being to map a rectangle onto a sphere and project it to the screen using true projection equations. The equations will transform 2D spherical coordinates to 3D Cartesian, then 3D Cartesian to 2D Cartesian and yield a realistic effect. Other approaches are to define arbitrary deformations with a "sphere-like" effect (working in polar coordinates could ease that). But actually what you are looking for is unclear. Could you rephrase ? –  Feb 02 '14 at 10:19
  • It _must_ be a genuine billboard: four vertices, generated by geometry shader. In the fragment shader, I need to (set the fragment depth)/(discard as required) so as to make the billboard appear to be a 3D sphere. – geometrian Feb 02 '14 at 21:53
  • Still unclear. I Need a drawing to understand. –  Feb 03 '14 at 07:40

1 Answers1

2

While browsing around not even remotely working on this problem, I stumbled on http://iquilezles.org/www/articles/sphereproj/sphereproj.htm, which is pretty close. The linked tutorial shows how to compute a bounding ellipse for a rasterized sphere; getting the depth (at worst, using a raycast) should be fairly easy to derive.

geometrian
  • 14,775
  • 10
  • 56
  • 132