Texture Array Generator - Unity

I have created a Texture Array tool to allow me to generate texture arrays inside unity and place them on a generated material. The textures are pulled from an array of materials that the user defines in the editor, It then iterates on that array and compiles list’s of textures from the different texture map slots. Once the textures are in their Lists the tool will compress them before generating a Texture2DArray for each texture type and adding the textures to it. A material is then generated at the specified path with the chosen name, it uses a quick shadergraph as the shader to read the array maps and a float is available in the inspector to modify the index of the array per material.

Throughout the process all the texture maps are compressed to save memory using ASTC_6x6 compression, I chose this as I would be targeting VR and is recommended by unity for mobile devices. Aside from setting the compression of the textures and texture arrays, using this tool will allow me to instance all the textures together as they are all part of one material.

Initial Goals:

To make this tool I firstly Outlined what I wanted to achieve via using it. The list I ended up with was:

  • Reimport the selected textures with the correct Compression settings and allowing the textures to be read/writeable.

  • Iterating over the list of textures and make sure they pass a selection of criteria to be able to be used within a Texture Array - correct compression and correct sizes(width+height)

  • Adding the updated list with compatible textures into a new array

  • Generate a new Texture2dArray asset and applying the updated list of textures to the array.

  • Setting a path to the location I want the array to be placed in the project

  • Create a shader which could read the texture array asset and allows the user to choose the index number they which to use on a particular asset from the material properties.

  • Generate the asset into the project and then apply it to a new material with the Texture2DArray shader applied.

I am happy to say I managed to hit all of my initial goals and can now look to improve the tool further!

For next time:

To improve the tool going forward I am going to be looking at placing the index for each material into the UVW’s of my meshes. I’d also like to perform a variety of performance tests comparing Texture Arrays, Texture atlases and regular material setups. For this I will need to produce a test environment which shall be my next project! I have learned a lot about modifying textures and materials from creating this tool and look forward to pursuing this topic further in the near future.

Next
Next

Unity Game - Optimization Techniques