URP Normal Map looking funky

Hi there,

I’m getting funky results when importing my normal maps and using them in a material with a Lit shader.

I’m creating the normal map at runtime, getting it from a web server. I’m not using UnityWebRequest.GetTexture, as I know that I need the texture to be linear.

I need the normal map to be imported as default texture type, not normal. What i’m “simulating” here is a texture imported at runtime from the web, where the option to import it as a normal map is not available. Here are the results:

Imported as default texture



Imported as normal map



Can someone help me understand why I’m getting this result? I remember doing the same thing with the Build-In RP and it worked fine. Can I not use normal maps this way with URP?

I’m using Unity 2021.3 with URP 12.1.15

Thanks!

I don’t get it? you want the normal map to be a default texture?

change the type at the top where it says Normal Map and don’t use the texture in the normal map slot

As I said, I can’t. The textures are loaded from a PNG on a web server. I’m creating the textures at runtime, so there is now “import them as normal maps”.

What i’m presenting here is just a “simulated” result of what i’m getting when using those runtime imported normal maps.

ok, what is the code are you using?

Hi, I did some digging on the topic and came across this post from another thread: Convert 2DTexture to Normal Map format realtime.

Hope this helps.

Blockquote ok, what is the code are you using?

This is the method I use for creating the textures from a base64 string representing a JPG or PNG image:

        private static bool TryFromBase64(
            string base64Str,
            out Texture2D output,
            TextureFormat format = RGBA32,
            bool mipChain = true,
            bool linear = true,
            bool compress = true,
            bool highQualityCompression = true,
            bool makeNoLongerReadable = true,
            FilterMode filterMode = FilterMode.Bilinear,
            int anisoLevel = 1)
        {
            output = null;

            if (string.IsNullOrEmpty(base64Str))
            {
                return false;
            }

            byte[] buffer = Convert.FromBase64String(base64Str);

            if (buffer.Length == 0)
            {
                return false;
            }

            output = new Texture2D(4, 4, format, mipChain, linear);
            bool success = output.LoadImage(buffer);

            if (!success)
            {
                output = null;
                return false;
            }

            if (compress)
            {
                output.Compress(highQualityCompression);
            }

            output.filterMode = filterMode;
            output.anisoLevel = anisoLevel;

            if (makeNoLongerReadable)
            {
                // LoadImage() creates a texture that is marked as readable. For performance reasons we should mark
                // it as non-readable as much as possible.
                output.Apply(mipChain, true);
            }

            return true;
        }

I don’t think this is related, I don’t manipulate the image, I just use it as it is.

Hi, I did some digging on the topic and came across this post from another thread: Convert 2DTexture to Normal Map format realtime.
Hope this helps.

Yeah, I stumbled this thread too, but didn’t find anything applicable to my problem. @bgolus mention the linear/sRGB thing but I already made extra sure that i’m creating linear textures for normal map.

EDIT: not to mention the fact that both my normal maps looks the same in the preview window, not like the example where the sRGB texture looks washed out:

default

normal

EDIT2: I don’t use UnityWebRequest.GetTexture, i’m getting the raw bytes.