- Home /
Layering multiple 2d images on one texture
What I am trying to do is build a customizeable 2d mech game, where you select armor and parts, and the appearance of your avatar changes accordingly. This means, with a top-down view, I need to layer shoulders, head, legs when walking, etc.
How do I do this? I've looked at Texture2d, and found the SetPixels command, but that seems to be rather clumsy. The only way I can envisage this is to GetPixels from the smaller images, then SetPixels, but as I said, this is rather clumsy.
Is there a better, easier to use way?
Answer by sean · May 06, 2010 at 09:19 PM
Hrm. So you've unwrapped entire mechs to textures and then split the model apart so you can have piecewise mechs where for some odd reason you want all the individual pieces to use the same texture file?
The answer from a proper pipeline standpoint is to allow each piece to use its own texture file- as long as you've loaded all the textures into Unity, it shouldn't actually chew up more VRAM to have multiple textures represented in multiple pieces of your mech. You may want to even split out and re-unwrap your mechs as separate pieces that can use separate texture files. This will make everything more modular and less headache-y.
If you really want to stick with compositing multiple parts of multiple textures into a single image, your best bet would be writing a shader that takes multiple textures and a grayscale mask image delineating which pieces of the final uv space to fill from which source image.
If even that would be a stretch, you may be able to somehow composite multiple Decal shaders, each with a texture that is transparent save for the part of the map you need, but I'm not sure offhand if Unity lets you stack render passes like that.
If you want to get REALLY pathological... I suppose you could (on a Pro license) stack up multiple simple full-viewport-sized planes each with an unlit transparent material and a component texture similar to the previous idea, render that to texture via a script, and plug the render result in as your final model texture.
No, I haven't taken apart mech models. This is an old-school 2d style game. :P
Answer by Chris Masterton · May 06, 2010 at 10:05 PM
You are building a top-down 2d mech game? You could avoid compositing them altogether and draw each piece at a different y height. Let the transparent sorting take care of the composite.
that, and make sure your camera is set to orthographic so you don't get scaling issues between pieces
Answer by Sammual12 · Sep 03, 2010 at 08:55 PM
If I understand http://answers.unity3d.com/questions/16020/multiple-textures-layered-in-a-single-mesh correctly then you can just make each mech part a different Texture and add a Material for every part/texture.