unity 过滤UI纯色背景

30 篇文章 0 订阅

新建一个shader和材质球 把shader赋值给材质球

Shader "Custom/ChromaKey" {

	Properties{
		_MainTex("Base (RGB)", 2D) = "white" {}
		_thresh("Threshold", Range(0, 16)) = 0.8
		_slope("Slope", Range(0, 1)) = 0.2
		_keyingColor("Key Colour", Color) = (1,1,1,1)
	}

		SubShader{
			Tags {"Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent"}
			LOD 100

			Lighting Off
			ZWrite Off
			AlphaTest Off
			Blend SrcAlpha OneMinusSrcAlpha

			Pass {
				CGPROGRAM
					#pragma vertex vert_img
					#pragma fragment frag
					#pragma fragmentoption ARB_precision_hint_fastest

					sampler2D _MainTex;
					float3 _keyingColor;
					float _thresh; // 0.8
					float _slope; // 0.2

					#include "UnityCG.cginc"

				   float4 frag(v2f_img i) : COLOR{
				  float3 input_color = tex2D(_MainTex,i.uv).rgb;
				  float d = abs(length(abs(_keyingColor.rgb - input_color.rgb)));
				  float edge0 = _thresh * (1 - _slope);
				  float alpha = smoothstep(edge0,_thresh,d);
				  return float4(input_color,alpha);


				  }

				ENDCG
			}
		}

			FallBack "Unlit/Texture"
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值