Home Unreal Engine

UE4 Normal blending

JackDCaron
polycounter lvl 4
Offline / Send Message
JackDCaron polycounter lvl 4
Trying to come up with some solutions for proper normal blending for layering tileable and detail maps in Unreal 4. Did a little write-up >here<, wondering if anyone had a different way, or maybe thought this was incorrect. Definitely not 100% sure how (or where) Unreal recreates the blue channel after the BC5 compression chucks it, but seems like I'm still getting the information from the blue in the blend, so thinking the textureSample node is handling it.

Thanks!

Replies

  • mAlkAv!An
    Offline / Send Message
    mAlkAv!An polycounter lvl 5
    That's right, the Normal sampler node automatically performs the math to reconstruct the blue channel,
    sqrt(saturate(1.0-dot( NormalXY,NormalXY))).
    I've also done a similar comparison for Unreal and yours look familiar although your 'Unreal Add' version is a bad idea because you should never add the blue channels of 2 normals maps but only the red and green.
    http://oliverm-h.blogspot.de/2014/01/ue3udk-mixing-normal-maps.html
  • Farfarer
    To get the blue it's something like sqrt(1 - (norm.x*norm.x + norm.y*norm.y)).

    Basically, you know it's a unit length vector and the blue channel is never negative, so you can work out what the blue channel is because you know what the other two components are and that their length should be 1.

    For really nice normal map blending, you probably want to look at this;
    http://blog.selfshadow.com/publications/blending-in-detail/
  • JackDCaron
    Offline / Send Message
    JackDCaron polycounter lvl 4
    Thanks guys!

    mAlkAv!An, totally agree that the "add" method is not right, pretty much the reason I started doing the comparisons is because I saw people (some at work even) just adding two normal texture samples together. I'll make it clearer that I'm calling this wrong in the write-up. I am curios about methods in which you multiply the normal buy 1,1,0 and then add 0,0,1 to even it out (I think this was used in the landscape demo).

    Farfarer, I referenced the paper in doing what I felt was the best (and simplest) method in the WhiteOut Blend in the last example of my writeup. I think I translated correctly in node form?

    float3 r = normalize(float3(n1.xy + n2.xy, n1.z*n2.z));

    I have another question, probably easy for you guys to answer. In Photoshop we are able to Overlay the R + G because the detail sits above or below the mid grey in value, while multiplying the B channel because its base is white. In UE, we pull the blacks to -1, essentially leaving the white at 1, but bringing the grey to 0, correct? Is this why the add node works for the R + G channels in UE?

    Thanks again.
  • mAlkAv!An
    Offline / Send Message
    mAlkAv!An polycounter lvl 5
    JackDCaron wrote: »
    I'll make it clearer that I'm calling this wrong in the write-up. I am curios about methods in which you multiply the normal buy 1,1,0 and then add 0,0,1 to even it out (I think this was used in the landscape demo).

    You should just add the X,Y components and discard the blue channel of the detail normal map. That's actually the real 'Unreal/UDN' version. See here.
    JackDCaron wrote: »
    I think I translated correctly in node form?

    float3 r = normalize(float3(n1.xy + n2.xy, n1.z*n2.z));

    Yes you did. Adding X,Y but multiplying Normal-Z.
    JackDCaron wrote: »
    I have another question, probably easy for you guys to answer. In Photoshop we are able to Overlay the R + G because the detail sits above or below the mid grey in value, while multiplying the B channel because its base is white. In UE, we pull the blacks to -1, essentially leaving the white at 1, but bringing the grey to 0, correct? Is this why the add node works for the R + G channels in UE?
    That's right, the adding works because the normals are in [-1, 1]-range. For the same reason it possible to simply multiply normal.xy by a scalar to increase or decrease the intensity of a normal map.
Sign In or Register to comment.