Gamma和Linear是目前两种可选的colorspace, Linear须要OpenGL3.0支持,目前大部分手机已经支持。默认就是Gamma形式,如下介绍在Unity实现Linear方式:html
1. 手动在Shader中设置,使用官方提供的两个函数:app
inline half3 GammaToLinearSpace (half3 sRGB) { // Approximate version from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1 return sRGB * (sRGB * (sRGB * 0.305306011h + 0.682171111h) + 0.012522878h); // Precise version, useful for debugging. //return half3(GammaToLinearSpaceExact(sRGB.r), GammaToLinearSpaceExact(sRGB.g), GammaToLinearSpaceExact(sRGB.b)); }
好比想让场景由Gamma转成linear的形式,参考简书中的过程,我理解为过程可简化为这样:函数
fixed4 frag (v2f i) : SV_Target { // sample the texture fixed4 col = tex2D(_MainTex, i.uv); col.rgb = GammaToLinearSpace(col.rgb); // 转换到Linear Space //TODO:Some shader codes here. col.rgb = LinearToGammaSpace(col.rgb* unity_ColorSpaceDouble); return col; }
2. 使用Unity的ColorSpace直接切换spa
在PlayerSetting中选择Linear. .net
因为Shader始终使用linear形式采样,在使用Unity Linear时,若是非32位的贴图时,PS生成的是图是gamma的,因此导入时若是不选sRGB,会被默认转成linear的形式,若是一张(127,0,0,0)的图,会被转成(187,0,0,0),即进行了一次gamma矫正(^1/gamma)。debug
相关参考文章:3d
https://blog.csdn.net/u012871784/article/details/78701996code
https://www.jianshu.com/p/9a91e6ad0d38htm
https://docs.unity3d.com/Manual/LinearRendering-LinearOrGammaWorkflow.htmlblog