• 13
• 18
• 19
• 27
• 9

# Billboards - Need help

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

## 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

tnx

##### 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 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 on other sites
[color=#222222]Hi,
[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...
[color=#222222]tnx.

##### 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 on other sites
Hi,

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 on other sites
Hi,

Found the problem.
I needed to inverse the camera matrix.

not its is working great.

tnx alot man!!!