Unity 溶解效果软硬描边

这版文章是我上一篇文章的进阶版,之前那版只有基础功能,当前这版可以选择是否自定义颜色

上一篇链接:https://blog.csdn.net/haseef520s/article/details/118230584

废话不多说直接上效果图

Shader "Custom/Disslove" 
{
    Properties
    {
        _MainTex("MainTex", 2D) = "white" {}
        _NoiseTex("NoiseTex", 2D) = "white" {}
        _EdgeWidth("EdgeWidth", Range( 0 , 1)) = 0
        _Dissolve("Dissolve", Range( 0.0001 , 1)) = 0.1643941
        [Toggle(CustomColor)]_IsCustom("自定义颜色",float)=0
        _DissolveColor("DissolveColor",Color) = (1,1,1,1)
    }
    
    SubShader {
        Tags {
            "IgnoreProjector"="True"
            "Queue"="Transparent"
            "RenderType"="Transparent"
        }
        Pass {
            Blend SrcAlpha OneMinusSrcAlpha
            Cull Off
            ZWrite Off
            
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"
            #pragma target 2.0
            uniform sampler2D _NoiseTex;
            uniform float _Dissolve;
            uniform float _EdgeWidth;
            uniform sampler2D _MainTex;
            float4 _DissolveColor;
            float _IsCustom;
            struct VertexInput {
                float4 vertex : POSITION;
                float2 uv0 : TEXCOORD0;
                float4 uv1 : TEXCOORD1;
                float4 uv2 : TEXCOORD2;
                float4 vertexColor : COLOR;
            };
            struct VertexOutput {
                float4 pos : SV_POSITION;
                float2 uv0 : TEXCOORD0;
                float4 uv1 : TEXCOORD1;
                float4 uv2 : TEXCOORD2;
                float4 vertexColor : COLOR;
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.uv0 = v.uv0;
                o.uv1 = v.uv1;
                o.uv2 = v.uv2;
                o.vertexColor = v.vertexColor;
                o.pos = UnityObjectToClipPos( v.vertex );
                return o;
            }
            float4 frag(VertexOutput i) : COLOR {
                float4 noiseTex = tex2D( _NoiseTex,  i.uv0 );
                float4 mainTex = tex2D( _MainTex,  i.uv0 );
                float percent = saturate((noiseTex.r - _Dissolve)/(_EdgeWidth*_Dissolve));
                float3 finalColor = lerp(mainTex.rgb, _DissolveColor,step(percent,0.8)*_IsCustom);
                return fixed4(finalColor,percent*mainTex.a);
            }
            ENDCG
        }
    }
}

step(percent,0.8)   这小段代码逻辑是当前半透明度<=0.8即认为是溶解边缘 当然这个值可以根据大家实际情况做出来调整. 大家也可以把溶解颜色替换成纹理图都可!希望对大家有帮助.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值