What happens to colors of a normal map when we sample them in shadergraph?

My original tangent space normal map is like this (light blue):
8230212--1075365--upload_2022-6-24_15-44-39.png

when I sample that in shadergraph or amplify shader editor it becomes more dark blue and its still in tangent space:

and when I try to bake this (or any other normal maps) from shader and save it to a file, the darker version will be saved.
P.S. The process of saving is done by applying normal result to BaseColor slot and Graphics.Blit into a renderTexture.

So what is the reason of darker colors and how I can have access to the light blue version to save it?

Part of the probable answer based on this video in OpenGL

RGB Colors are between 0 and 1.
Normal vectors are between -1 and 1.
So to convert RGB data to normal vectors, we need to multiply RGB values by 2 and subtract by 1.
This is probably what Sample node does to a normal map in shadergraph or amplify shader editor and in order to have the original texture data, we need to convert it back to values between 0 and 1 (add one and divide by 2)

this will get a close results to the original texture, but not the exact same one.
Not sure why…

1 Like

You can just set the Type of the Sample Texture 2D node to Default.

1 Like

Yes, but I want to keep it in normal mode cuz this method only works if the texture is not set to Normal map in import setting. And this is not always desired.

Ok, I have found the solution.
The result of the formula is the correct one. when I tried to save the texture and compare, that I was using:

RenderTexture.GetTemporary(resolution.x, resolution.y);

This renderTexture is in sRGB color space and the original texture was made in linear space.
so when I render in Linear space using:

new RenderTexture(resolution.x, resolution.y, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);

the rendered png texture is almost exactly the same as the original one.