关于Unity里的ColorSpace

Gamma和Linear是目前两种可选的colorspace,  Linear需要OpenGL3.0支持,目前大部分手机已经支持。默认就是Gamma形式,以下介绍在Unity实现Linear方式:

1. 手动在Shader中设置,使用官方提供的两个函数:

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直接切换

在PlayerSetting中选择Linear. 

 

由于Shader始终使用linear形式采样,在使用Unity Linear时,如果非32位的贴图时,PS生成的是图是gamma的,所以导入时如果不选sRGB,会被默认转成linear的形式,如果一张(127,0,0,0)的图,会被转成(187,0,0,0),即进行了一次gamma矫正(^1/gamma)。

 

相关参考文章:

https://blog.csdn.net/u012871784/article/details/78701996

https://www.jianshu.com/p/9a91e6ad0d38

https://docs.unity3d.com/Manual/LinearRendering-LinearOrGammaWorkflow.html

转载于:https://my.oschina.net/u/138823/blog/3062245

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值