Billboard issue in front of 3D object

Started by
5 comments, last by Laubstein 10 years, 5 months ago

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 with characters and items such as billboards.

I'm using an orthographic camera with an angle of 30 degrees on the X axis, I did my sprite to act as a billboard with the pivot in the center, the problem occurs when the sprite is nearing a 3D object such as a wall.

billboardissue.jpg

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 flattened, I also changed the pivot to the bottom of the sprite but this problem appears with objects in front of the sprite too. I was thinking that the solution would be to create a fragment shader that relies on the depth texture of some previous pass, I tried to think in how to do it with shaders but I could not figure it out. Could you help me with some article or anything that puts me in the right direction? Thank you.

Advertisement

If you stand somewhere and someone watches you from above, you would not bend down backwards or even lay on the ground right? So you should not let your sprite do that, too.

Just keep the feet on the ground (that may be an easier object origin than the middle) and the head directly above in world space, not view space.

I am trying to achieve the same visual as this video shows:
You can see that the player almost lay down on the ground right? Sorry if I am still wrong. Otherwise if I leave the head directly above in world space the sprite gets kinda flattened. Am I missing something? Thanks :)

That's an interesting problem.

My first thought would be to not use full camera facing billboards, instead use normal quads that are orthogonal to the ground and put the texture on there. You'd still want them to billboard on the y axis however. The side effect of this would be that the sprites would look shortened vertically when viewing from above, so to compensate for that you'd have to stretch the quads vertically dependent on the camera angle. I can't think of any reasons immediately why this wouldn't work, and it seems preferable to messing with shaders.

I will elaborate if it's not clear what I'm saying.

I guess it is a clever idea, I am gonna try to test it tonight. The good is that I won't plan to change the angle of the camera dynamically in the scene so a good height offset for the billboard to stretch the quad would do the trick. I read that another solution would be disabling the z-buffer write and draw the objects from the furthest to the nearest, but sort ing the entirely objects in Unity3d would not be so easy as if it was in OpenGL. Just for curiosity do you think in something related to shaders technique to solve it?

Thanks.

With shaders you might be able to change the depth testing offset factor (see http://docs.unity3d.com/Documentation/Components/SL-CullAndDepth.html ) of the scenery to 0 - if I'm understanding the documentation properly this would make the scenery all screen facing in terms of depth, but I'm not sure if it would introduce any other problems.

I tried your solution @stevenmarky and it works great, the scaling should be about 1.1547. It is (1 / cos30), which makes billboards look like original size from the camera with the angle of 30 degrees.

This topic is closed to new replies.

Advertisement