What a small technique for such a great effect. The image shows each model with and without the emissive layer. Note the how the red lens of the camera model is all lit up.

Since I'm finally using textures instead of solid colors, I decided to upgrade the models to incorporate an emissive layer (they are robots after all). The shaders have been upgraded to support this.


But now there are two textures for every variant of every model (diffuse and emissive). This is annoying and inefficient. So I wrote a quick script to aid with shader texture atlassing.


  • AtlasOffset - This is the "index" of the texture along each axis. Use round numbers here. If you have an atlas that is 2x2 (two rows by 2 columns) and wanted to target the bottom-right sub texture set this to x:1, y:0
  • Size - The number of cells along each axis. For a 2x1 set this to x:2, y:1.
  • RandomizeOnSpawn - Set to true to randomly choose a sub texture on start.
  • RandomOffsetRange - Set this struct to the ranges of sub-textures you want to randomly (inclusively) choose from. If you have a 2x2 texture and want to only choose randomly from the top two you would set this to XMin:0, XMax:1, YMin: 1, YMax: 1.
  • TextureNames - Your shader may have multiple textures. Add the shader property name for each texture you want to affect. For instance I set this to ["_MainTex","_Emission"] because I have a shader that accepts a diffuse and emission texture. For more examples of multi-textured shaders take a look at the Unity docs: http://docs.unity3d.com/Manual/SL-SurfaceShaderExamples.html.


First of all, this works in Unity 5 only.

It assumes that your textures are combined into an atlas that is divided into uniform cells. For example, if you have 4 textures in the atlas arranged in a 2x2 grid, each sub texture will be atlas.width*.5f by atlas.height *.5f in size. This is is probably a waste of memory (dead space in the atlas texture) - sure - but it was fast to implement.

draw calls

This script copies the original materials. This is important! It may double your draw calls. You can get around this by pooling materials with the same UV offsets, but that's another tutorial for another day.

why not just update the UVs on each mesh?

That would have worked too, but again, this duplicates draw calls as you would have to make a new instance of the mesh. Because it was a wash in performance I implemented the quicker of the two.

drop me a line if you give this script a try

I would love to help if you experience any issues. I would also enjoy seeing any additions you make. Just drop me a line using one of the social icons above. (eg. Twitter)