Normal map issue with standard shader

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.


1967242–127419–Archive.zip (1.96 MB)

I think your normals are wrong. Have you calculated normals and tangents?

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!

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?

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.