Hi
I’m struggling to load normal textures at runtime (not from the unity editor). I have read a bunch of threads about that, and was able to understand a lot, but now I came to the point where I’m really stuck.
Project settings :
unity 2020.3.14f1
HDRP
I’m using HDRP/Autodesk Interactive shader on my models.
I want to be able to load textures from a folder on the computer at runtime and use it on my models
everything works great, except for the normal textures
When I do import texture in the unity editor (not at runtime) I can select the texture type “normal maps” that makes it works. When I do this at runtime, I cannot.
So I’m trying to compute myself the normal texture at the expected format for Unity. So far I failed.
Based on this thread : Runtime generated bump maps are not marked as normal maps
I tryed this :
Texture2D loadedNormalMap = LoadTextureFromPath(f.FullName);
Texture2D convertedNormalMap = new Texture2D(loadedNormalMap.width, loadedNormalMap.height,TextureFormat.RGBA32, true, true);
Color loadedColor;
Color convertedColor;
for (int w = 0; w < loadedNormalMap.width; w++)
{
yield return null;
for (int h = 0; h < loadedNormalMap.height; h++)
{
loadedColor = loadedNormalMap.GetPixel(w, h);
convertedColor = Color.white;
convertedColor.r = 1;
convertedColor.g = loadedColor.g;
convertedColor.b = 1;
convertedColor.a = loadedColor.r;
convertedNormalMap.SetPixel(w, h, convertedColor);
}
}
convertedNormalMap.Apply();
newMat.SetTexture("_BumpMap", convertedNormalMap);
newMat.SetInt("_UseNormalMap", 1);
Set aside the fact that it’s very slow, it seems to works !
But looking closely, there is a huge loss of quality between a runtime loaded texture (modified with this code) and the same texture that would have been imported in the Unity editor and marked as “normal map”.
Also if I display the texture.graphicsFormat for both texture :
My runtime generated texture says it’s “R8G8B8A8_UNorm”
while the unity-editor-imported texture says “RGBA_DXT5_UNorm”
(which explains the quality gap I guess)
How can I convert my base (.tga / .png ) runtime imported texture to the expected Unity format ?
Alternatively, What should I ask to my artist coworker, for them to give me a .tga file that would be already all set up ?
PS : I tried to convert my texture to BC5 with another software, to try to import it (without marking it as “normal map” in the editor) and see the result, but it outputed me a DDS file that don’t seems to be accepted by unity : "Unsupported Assets/Resources/test_normal_PNG_BC5_1.DDS file. "
PS2:
runtime texture preview (without running the code above):
On the mesh it looks completely wrong, normals looks inverted

runtime texture preview (after having run the code above) :
( texture.graphicsFormat : R8G8B8A8_UNorm)
On the mesh it looks correct

Here I dragged and dropped the Unity texture instead :
( texture.graphicsFormat : RGBA_DXT5_UNorm)
On the mesh it looks way better

@bgolus <3 :help:

