Thursday, February 14, 2013

A simple asset, but a lot of technical hurdles...

I decided to practice some sci-fi and found this neat concept by Jeremy Love.



Very simple asset, but when I brought it into UDK it ended up looking like this:





Ugh, awful.


My problem is that my normal map is mirrored, which means that half of the UV shells are flipped which cause problems with how the normals are calculated in the engine. 



Look at all that red. That's a bad sign all right. So after some research I came up with this solution.

First of all you need to fix your UV's. UDK hates mirrored UV's so I flipped the red shells so they are blue and nicely correspond to their geometry again. The problem of course is that they no longer line up with the texture any more, but there's a solution to it. 


In UDK you can change the way that textures tile in the Texture Properties. The default is Wrap which is the mode we're all used to, but there's also Mirror and Clamp. Mirror is the one we're interested in because it does this:





Excellent! This means that if we lay out or UV’s this way they will match the mirroring:



But it’s not that simple, because when you mirror the normal map horizontally you end up flipping the X axis (red channel) which causes mirrored  lighting.  But with a little bit of material editor magic we can fix that.
We can flip the red channel by multiplying the normal map with a float3 with the values -1,1,1, but we want that to only apply to the mirrored UV’s. This is also fairly simple. All we have to do is to lerp the two normal maps with a checker pattern with its UV tiling set to 0.5. This will make it match up to the alternating mirroring and mask out the x-flipped normals from where we don’t need them. But again it’s not that simple, because when you mirror the normal map horizontally you end up flipping the X axis (red channel) which causes mirrored  lighting.  But with a little bit of material editor magic we can fix that. We can flip the red channel by multiplying the normal map with a float3 with the values -1,1,1, but we want that to only apply to the mirrored UV’s. This is also fairly simple. All we have to do is to lerp the two normal maps with a checker pattern with its UV tiling set to 0.5. This will make it match up to the alternating mirroring and mask out the x-flipped normals from where we don’t need them.



And the results?



Perfectly mirrored normals! No seams, huzzah! :D

Hope this is helpful to y’all.

1 comment:

Arthur Ramazanov said...

Dude - this is pretty awesome AND SHINY!!!!