Pixel Perfect Billboard Sprites 1

I spent some time researching the issue of billboard sprites. I personally believe that the correct course of action is not to just perform a Transform.LookAt, but to actually align all billboard sprites to point the same direction that the camera is pointing. If you simply have each sprite look at the camera, multiple billboards across your screen will create a curve around your camera and they jut into each other if they overlap; This is because each billboard sprite would exist in 3D space at slightly different angles. Worse still, objects on the edge of the screen get warped like a funhouse mirror. Therefor aligning seems to be the way to go.

Here is an example I created in Unity that demonstrates this issue:

Billboard Sprite Align Technique Vs LookAt Technique

Billboard Sprite Align Technique Vs LookAt Technique

The Code

Here is the key line of code:

MyTransform.LookAt (MyTransform.position + MyCameraTransform.rotation * Vector3.forward,
		MyCameraTransform.rotation * Vector3.up);

Here is an entire Unity class file for you to play with:

// BillboardSprite.cs
using UnityEngine;
using System.Collections;

public class BillboardSprite: MonoBehaviour {

	public Transform MyCameraTransform;
	private Transform MyTransform;
	public bool alignNotLook = true;

	// Use this for initialization
	void Start () {
		MyTransform = this.transform;
		MyCameraTransform = Camera.main.transform;
	}
	
	// Update is called once per frame
	void LateUpdate () {
		if (alignNotLook)
			MyTransform.forward = MyCameraTransform.forward;
		else
			MyTransform.LookAt (MyCameraTransform, Vector3.up);
	}
}

Bonus

Now that you are aligning objects with the camera, depending on your game, you might not need to keep rotating the sprites every frame unless the camera rotates. This might be particularly true for an orthographic camera. So for further optimization, you could (in theory) set up a C# event system to achieve tighter results.

My laptop was struck by lightning! LOL

I wish I were kidding folks, but my laptop was struck down by lightning. I lost about $4,000 worth of electronics in the blink of an eye. So please if I may suggest one thing to you: Backup is important.  The backup service that I personally use is Backblaze. They offer unlimited backup (including external hard drives) for $5/month or less. Please do me a favor and check out their free trialLet's thwart the mighty Zeus together! 

Click here to price compare. Or click here to download the Backblaze install file immediately.  A big thank you to the folks at Backblaze and thank you dear reader for supporting websites such as this one.

One comment on “Pixel Perfect Billboard Sprites

  1. Pingback: Billboard experiments – Reeltrash

Leave a Reply

%d bloggers like this: