Jump to content
  • Advertisement
Sign in to follow this  

Billboards - Need help

This topic is 2231 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all,

I'm trying to implement billboards, but have few problems.

I'm using projecting a 2D rectangle to the screen, and drawing it with orthographic camera.
the problem is that the object is always rendered on top of the 3D objects. changing the rendering order makes the 3D rendered on top
on the 2D, but now I have problem with the depths.
The thing is that the billboards are semi transparent (needs to be rendered last) and belongs to transparent objects list, which
is sorted by the distance from the camera, and rendered after the none transparent objects. this means that the 2D rendered on top on the 3D.
how can I solve that? can u suggest better render work flow.

I have also tried to make the object lookat the camera position, which works gr8 for 3rd camera, but for the trackball camera, it is not working,
as the camera position does not changes like the 3rd.
So any help on that direction will be blast to :)


Share this post

Link to post
Share on other sites
I am not an expert, but are you sure you're meant to render it with a different camera? It seems to me that if you rendered it as a texture on a plane that's actually created in your scene facing you the depth would sort itself out using the depth buffer. Or maybe you can use the depth buffer in a some other way.

Share this post

Link to post
Share on other sites
Billboards are usally: 3D planes that always face the player. 3D not 2D. Is this for trees or something? What is the full effect you are doing with the billboards (trees, particles), and a pic might help.

Share this post

Link to post
Share on other sites
[color=#222222]Maybe I was not clear. I have tried to create billboard with different ways.
[color=#222222]The first is with orthographic camera, just by drawing a plane, which is works fine, but I have a problem with the depths. The billboards are always appears on top of the scene.
[color=#222222]Changing the drawing order, does fixes the problem, but if the billboard is transparent, it doesn't work because transparent objects needs to be rendered last.
[color=#222222]The second is by setting the object rotation to always look at the camera, which is work fine if the camera position is change on space. However for TrackBall camera,
[color=#222222]this is not the case, and it is not working for that type of camera,
[color=#222222]Hmm, yes. a tree can be good example.
[color=#222222][font="Times New Roman"][size="3"] [/font]
[color=#222222]I would like to learn the solution for both cases...

Share this post

Link to post
Share on other sites
Take your camera matrix, now think about it in terms of a set of 4 vectors.

X: a b c 0
Y: d e f 0
Z: g h i 0
W: j k l 1

So, given some quad of width W, height H, located at the position P, the 4 corners of the quad can be calculated like so:

// half width and height
float W2 = w * 0.5f;
float H2 = h * 0.5f;

// use X and Y directions of camera matrix to compute the offsets to edges from P
vec3f VW = X * W2;
vec3f VH = Y * H2;

// compute 4 points that make up the quad.
vec3f P0 = P - VW + VH;
vec3f P1 = P + VW + VH;
vec3f P2 = P + VW - VH;
vec3f P3 = P - VW - VH;

If you need a normal vector, just use the Z axis of the camera transform.

Share this post

Link to post
Share on other sites

I have tried to do your suggestion, and it still not working. When I'm rotating the camera, the billboards is not facing the camera.

float W2 = 20.0 * 0.5;
float H2 = 20.0 * 0.5;
// c is a pointer to the camera.

vec3 X = vec3(c->GetWorldMatrix().m[0],c->GetWorldMatrix().m[1],c->GetWorldMatrix().m[2] );
vec3 Y = vec3(c->GetWorldMatrix().m[4],c->GetWorldMatrix().m[5],c->GetWorldMatrix().m[6] );
vec3 VW = X * W2;
vec3 VH = Y * H2;
vec3 P = vec3( mGlobal.m[12],mGlobal.m[13],mGlobal.m[14]);
vPoints[0] = vec3( P - VW + VH );
vPoints[1] = vec3( P + VW + VH );
vPoints[2] = vec3( P + VW - VH );
vPoints[3] = vec3( P - VW - VH );
static us16 uiIndices[ 6 ];
uiIndices[0] = 2; uiIndices[1] = 1; uiIndices[2] = 0;
uiIndices[3] = 0; uiIndices[4] = 3; uiIndices[5] = 2;
pGeo->vTxCoords.push_back(vec2(0.0f , 0.0f));
pGeo->vTxCoords.push_back(vec2(0.0f , 1.0f));
pGeo->vTxCoords.push_back(vec2(1.0f , 1.0f));
pGeo->vTxCoords.push_back(vec2(1.0f , 0.0f));

Can u spot the problem?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!