【着色器实现Shine局部或整体扫光效果_Shader效果第三篇】

效果图如下

请添加图片描述

属性栏如下

带Shine Mask效果,可以实现Tex的部分Shine。
请添加图片描述

完整代码如下

Shader "XKB/Shine"
{
    Properties
    {
        _MainTex ("Main Texture", 2D) = "white" {}
		_Color("Main Color", Color) = (1,1,1,1)
		_Alpha("General Alpha",  Range(0,1)) = 1
        _ShineColor("Shine Color", Color) = (1,1,1,1)
        _ShineLocation("Shine Location", Range(0,1)) = 0.5
        _ShineRotate("Rotate Angle(radians)", Range(0, 6.2831)) = 0
        _ShineWidth("Shine Width", Range(0.05,1)) = 0.1
        _ShineGlow("Shine Glow", Range(0,100)) = 1
		[NoScaleOffset] _ShineMask("Shine Mask", 2D) = "white" {}
    }

    SubShader
    {
        Tags {"Queue" = "Transparent" "RenderType"="Opaque" "IgnoreProjector" = "True" }        
        Blend SrcAlpha OneMinusSrcAlpha
        ZWrite Off
        Cull Off
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
				half4 color : COLOR;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
				half4 color : COLOR;
            };

            sampler2D _MainTex;
            half4 _MainTex_ST, _MainTex_TexelSize, _Color;
			half _Alpha;
            float _RandomSeed;
			sampler2D _ShineMask;
			half4 _ShineColor;
			half _ShineLocation, _ShineRotate, _ShineWidth, _ShineGlow;
			
            v2f vert (appdata v)
            {
                v2f o;
				o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
				o.color = v.color;
                return o;
            }

            half4 frag (v2f i) : SV_Target
            {
				float2 uvRect = i.uv;
				half2 center = half2(0.5, 0.5);
				half2 centerTiled = half2(center.x *  _MainTex_ST.x, center.y *  _MainTex_ST.y);
				half4 col = tex2D(_MainTex, i.uv) * i.color;
				half originalAlpha = col.a;
				half2 uvShine = uvRect;
				half cosAngle = cos(_ShineRotate);
				half sinAngle = sin(_ShineRotate);
				half2x2 rot = half2x2(cosAngle, -sinAngle, sinAngle, cosAngle);
				uvShine -= half2(0.5, 0.5);
				uvShine = mul(rot, uvShine);
				uvShine += half2(0.5, 0.5);
				half shineMask = tex2D(_ShineMask, i.uv).a;
				half currentDistanceProjection = (uvShine.x + uvShine.y) / 2;
				half whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation) / _ShineWidth);
				col.rgb +=  col.a * whitePower * _ShineGlow * max(sign(currentDistanceProjection - (_ShineLocation - _ShineWidth)), 0.0)
				* max(sign((_ShineLocation + _ShineWidth) - currentDistanceProjection), 0.0) * _ShineColor * shineMask;
				col.a *= _Alpha;
				col *= _Color;
                return col;
            }
            ENDCG
        }
    }
	Fallback "Sprites/Default"
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

暴走约伯

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值