About Gamma Correction

Hi, everyone, I am confused that the result between Unity gamma correction(Edit-Project Settings-Player-Other Settings-ColorSpace) and handmake gamma correction in shader is entirely different.
My handmake gamma correction did as followed:

float4 Gamma2Linear(float4 c)
{
return pow(c, 2.2);
}

float4 Linear2Gamma(float4 c)
{
return pow(c, 1.0 / 2.2);
}

Could any one help? Thank you very much!

I presume it happens because of that calculations for lightDir, normalDir etc are made in respective color space (for gamma in gamma, for linear in linear). I’m not really good at shader programming, so try reading this:
http://gamedev.stackexchange.com/questions/74324/gamma-space-and-linear-space-with-shader
I also want badly to achieve linear space look in gamma, and tried the method you suggested already:)
But, it doesn’t work. If you manage to make such a shader - I would really appreciate if you share it :slight_smile:

Thank you very much, edredar!
Finally, I found that pow(c, 2.2) is correct. It is a little different between pow(2.2) and unity builtin gamma correction pipeline, but it’s negligible.
The problem that I said “entirely different” caused by a stupid mistake. I compared two result on two LCD screens, and the “entirely different” came from the different color temperature(or contrast) between the two screens, but not gamma correction algorithm.

My experiment shader is very simple:

Shader "Custom/test" {
    Properties {
        _MainTex ("Albedo (RGB)", 2D) = "green" {}
        _Test ("test", Float) = 2.2
        _Color ("C", Color) = (1.0, 1.0,1.0,1.0)
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
     
        Pass
        {
            Name "FORWARD"
            Tags { "LightMode" = "ForwardBase" }
         
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
         
            #include "UnityCG.cginc"
            #include "Lighting.cginc"
         
            struct VS_OUTPUT
            {
                float4 pos : SV_POSITION;
                float2 uv    : TEXCOORD0;
            };
         
            uniform float _Test;
         
            float4 Gamma2Linear(float4 c)
            {
                return pow(c, _Test);
            }

            float4 Linear2Gamma(float4 c)
            {
                return pow(c, 1.0 / _Test);
            }
         
            VS_OUTPUT vert(appdata_tan i)
            {
                VS_OUTPUT o;
                o.pos = mul(UNITY_MATRIX_MVP, i.vertex);
                o.uv = i.texcoord.xy;
             
                return o;
            }
         
            uniform sampler _MainTex;
         
            float4 frag(VS_OUTPUT i): COLOR
            {
                float4 c = float4(i.uv.x, i.uv.x, i.uv.x, 1.0);

                return Linear2Gamma(c);
            }     
         
            ENDCG
        }
    }
    FallBack "Diffuse"
}

Thanks edredar again for your kind heart reply!