3D World and 2D Sprites

Started by
9 comments, last by GameDev.net 19 years, 7 months ago
I've read as many articles on this that I could possibly find. Many use techniques like billboarding and such, but this won't work in the case that I need it. Here's the problem. The sprites render in the correct positions, but their Z depth causes them to jut into the terrain if they are near objects. Screenshot Here As you can see that isn't an option to allow that to happen. So I'm curious if anyone knows some techniques to get the Z correct for the sprites.
Advertisement
Why won't bill-boarding work? That's what I'd use.
Would it be sufficient to simply disable Z-test? Or maybe better still, clear the Z-buffer after rendering all 3D stuff, so that 2D stuff is still properly depth-tested against other 2D stuff, but not at all against 3D.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
Well, clearing the Z buffer would make the sprites render regardless. I need them to be behind any terrain that would be in front of them. I think I might have came up with an idea of how to fix the problem. If I project the sprite onto a flat surface (and not draw the surface), it would be in a perfect Z upwards position, which should fix the problem. Just gotta make sure I position the flat surface coordinates correctly before projecting on it.
Perhaps you should be using cylindrical billboarding instead of spherical, meaning basically that your sprites could be aligned towards the camera but with a constrained up vector. If the camera were directly over them, they would appear flat, but at an angle they would simply appear to be standing on the terrain. You could also encode depth information in your textures and use a fragment shader to write to the depth buffer, making your sprites actually have some contour, but this might be overkill, and wouldn't really solve the problem you're having now anyway. Just an additional suggestion that might be nice :-)
-bodisiw
The problem with the cylinder method is the camera is on an angle all the time, so the sprites won't look quite right since they are drawn to be on an angle. I think projection is the only method, unless I used stencil buffers, but I think that's overkill too.
Why could'nt you just slap a texture and alpha map on a quad polygon. If your engine already has 3d incorperated, then your sorting would already be implimented for other 3d objects in the scene right?
That screenshot is 3D quads with alpha'd textures. The problem with sprites is they always have to face the camera to look correct. If they don't they won't look correct and can even end up skewed. The problem is, facing the camera doesn't always mean they will fit in the geometry of the map correctly (as the screenshot shows). So the question is, how do you make the quad shape itself to fit in the geometry correctly and make the texture not look skewed. I was thinking that if I project the quad's coordinates so that they remain the same shape/size in the view but end up straight up and down along the Z, that would fix the problem. It requires intersection tests though for each quad, which means even on screen sprite would be taking intersect tests. I'm looking to see if someone invented a better method.
Maybe you can adjust the Z bias when rendering your sprites based on the camera angle.

It goes like this... your sprite has a location on the ground, I assume. Before rendering the sprite, translate that position vector by the character's height in the height axis (either Z or Y, depends on what you're working on) and check the distances between that top position and the ground position to the camera, and then get the difference between them.

Use that to push your z-bias further close to the camera so the sprite top area will not intersect things behind it.

If that doesn't work, then there is no other way: you will have to disable z-reads for the sprites, and sort all objects back-to-front, like in the old days. Considering how your game looks, that'll not affect the performance that much, if node right.
If you use an isometric or axionometric view,
you can constrain your vertical walls to be of constant Z.
So you wouldn't have any problem with your sprite being in a parallel plane. Of course you would still have to constrain the movement of your sprites near walls anyway since whatever your sprite/wall orientation there is still a case which will end up in both penetrating (that is also true of 3d objects.)

This topic is closed to new replies.

Advertisement