Jump to content

  • Log In with Google      Sign In   
  • Create Account


Orthographic-like billboards in perspective projection?

  • You cannot reply to this topic
2 replies to this topic

#1 Grumple   Members   -  Reputation: 164

Like
0Likes
Like

Posted 30 July 2014 - 01:27 PM

Hello,

 

I've got an old billboard rendering implementing in fixed-function openg.   The billboards technically represent locations in 3D space, but I want them to render the same pixel dimensions no matter how far away they are in my 3D (perspective projection) scene.

 

The way I handled this in the current (ancient) implementation is as follows:

  • Render my scene in standard 3D perspective projection without my billboards.  
  • Switch to orthographic projection, Loop through the billboards client-side, transforming their 3D position into 2D Screen coords
  • Render all billboards as 2D objects with a constant size used in pixels.

This is horrible for a number of reasons, first being it uses the oldest of old GL functionality.  I'm switching to shaders and using opengl 'instancing' as the basis for the update.  

 

One of my main goals is to eliminate the client-side step of projecting the billboards into 2D screen space, and rendering via a second pass in an orthographic projection.  

 

As far as I can tell, the only way to render the billboards within the perspective projection, while having them all maintain a fixed pixel size on screen, is to re-size each billboard dynamically from within the vertex shader, based on distance from eye .  

 

Is the above assumption correct?  Is there any simpler way to go about this that eliminates the client-side transforms/orthographic render stage while maintaining constant pixel dimensions for billboards in a 3D scene?

 

For what it's worth I'm intending to render the shader-based billboards using OpenGL 'instancing', such that I can store a vertex array with each point representing a unique billoard, and my 'instance' data containing the base corner offsets.

 

Thanks!



Sponsor:

#2 MJP   Moderators   -  Reputation: 10877

Like
2Likes
Like

Posted 30 July 2014 - 04:30 PM

You can certainly still use an orthographic projection and achieve your goal of using instancing + shaders. You just need a custom vertex shader that does the following:

 

1. Take the 3D center point of the billboard that comes from your per-instance data, and project it into 2D space

2. Offset the 2D center point by the current vertex position

3. Transform the resulting vertex position by your orthographic projection



#3 Grumple   Members   -  Reputation: 164

Like
0Likes
Like

Posted 31 July 2014 - 07:17 AM

Hi MJP,

Thanks for the response!  I see what you are saying and I think it makes complete sense....Being still somewhat new to shaders, I forget that the view frustum clipping doesn't happen prior to my vertex shader stage....for some reason I was assuming that GL would throw away my 3D vertices once I had set up for an ortho viewport/pixel-based coord system.  

 

Sometimes it is easy to fall back into a fixed-function mentality.. =P

 

Thanks!







PARTNERS