Pixel Sprite Generator Unity

by Shogan

A port of the PixelSpriteGenerator to C# for use with the Unity3D game engine

( Updated a few seconds ago )


A port of the Pixel Sprite Generator to C# for use with the Unity3D game engine.

Ported from the JavaScript / HTML version done by zfedoran https://github.com/zfedoran/pixel-sprite-generator to work with Unity3D.


Space ship sprites colored

alt text

Space ship sprites low saturation

alt text

Space ship sprites many color variations

alt text

Dragon sprites colored

alt text

Tree sprites colored

alt text

Shrub sprites colored

alt text

Robot sprites B&W

alt text

Algorithm information

The sprites are generated by using a two dimensional mask. The values in the mask are then randomized and mirrored. The resulting template is rendered to a canvas element.

alt text

The algorithm is explained in more detail on Dave Bollinger's website.

alt text

Usage in Unity3D

To use Pixel Sprite Generator for Unity, you should first of all add the three main scripts/classes to your Unity project:

  • PsgSprite.cs
  • PsgMask.cs
  • PsgOptions.cs

Once these are added, to generate a sprite you need to define a template. The template is an integer array. Take a look at the template examples in the included PixeSpriteGeneratorDemo.cs for some ideas. Create an instance of the PsgMask class and pass in your template int[] and also pass in parameters to indicate your template size dimensions (x, y) as well as whether or not it is mirrored on the X or Y axes.

Next, create an instance of PsgOptions and define the options you would like to use. For example, colored or not, saturation, edge brightness etc... These options effect the look of your generated sprites.

Finally, create a new PsgSprite instance and pass in the mask and options (PsgMask and PsgOptions instances you created before).

The constructor of PsgSprite instance will do everything for you, and afterwards you can access the PsgSprite texture property to get a handle on the Texture2D that is created of the sprite. Use point mode filtering for the texture and set the wrap mode to Clamp for best results and usage as the texture for a Sprite.