Decode normal maps on export instead of trying to access pixels.#33
Decode normal maps on export instead of trying to access pixels.#33hybridherbst wants to merge 1 commit intosketchfab:masterfrom
Conversation
…s for all normal maps, no matter how they were created (greyscale/bumpmap/tangent space...)
|
Hi @soraryu, Thanks a lot for this PR and the explanations 👍 Please note that we are not active anymore on this code, as we switched to https://github.com/sketchfab/UnityGLTF. |
|
I see. Would be great if you could mention that on this repo's Readme – otherwise I would have spent time on that other code directly ... From a quick look at the code, looks like the other repo has similar problems with requiring all textures to be living in the AssetDatabase for export. Edit: the "new" repo is way behind the official Khronos Group repo, right? |
|
Yes, I would make sense to mention this in the Readme (I'll add a note), and you're right, we have the same problems with the new code. We actually diverged from the official Khronos Group repo since our only goal was to build a Sketchfab to Unity plugin around glTF. The structure of UnityGLTF was much more interesting and maintainable so we moved both our importer and our exporter. The official repo has been updated since we worked on our version so they probably went further that us (as we stopped when we had enough features to support for our usecase). |
|
@AurL Note that both versions linked at https://sketchfab.com/exporters/unity, the AssetStore version and the github version, are this one (the one you say is deprecated). |
Reading raw texture pixels from disk is, in general, not a good idea given the wealth of texture formats Unity supports internally. A Texture2D could come from anywhere -
One case where that is a problem in the sketchfab exporter is NormalMap exporting - their pixels would only be correct if the normal on disk is already in tangent space (sometimes, but rather rarely the case).
A solution (for the normal maps, but a similar approach would work in general) is to decode the actual texture and convert the necessary data to a PNG or JPEG file which is then stored for glTF usage.
A shader is used to convert into the right encoded normals format (tangent space).
This works for all normal maps, no matter how they were created (greyscale/bumpmap/RenderTex)...