Question about UNORM and sRGB Render Texture formats when generating Noise from Compute Shader

Hello!

I have been learning how to generate noise textures with compute shaders and have run into an issue that doesn’t make sense to my expectations and understanding of working with Linear colour space and textures.

The problem exists that I want to generate my textures as linear colour space textures but Unity is requiring me to import the final texture as an sRGB texture to display the noise correctly. My understanding is that because noise is data it should be generated and imported as a linear texture.

I have set up a few examples of what I am seeing using a simple gradient generated from a compute shader.

Here is the basic set up:

The compute shader:

#pragma kernel SimpleGradient

RWTexture2D<float4> Result2D;

int SquareResolution;


[numthreads(16, 16, 1)]
void SimpleGradient(uint3 id: SV_DispatchThreadID)
{
    float2 gradients = id.xy / (float)SquareResolution;

    Result2D[id.xy] = gradients.x;
}

Render Texture generation code:

        public override RenderTexture CreateRenderTexture()
        {
            GraphicsFormat format = GraphicsFormat.R8G8B8A8_UNorm;
            RenderTexture renderTexture = new RenderTexture(rwTexture.squareResolution, rwTexture.squareResolution, 0, format);
            renderTexture.enableRandomWrite = true;
            renderTexture.name = name;
            renderTexture.wrapMode = TextureWrapMode.Repeat;
            renderTexture.filterMode = FilterMode.Bilinear;

            renderTexture.Create();

            return renderTexture;
        }

Convert, save and re-import the Render Texture code:

        public static void SaveTexture2D(RenderTexture rt, string AssetName)
        {
            Initialize(rt);

            Texture2D newTexture = ConvertFrom2DRenderTexture();
            string path = assetPath + AssetName + ".png";

            MDebug.LogPurple($"SaveTexture2D() {newTexture} at {path}");

            // other wway of writing to texture
            File.WriteAllBytes(path, newTexture.EncodeToPNG());
            UnityEngine.Object.DestroyImmediate(newTexture);
            ReimportTexture(path);

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

        }

        static Texture2D ConvertFrom2DRenderTexture()
        {
            // intitalize our new texture
            int squareResolution = ActiveRenderTexture.width;
            bool mipChain = false;
            bool linear = true;

            Texture2D output = new Texture2D(squareResolution, squareResolution, TextureFormat.RGBA32, mipChain, linear);

            // set our RT to active to read from it
            RenderTexture.active = ActiveRenderTexture;
            output.ReadPixels(new Rect(0, 0, squareResolution, squareResolution), 0, 0);
            output.Apply();

            return output;

        }

        static void ReimportTexture(string path)
        {
            TextureImporter texImporter = AssetImporter.GetAtPath(path) as TextureImporter;

            if (texImporter != null)
            {
                texImporter.textureType = TextureImporterType.Default;
                texImporter.sRGBTexture = false;

                texImporter.mipmapEnabled = false;
                texImporter.filterMode = FilterMode.Bilinear;
                texImporter.isReadable = true;

                texImporter.textureCompression = TextureImporterCompression.Uncompressed;

                MDebug.LogPurple($"ReimportTexture() {texImporter.sRGBTexture}, {texImporter.mipmapEnabled}, {texImporter.textureCompression}");

                EditorUtility.SetDirty(texImporter);
                texImporter.SaveAndReimport();
            }
        }

Regardless of whether I generate my Render Texture as GraphicsFormat.R8G8B8A8_UNorm or
GraphicsFormat.R8G8B8A8_SRGB the final Texture2D is in the same colour sRGB colour space anbd requires the sRGB conversion to display correctly:

Here I have generated the texture using both Graphics Formats and toggling the sRGB flag in the texture import settings:

I am using Unity 2021.1.13 and the quads are being rendered with an UnlitTexture shader

What am I missing here? Shouldn’t the UNORM texture imported as linear be a linear gradient?

Any help would be greatly appreciated!

Never mind I was getting confused by perception!