I'm very new to LibGDX and I'm trying to use DecalBatch with PerspectiveCamera, simply to have z-coordinate for my sprites, as SpriteBatch does not offer that. However, I don't know how to calculate the z-coordinate for the PerspectiveCamera to have "pixel-perfect 2D-projection". Anyone know how to do that?
What "Pixel perfect" is depends on the size of your textures divided by the mesh's area. First, It's important you keep the aspect ratio between your mesh and textures: If your texture is 64x32, your mesh/quad/Decal will be 2:1 (for example, 2x1).
Now, closer to what you desire, the most important part is to have a consistent and analogous unit measurement. Let's go back to the example before, but let's make the Decal 64x32 (we'll make the 3D unit be equivalent to a "pixel" -notice the quotes, as it's not really the case, just a illusion to help us-). Next, you have to calculate which depth/distance from the general decal plane (assuming your decal's will be coplanar, if not, you can't achieve "pixel perfect" on all -well, you can, but decals with the same resolution should be coplanar-) using the inverse of the equations exposed here: http://docs.unity3d.com/Documentation/Manual/FrustumSizeAtDistance.html (calculating the inverse will be left as exercise for you, or you can always iterate to aproximate)
And, with the distance calculated, you set the camera to look at the plane from that distance: Suposing a XY plane, set z=thisDistance You may need to toy around with the Field Of View depending on the resolution/aspect ratio, or you'll only achieve "Pixel Perfect" on a single dimension.
This is one area that I also found quite lacking. Instead of using
Technically, I created my own wrapper/subclass of
In terms of performance, try to maintain the sorting/ordering outside of the actual drawing (don't re-sort on each draw call, only when you add/remove a sprite).