UnityShader源码2017---学习笔记与自我拓展042

源自Skybox,Skybox-Cubed,Skybox-Procedural

先看一下SkyBox这个shader里的一个方法

float3 RotateAroundYInDegrees (float3 vertex, float degrees)
{
    float alpha = degrees * UNITY_PI / 180.0;
    float sina, cosa;
    sincos(alpha, sina, cosa);
    float2x2 m = float2x2(cosa, -sina, sina, cosa);
    return float3(mul(m, vertex.xz), vertex.y).xzy;
}

这就是个绕着Y轴旋转的方法。

里面用到的二维旋转矩阵,很简单也很明确,网上一堆资料推导。这就就省略了。

仔细看一下return那行,操作很骚。

 

接下来看一下unity_ColorSpaceDouble

#ifdef UNITY_COLORSPACE_GAMMA
#define unity_ColorSpaceDouble fixed4(2.0, 2.0, 2.0, 2.0)

#else // Linear values
#define unity_ColorSpaceDouble fixed4(4.59479380, 4.59479380, 4.59479380, 2.0)
#endif

定义了不同颜色空间下的一个常量值。

 

 

看一下一个有趣的方法skybox_frag,里面用到了DecodeHDR,用的参数是smpDecode,也就是(以frongTex为例)_FrontTex_HDR。

官方解释的很骚啊。完全地暧昧般的的暗示。

然而我还是不知道里面到底存了啥。。。。也没有google到。。。

 

找一下DecodeHDR的定义

// Decodes HDR textures
// handles dLDR, RGBM formats
inline half3 DecodeHDR (half4 data, half4 decodeInstructions)
{
    // Take into account texture alpha if decodeInstructions.w is true(the alpha value affects the RGB channels)
    half alpha = decodeInstructions.w * (data.a - 1.0) + 1.0;

    // If Linear mode is not supported we can skip exponent part
    #if defined(UNITY_COLORSPACE_GAMMA)
        return (decodeInstructions.x * alpha) * data.rgb;
    #else
    #   if defined(UNITY_USE_NATIVE_HDR)
            return decodeInstructions.x * data.rgb; // Multiplier for future HDRI relative to absolute conversion.
    #   else
            return (decodeInstructions.x * pow(alpha, decodeInstructions.y)) * data.rgb;
    #   endif
    #endif
}

先看一下方法体里的第一个注释。

他说decodeInstructions.w存的是一个可以知道是否alpha通道可以影响RGB的一个值。

decodeInstructions这个就是我们的{TexutexName}_HDR,之后我之间用例子_FrontTex_HDR代替了

就是说_FrontTex_HDR.w如果值不是0就要考虑alpha对rgb的影响。(RGBM)

half alpha = decodeInstructions.w * (data.a - 1.0) + 1.0;

这个操作就很明显了,

如果w分量是0,alpha=1,

如果w分量是1,alpha=data.a。

如果w分量是0.5。。。。非要这么megic的话。。。自己看效果。。高兴就好。。

然后,继续看着看着。突然发现了一点,似乎之前探讨过(unity_Lightmap_HDR)这个问题。链接在这里

 

这个Skybox-Cubed shader里没有特殊亮点。

Skybox-Procedural  这个shader。。。。

也不想说什么,感兴趣的去shadertoy里多研究研究就好了,这个shader就是unityi默认天空盒的shader

 

 

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值