栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 游戏开发 > 其他

Unity Shader 2D图片 溶解

其他 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Unity Shader 2D图片 溶解

 

 

Shader "TintDissolve"
{
	Properties
	{
		[PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
		_Color("Tint", Color) = (1,1,1,1)
		[MaterialToggle] PixelSnap("Pixel snap", Float) = 0
		[HideInInspector] _RendererColor("RendererColor", Color) = (1,1,1,1)
		[HideInInspector] _Flip("Flip", Vector) = (1,1,1,1)
		[PerRendererData] _AlphaTex("External Alpha", 2D) = "white" {}
		[PerRendererData] _EnableExternalAlpha("Enable External Alpha", Float) = 0

		_DissolveTex("Dissolve Overlay", 2D) = "white" {}
		_EmissionColor("Emission Color", color) = (1,1,1,1)
		_EmissionThickness("Emission Thickness", Range(0, 1)) = 0
		_DissolvePower("Dissolve Power", Range(0, 1)) = 1
	}

	SubShader
	{
		Tags
		{
			"Queue" = "Transparent"
			"IgnoreProjector" = "True"
			"RenderType" = "Transparent"
			"PreviewType" = "Plane"
			"CanUseSpriteAtlas" = "True"
		}

		Cull Off
		Lighting Off
		ZWrite Off
		Blend One OneMinusSrcAlpha

		Pass
		{
		CGPROGRAM
			#pragma vertex SpriteVert_Dissolve
			#pragma fragment SpriteFrag_Dissolve
			#pragma target 2.0
			#pragma multi_compile_instancing
			#pragma multi_compile_local _ PIXELSNAP_ON
			#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
			#include "UnitySprites.cginc"

			sampler2D _DissolveTex;
			float4 _DissolveTex_ST;

			fixed4 _EmissionColor;
			fixed _EmissionThickness;
			fixed _DissolvePower; //start at 1 then gradually to 0

			struct v2fExt
			{
				float4 vertex   : SV_POSITION;
				fixed4 color : COLOR;
				float2 texcoord : TEXCOORD0;
				float2 texcoord2 : TEXCOORD1;
				UNITY_VERTEX_OUTPUT_STEREO
			};

			v2fExt SpriteVert_Dissolve(appdata_t IN)
			{
				v2fExt OUT;

				UNITY_SETUP_INSTANCE_ID(IN);
				UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);

				OUT.vertex = UnityFlipSprite(IN.vertex, _Flip);
				OUT.vertex = UnityObjectToClipPos(OUT.vertex);
				OUT.texcoord = IN.texcoord;
				OUT.color = IN.color * _Color * _RendererColor;

				#ifdef PIXELSNAP_ON
				OUT.vertex = UnityPixelSnap(OUT.vertex);
				#endif

				//coord for dissolve to accomodate texture scale/offset
				OUT.texcoord2 = IN.texcoord * _DissolveTex_ST.xy + _DissolveTex_ST.zw;

				return OUT;
			}

			fixed4 SpriteFrag_Dissolve(v2fExt IN) : COLOR
			{
				fixed4 clr = SampleSpriteTexture(IN.texcoord) * IN.color;
				fixed mask = tex2D(_DissolveTex, IN.texcoord2).r;

				fixed4 blend = fixed4(0,0,0,0);
				if (mask < _DissolvePower + _EmissionThickness)
					blend = fixed4(_EmissionColor.r, _EmissionColor.g, _EmissionColor.b, clr.a);
				if (mask <= _DissolvePower)
					blend = clr;

				blend.rgb *= blend.a;

				return blend;
			}
		ENDCG
		}
	}
}

素材:

 

ASE:

 

素材:

 

 

 

 

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/901480.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号