We’re trying to develop a game where the player can customize his/her avatar’s clothes/armor, skin tone, face and hair (i.e. your typical modern day RPG game experience). We divided the avatar into 5 pieces which are for purposes of this discussion: the head, torso+upper arms, lower arms+hands, pelvic area+ thighs, and shin+feet.
Mixing and matching various armor pieces and heads this way seems to work fine except for one particular issue at the moment as illustrated in the attachment.
The left and right avatars are basically identical except the left avatar is comprised of the 5 aforementioned pieces while the right avatar is is one solid mesh. The issue we’re having problems with is with the shading of the left avatar. Even though for example, the left lower arm connects precisely with the left upper arm, the shading gives the seam away because of the misalignment of light and shadow across the 2 meshes. When looked at from the front, it looks like there’s a crease at the edges where the 2 meshes connect. The right avatar, being one solid mesh has correctly aligned shading. The right arm suffers the same problem.
If you’re observant of the avatar’s lower back, you’ll notice further misaligned shadows between the torso and the pelvis area. Though the textured panties does a lot to obfuscate this problem, I can’t apply the same trick to the elbow and knee areas.
My supervisor wants me to go with the one solid mesh way but this adds a bit more complexity in handling armor/head swapping which I’d rather not introduce to our design.
He’s giving me today to try to solve this problem; otherwise, I’ll have to redo every armor among other things. Is there a way to solve this issue? It looks like a shader problem but I don’t know how to fix it. I made the meshes in Blender if that helps.
The problem looks like it comes down to the normals. On your single mesh actor, the normals are averaged across each face, however in the multi mesh actor, there is a distinct change in the normals, hence why you get that seam. The best way to avoid this would be to weld the verts at the elbow. This can be done through script but it is not an easy task.
Thanks for your reply. Pointing out that it was the normals made me try baking the normals of the solid mesh and applying it to the 5-piece mesh’s materials and importing it into Unity with Calculate Normals enabled and Smoothing Angle set to 180. With or without Split Tangents enabled, the difference between the result and my previous mesh (without normals calculated) was negligible. The shadows and light moved a few pixels here and there but they were still nowhere near being aligned.
I’d like to try that suggestion of yours regarding combining vertices via scripting but I’m still learning Unity and I’m starting from the 3d modeling perspective while my supervisor’s the one doing the programming; ergo I currently have zero idea where to begin to look to program that.
Anyway, my one day grace period’s over so it looks like we’ll be working on one solid body base and making it work from there.
Still, if anyone reading this has a scripting solution to this like a way to group “interlocking” meshes and have the render engine average the normals across all meshes in the group, please point me in the right direction.
Provided these meshes connect precisely as you say, the problem should be easily fixed.
With Unity AssetImporter you can find these close-together verts and assign them the same weight-per-bone and normals.
This should be really straight-forward.
Not the same, but this is how I build collision from level geometry. It’s not what you need, but shows how to iterate through your verts and what classes are involved.
Tell your supervisor to give this another try. Unless he can’t handle it, which means you have more work to do.
From the docs, this is the data you can play with, which is all you need to get the job done.
vertices Returns a copy of the vertex positions or assigns a new vertex positions array.
normals The normals of the mesh.
tangents The tangents of the mesh.
uv The base texture coordinates of the mesh.
uv2 The second texture coordinate set of the mesh, if present.
bounds The bounding volume of the mesh.
colors Returns the vertex colors of the mesh.
triangles An array containing all triangles in the mesh.
vertexCount Returns the number of vertices in the mesh (Read Only).
subMeshCount The number of submeshes. Every material has a seperate triangle list.
boneWeights The bone weights of each vertex
bindposes The bind poses. The bind pose at each index refers to the bone with the same index.
Thanks a lot Rozgo. My supervisor was actually looking at this code snippet: http://www.unifycommunity.com/wiki/index.php?title=CombineSkinnedMeshes yesterday and it looked the most promising because it seems geared specifically for avatar customization. Unfortunately, he couldn’t get it to work right of the bat so he still asked me to go with one mesh this morning.
I directed him to your post here but unfortunately his failure to get that last script working discouraged him somewhat and since he’s the only knowledgeable Unity programmer we have working on this project it looks like I’ll have to do the single mesh thing.
Thanks though. I really appreciate your taking the time to reply.