Thread: [Algorithms] Keeping an object's label on the screen
Brought to you by:
vexxed72
|
From: Monteleone, N. <nat...@lm...> - 2009-04-29 18:29:04
|
I have to draw some billboard text over some shapes we've "painted" onto our terrain via multitexturing. Normally this is easy enough - just plop the label in an auto-rotated billboard and float it above the center of the geometry. But I need to keep the label on screen at all times if any part of the painted geometry is visible. I.e. if I have a square painted on the terrain, but I can only see a small corner of it, I still need to show the whole label. What's a good algorithm to figure out where to draw the label? The idea I had in mind was to do something in screen space... I'd write out an object ID version of the projected texture, apply it, render the terrain geometry into a low-res buffer, then compute min/max screen coords for each object. Then I could just draw my text label in screen space based on that information. Is this a sane approach? Otherwise I'd have to create a geometric representation of our shapes that conforms to the terrain and choose a 3d location for my text based on the view frustum. That seems painful to implement efficiently. Thanks, Nathan |
|
From: Jeff R. <je...@8m...> - 2009-04-29 18:43:37
|
*The idea I had in mind was to do something in screen space... I’d write out an object ID version of the projected texture, apply it, render the terrain geometry into a low-res buffer, then compute min/max screen coords for each object. Then I could just draw my text label in screen space based on that information. Is this a sane approach?* Could be, if your object counts are reasonably small. If this is just sections of the terrain we're talking about, and your terrain is at least sort of flat, you could just project the bounds of these shapes into screen space and center your label accordingly. -- -------------------------------------------- Jeff Russell Engineer, 8monkey Labs www.8monkeylabs.com -------------------------------------------- |
|
From: Jon W. <jw...@gm...> - 2009-04-29 18:56:06
|
Monteleone, Nathan wrote: > > What’s a good algorithm to figure out where to draw the label? > In general, this is easy, by projecting the desired location to screen space. However, you can get into situations where a corner is visible on the screen, but the center of the object is behind the camera, which may lead to poorly behaved labels. Just project the corners of the bounding box of the object to screen space; take the average of the corners that are in front of the camera, and project that to screen space. Form the rectangle around that, and clamp that rectangle to screen space to force it onto the screen. If you also want multiple labels to sort themselves out without overlapping, it gets slightly more twisty. Sincerely, jw |
|
From: Monteleone, N. <nat...@lm...> - 2009-04-29 20:17:31
|
Unfortunately the terrain isn't very flat :-( ________________________________ From: Jeff Russell [mailto:je...@8m...] Sent: Wednesday, April 29, 2009 1:43 PM To: Game Development Algorithms Subject: Re: [Algorithms] Keeping an object's label on the screen The idea I had in mind was to do something in screen space... I'd write out an object ID version of the projected texture, apply it, render the terrain geometry into a low-res buffer, then compute min/max screen coords for each object. Then I could just draw my text label in screen space based on that information. Is this a sane approach? Could be, if your object counts are reasonably small. If this is just sections of the terrain we're talking about, and your terrain is at least sort of flat, you could just project the bounds of these shapes into screen space and center your label accordingly. -- -------------------------------------------- Jeff Russell Engineer, 8monkey Labs www.8monkeylabs.com -------------------------------------------- |
|
From: Monteleone, N. <nat...@lm...> - 2009-04-29 20:17:38
|
Ok thanks. Using the bounding box like that seems a lot faster than trying to analyze an ID buffer. Not worried about overlapping for now :) -----Original Message----- From: Jon Watte [mailto:jw...@gm...] Sent: Wednesday, April 29, 2009 1:56 PM To: Game Development Algorithms Subject: Re: [Algorithms] Keeping an object's label on the screen Monteleone, Nathan wrote: > > What's a good algorithm to figure out where to draw the label? > In general, this is easy, by projecting the desired location to screen space. However, you can get into situations where a corner is visible on the screen, but the center of the object is behind the camera, which may lead to poorly behaved labels. Just project the corners of the bounding box of the object to screen space; take the average of the corners that are in front of the camera, and project that to screen space. Form the rectangle around that, and clamp that rectangle to screen space to force it onto the screen. If you also want multiple labels to sort themselves out without overlapping, it gets slightly more twisty. Sincerely, jw ------------------------------------------------------------------------ ------ Register Now & Save for Velocity, the Web Performance & Operations Conference from O'Reilly Media. Velocity features a full day of expert-led, hands-on workshops and two days of sessions from industry leaders in dedicated Performance & Operations tracks. Use code vel09scf and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf _______________________________________________ GDAlgorithms-list mailing list GDA...@li... https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list Archives: http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-lis t |
|
From: Tom P. <ga...@fa...> - 2009-05-04 01:26:08
|
> I have to draw some billboard text over some shapes we've "painted" onto > our terrain via multitexturing. Normally this is easy enough - just > plop the label in an auto-rotated billboard and float it above the > center of the geometry. But I need to keep the label on screen at all > times if any part of the painted geometry is visible. I.e. if I have a > square painted on the terrain, but I can only see a small corner of it, > I still need to show the whole label. Draw the text if the object isn't culled. You know where you want the text drawn (if you were to draw onto the center of the object), and if you've got the text rect you can just move it so it's within the screen area you want to allow it to live in. -tom! -- |
|
From: Monteleone, N. <nat...@lm...> - 2009-05-04 16:44:00
|
The hard part is figuring out the screen area I want to allow it to live in - the overlay in question is rendered to a texture and then pasted on the terrain. I think I know how to do it though - I know the 2d bound of my overlay. I can combine that with the min/max height of the terrain underneath to get a pretty good bounding box, then project that to screen space like Mr. Watte said. -Nathan -----Original Message----- From: Tom Plunket [mailto:ga...@fa...] Sent: Sunday, May 03, 2009 8:26 PM To: Game Development Algorithms Subject: Re: [Algorithms] Keeping an object's label on the screen > I have to draw some billboard text over some shapes we've "painted" onto > our terrain via multitexturing. Normally this is easy enough - just > plop the label in an auto-rotated billboard and float it above the > center of the geometry. But I need to keep the label on screen at all > times if any part of the painted geometry is visible. I.e. if I have a > square painted on the terrain, but I can only see a small corner of it, > I still need to show the whole label. Draw the text if the object isn't culled. You know where you want the text drawn (if you were to draw onto the center of the object), and if you've got the text rect you can just move it so it's within the screen area you want to allow it to live in. -tom! -- ------------------------------------------------------------------------ ------ Register Now & Save for Velocity, the Web Performance & Operations Conference from O'Reilly Media. Velocity features a full day of expert-led, hands-on workshops and two days of sessions from industry leaders in dedicated Performance & Operations tracks. Use code vel09scf and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf _______________________________________________ GDAlgorithms-list mailing list GDA...@li... https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list Archives: http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-lis t |