Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Normal map issue with standard shader

Discussion in 'Unity 5 Pre-order Beta' started by Liquidwad, Feb 17, 2015.

  1. Liquidwad

    Liquidwad

    Joined:
    Feb 8, 2015
    Posts:
    5
    I have been scratching my head over this issue for several days now and couldn't find another thread with the same problem so I figured it was time to post it here. I have a script-generated terrain mesh - a simple mesh with vertices, triangles, and 2 uv sets. No sub-meshes. I am using the standard shader to assign a texture to it using a texture atlas. When I assign albedo-only, it works fine. Adding specular map works fine. As soon as I add a normal map, the mesh goes completely black. The wireframe for the mesh also disappears, and all you see is the wireframe around its outline.

    I add the exact same material to a sphere, and it works without issues.

    If I use the bumped diffuse legacy shader, with the same normal map, it shows up fine.
    I tried both forward and deferred rendering paths. With forward it goes black. With deferred it goes white until I turn on HDR then it goes black.

    At this point I am perplexed to what is causing the shader corruption, but I have a feeling it has something to do with my mesh. Help!

    I attached the mesh with the normal map in the zip file.
     

    Attached Files:

  2. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    I think your normals are wrong. Have you calculated normals and tangents?
     
  3. Liquidwad

    Liquidwad

    Joined:
    Feb 8, 2015
    Posts:
    5
    I have normals and I know they are ok because when I flip them the mesh plane renders from the opposite side. I have not calculated tangents. Didn't know they were required :O. Will try this when I get home from work. Thank you!
     
  4. Liquidwad

    Liquidwad

    Joined:
    Feb 8, 2015
    Posts:
    5
    Calculating tangents fixed the problem! Thank you so much.
    I have another question though: my terrain mesh blends two albedo maps, each using a different UV set. UV's are an input to the tangent calculation, so I need to calculate two sets of tangents, one for each UV set. However, the Mesh class only supports one set of tangents as far as I can see. So if I want to pass two sets of tangents to the shader, I guess the only way to do it is to use color for the second tangent set?
     
  5. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    If it is a terrain mesh, both textures are probably aligned and tiling. I think you can use the tangents for both. There are other blend shaders as well and they have only one set of tangents, too.