View Full Version : Billboard issue

11-24-2013, 09:31 AM
Hello, I'm starting to develop a poc with the main features of a turn-based RPG similar to Breath of Fire 4, a mixture of 3D environment.

I am currently facing a rendering problem. In our game, the character is a sprite rendered on a plane, living in a 3D world. The plane is a billboard always facing the camera, camera which is over his head. So, the plane is almost horizontal to show a character standing vertically. It provokes visual problems when the billboard goes through a wall:


I had tried the solution leaving the rotation matrix of the billboard "upright", worked well, but of course depending on the height and angle of the camera toward the billboard it gets kinda flat.
I read that one solution would be to create a fragment shader that relies on a depth texture, I searched a lot in internet and could not find much. Could you help me with some article or anything that puts me in the right direction?
Thank you.

11-24-2013, 09:55 AM
You could first render your 3D enviroment, then clear the depth-buffer bit, and then draw all your 2D sprites.
This way your 3D enviroment will never obscure your 2D sprites, no matter their positioning.
However, this might not be what you want, depending on the situation.

11-24-2013, 10:01 AM
This would only work when there is nothing in front of the sprite, i still want my sprite is hidden by obstacles in front of him. Will I have to rearrange each object in the scene each frame depending on the position of the sprite?

11-24-2013, 10:07 AM
Maybe I can render the 3d enviroment, clear the z-buffer, draw my sprites and then do some raycasts to check if there are objects in front of him and then draw those objects again?

Dark Photon
11-24-2013, 06:03 PM
It provokes visual problems when the billboard goes through a wall:

Billboard => /| <= Wall (Can't paste links, new user

Lets see your problem. Go ahead and paste the url in there. Put some spaces in there, remove the http://, or whatever it takes to get it in there, and I'll edit it so it shows up.

11-24-2013, 06:11 PM
Done, thanks Dark.

Dark Photon
11-24-2013, 06:14 PM
Briefly, billboards only work well in place of objects (in this use case BTW, they are called impostors) when nothing else intersects the bounding volume represented by the impostor billboard. If it does, you have to jump through some hoops because the depths being used in the pipeline for fragments of your billboarded quad are NOT the depths for the object that is being represented. In other words, depth testing with the quad depths isn't completely valid. But can be given some assumptions.

Depth impostors are I think what you're referring to, where the impostor provides a depth at each fragment to override the quad depth, but those have their disadvantages (typically doesn't provide MSAA depth info, prevents early depth tests, etc.). Soft particles is another technique that is sometimes used here. But let's be sure you really need that first.

Dark Photon
11-24-2013, 06:32 PM
Just edited your URL so we can see the post above.

First since you're using impostors, you might consider whether it's possible in your case to just render everything furthest-to-nearest without depth testing (termed painters algorithm) and have everything appear the way you want with sufficient performance. If so, just do that.

If not, you have a few issues to deal with: depth and alpha. First, depth. As I mentioned with impostors you typically don't have the depth for the "actual" object represented in the impostor in-tow with the impostor quad, so without special tricks, you need to ensure that no other object protrudes into the space represented by the impostor. The texels of the impostor which are 100% transparent don't count because you can alpha test that out easily enough in the pipeline. With this assumption, the impostor quad depths are often "good enough" because nothing else intrudes into its space so the quad depths are "good enough".

The next thing is alpha (translucency). Initially, you can just render the impostors with blend disabled but alpha test enabled (to snip off the 100% transparent texels). Get that looking good. Then you have to deal with getting the translucent fragments blended properly. There are several ways to deal with this problem. For standard alpha blending, you typically need to render the alpha objects (or at least the alpha portions of them) from furthest to nearest so that they blend properly. But there are other ways for handling transparency that don't have this problem, such as using weighted average transparency, MSAA transparency, etc.

11-25-2013, 06:17 PM
Thanks for the explanations Dark, I ended up leaving the impostor with only the rotation on the y axis, it gets kinda flattened but I can stretch the quad vertically to make it look right relative to the angle of the camera, it looks very good:
Image (http://s23.postimg.org/h4a8q15wr/Sem_t_tulo.png)