unity的shader总结(一)

unity的shader总结

  1. clip()函数可以丢弃掉一些不满足条件的像素
    比如clip(xx.a-0.3)将丢弃掉alpha值小于0.3的像素。
    并不需要随着片段着色器返回
    fixed4 frag (v2f i) : SV_Target
    {
    	fixed cutout = tex2D(_NoiseTex, i.uvNoiseTex).r;
    	clip(cutout - _Threshold);//这地方已经将像素丢掉了
    
    	fixed4 col = tex2D(_MainTex, i.uvMainTex);
    	return col;
    }
  2. lerp函数,
    lerp(a,b,w) 根据w返回a到b之间的插值
    a,b,w可以为标量也可以为向量,但是三者应该统一。且为向量时长度也需要统一。
    相当于
    float3 lerp(float3 a, float3 b, float w)
    {
        return a + w*(b-a);
    }

     

  3. saturate(x)的作用是如果x取值小于0,则返回值为0。如果x取值大于1,则返回值为1。若x在0到1之间,则直接返回x的值.
    fixed4 frag (v2f i) : SV_Target
    {
        
    	fixed cutout = tex2D(_NoiseTex, i.uvNoiseTex).r;
    	clip(cutout - _Threshold);
    
    	float degree = saturate((cutout - _Threshold) / _EdgeLength);//取一个0到1之间的值
    	fixed4 edgeColor = lerp(_EdgeFirstColor, _EdgeSecondColor, degree);//取中间值
    
        fixed4 col = tex2D(_MainTex, i.uvMainTex);
    
    	fixed4 finalColor = lerp(edgeColor, col, degree);
    	return fixed4(finalColor.rgb, 1);
    }
     

     

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值