Combining multiple Texture2D into a single texture (Character customization)

So, I’m trying to figure out the best way to go about character customization for 2D sprites. So far, I’ve come up with the idea of splitting my character up into 3 pieces (head, upper body and lower body) and then combining them at runtime. This way I can have variations of each part, and just combine the ones chosen by the player.

I would also have to combine normal maps and depth maps for each part as well, though, so I’m worried that this would be a huge performance hit. Would this be the right way to go about making character customization, or is there a better way?

Thanks.

Sounds like what you really need is a texture atlas. Unity 4.3 added lots of 2D tools to simplify this. Start here to learn more: Unity Blog

However, judging by the question’s title, you really do mean that you want to combine three textures into one texture at runtime. If so, the performance gains of an atlas aren’t going to mean much, and you just need a clever way to build your new texture quickly. This can be done over several frames to reduce or eliminate any hiccup / lag. Need more info to comment further.

Best of luck,

Thanks for the reply, and sorry for the delay in my response.

Unless I’ve misunderstood how to use a Texture Atlas, I don’t think it would be particularly effective in this case, just because of the large amount of animations and frames. I have multiple frames of one animation as all part of the same atlas at the moment.

I’m not sure what info you need to give a better response. Essentially i was thinking of having a head sprite/texture2D, as well as a completely separate upper body texture and lower body texture. Each would have its own “walkdown” animation, for example. Then, when the “walkdown” animation is called, it would find the correct texture of each part of the body, and then combine it to make the complete character.

I also heard there was a way to combine textures in a shader? I also have to apply lighting, self shadows, depth and normals in the shader, so I’d have to combine all the textures, then do all the light calculations etc.

After googling this, I wasn’t able to find anyone else that has done character customization either of these ways, so I’m not sure if this is the right way to go about it. What does everyone else think?

Any chance we can get some pictures or other visual aids to see what you’re doing versus what you want to achieve? I think we’re left to assume too much about your scenario to be super helpful.

So here’s an example RunDown texture I have:
1542832--89866--$RunDownAnim.png
At the moment, there is no possible way to customize this character (besides maybe a color swap function in the shader)

I want to have 3 separate parts for the character, so that I can have different clothes, hairstyles, etc for the character. So it would need to be split into different textures like so: (This is just a mockup done by me; I haven’t asked my artist to split up the texture yet due to the fact that I don’t know if this is possible or not)

Head:
1542832--89864--$Head.png

UpperBody:
1542832--89867--$Upper.png

LowerBody:
1542832--89865--$Lower.png

During runtime, these 3 textures would need to be combined to look like the very first texture. This way I can have 10 different head textures, for example, and the player can choose #3 and have the same clothes, but a different looking head.

When your artist creates these assets, are they going to give them pixel-perfect cutouts as you’ve indicated here? Will there ever be cases where the body overlaps the head, for instance? Your approach must consider all potential cases.

You could create a three-pass shader which renders the lower, mid, and upper parts in that order, and possibly avoid making pixel-perfect cutouts. Your best alternative would be mixing down each possible frame of animation when the user changes one of the customizable elements. (You shouldn’t do this each frame because it’s a very expensive operation.)

I’d probably go with the 3-pass shader option, if your parts never overlap differently. What’s all this about lighting and normals? How is that meaningful in your scenario? Cool art by the way, that’s good stuff. :slight_smile:

Oh hm, I didn’t consider the possibility of having the body overlapping the head, but when you mentioned it, I realized that there are cases where that does happen (like when the character lifts a weapon over his head). I didn’t plan on using pixel perfect cutouts, as that would create issues if the hairstyle that was chosen instead of this one was smaller, etc, etc. Could I use the depth maps to determine which pixel is showing when merging?

Speaking of which, I mention normal and depth maps because I’m working on implementing real time dynamic lighting, using a modified version of this shader. It takes normals and depth to determine shadows and such. So if I used the shader approach to combining the textures (which seems like the best approach at the moment) it would have to first do 3 passes to combine each diffuse map (essentially the textures I attached previously) then 3 passes for normals, and 3 for depth. Afterwards it would need to do another pass for lighting. Although, I’m unsure as to how to pass the merged diffuse/normal/depth maps to the lighting part of the shader…

Wow, that is a cooooool shader technique. For situations where you’d like to control rendering order in a more complex fashion, I’m not sure a shader-based approach to customizable characters remains appropriate. If you can completely forgo overlap situations more complex than head-over-torso-over-legs, the shader approach sounds okay. I’m not convinced it would require more than three passes - one per body part - but I have zero experience with custom lighting models or complex uses for normal maps. If I were you I’d start a new thread - possibly in the shader forum - which asks whatever specific questions arise next. Unless someone comes along who is better informed in the mean time, of course. I’m afraid this is unfamiliar territory to me.

Well, thanks for the help and advice.
I’ll try posting to the shader forum, but that place tends to be pretty dead…