I've implemented normal maps into my game renderer using the formulas by Christian Schuler.

It works OK with most normal maps but some not so much since in some the Y component (green) is reversed. Apparently there is no real standard here and Maya does it one way and Max does it the other way.

I'd like to be able to look at a normal map's values and somehow determine which scheme is being used, if that's possible.

Also, though I have not actually seen any, some normal maps appear to use only two channels and the third channel is left blank and calculated at runtime. Ideally I would be able to detect those, too. I figure maybe the Z channel is all zeros? I am not sure that would save any space though so maybe it is some other scheme.

Seems like an obvious desire, but I don't see any references to this. but then, maybe it's not really possible.

up vote 2 down vote accepted

There's no good way to detect different data formats from each other in shader code.

In general you should always give the same kind of data to your shaders. You need to pre-process your data before drawing with it. Pick one format and convert all data to that, and then write your shaders to use that format.

One other way is to detect the format before you start drawing and then use separate shader made for that spesific format.

  • Is there a way to detect it from the data outside the shader? That would be OK too. – Yudrist Jul 8 '16 at 11:23
  • When you are importing assets to your game, your importer should have an option for each different case so it can import the assets in correctly. Usually the user knows in which format the normal map is in and can give the information straight to the importer. Or then just convert the data to a known format before giving it to the importer. – Lasse Jul 8 '16 at 12:42

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.