182 lines
6.6 KiB
GLSL
182 lines
6.6 KiB
GLSL
Shader "BF/Effect/eff_dissolve_add"
|
|
{
|
|
Properties
|
|
{
|
|
[Enum(CullMode)] _CULLENUM("剔除模式", int) = 0
|
|
[Enum(show_all,0,hide_cut,4,show_cut,7)]_ztest_on("遮挡显示",int)=4
|
|
|
|
[Space(8)]
|
|
[Header(texture _____________________________________________________________)]
|
|
[Space(2)]
|
|
|
|
[HDR]_tex_color("贴图颜色", Color) = (1, 1, 1, 1)
|
|
_tex("贴图", 2D) = "white" {}
|
|
_tex_uv_speed("贴图UV速度向量", Vector) = (0,0,0,0)
|
|
_tex_rotate("贴图旋转【0到360°】", Range(0, 360)) = 0
|
|
_tex_mask("贴图遮罩", 2D) = "white" {}
|
|
[Toggle(_MASK_UV_SPEED_CUSTOM)]_MASK_UV_SPEED_CUSTOM("粒子custom1.zw(uv1.xy)控制mask uv偏移",int) = 0
|
|
_tex_mask_uv_speed("贴图遮罩UV速度向量", Vector) = (0,0,0,0)
|
|
_tex_mask_rotate("贴图遮罩旋转【0到360°】", Range(0, 360)) = 0
|
|
|
|
[Space(8)]
|
|
[Header(dissove _____________________________________________________________)]
|
|
[Space(2)]
|
|
_diss_tex("溶解贴图", 2D) = "white"{}
|
|
_diss_tex_rotate("溶解贴图旋转【0到360°】", Range(0, 360)) = 0
|
|
[ScaleOffset] _diss_tex_offset("溶解贴图偏移", Vector) = (0, 0, 0, 0)
|
|
[HDR]_diss_edge_color("溶解边颜色", Color) = (1, 1, 1, 1)
|
|
_diss_edge_width("溶解边宽度", Range(0,1)) = 0.01
|
|
_diss_edge_smoothness("溶解边外侧平滑", Range(0, 3)) = 1.8
|
|
_diss_smoothness("溶解边内侧平滑", Range(0, 1)) = 0.01
|
|
[IntRange]_diss_alpha_clip("溶解使用alpha做阀值", Range(0, 1)) = 0
|
|
_diss_clip("溶解阀值", Range(-0.2,1.2)) = 0.2
|
|
}
|
|
|
|
CGINCLUDE
|
|
#include "UnityCG.cginc"
|
|
struct a2v{
|
|
float4 vertex : POSITION;
|
|
float4 normal : NORMAL;
|
|
float4 color :COLOR;
|
|
float4 uv : TEXCOORD0;
|
|
#if _MASK_UV_SPEED_CUSTOM
|
|
float4 uv1 : TEXCOORD1;
|
|
#endif
|
|
};
|
|
struct v2f{
|
|
float4 pos : SV_POSITION;
|
|
fixed4 color :COLOR;
|
|
fixed2 uv_tex:TEXCOORD0;
|
|
fixed2 uv_tex_mask :TEXCOORD1;
|
|
fixed2 uv_dissiove : TEXCOORD2;
|
|
fixed4 uv_custom : TEXCOORD3;
|
|
};
|
|
|
|
//tex
|
|
fixed4 _tex_color;
|
|
sampler2D _tex;
|
|
float4 _tex_ST;
|
|
float4 _tex_uv_speed;
|
|
float _tex_rotate;
|
|
sampler _tex_mask;
|
|
float4 _tex_mask_ST;
|
|
float4 _tex_mask_uv_speed;
|
|
float _tex_mask_rotate;
|
|
|
|
//dissolve
|
|
sampler2D _diss_tex;
|
|
float4 _diss_tex_ST;
|
|
float _diss_tex_rotate;
|
|
int _diss_alpha_clip;
|
|
half _diss_clip;
|
|
half _diss_smoothness;
|
|
float4 _diss_edge_color;
|
|
float _diss_edge_width;
|
|
float _diss_edge_smoothness;
|
|
float2 _diss_tex_offset;
|
|
|
|
v2f vert(a2v v){
|
|
v2f o;
|
|
UNITY_INITIALIZE_OUTPUT(v2f, o);
|
|
// common.
|
|
o.pos = UnityObjectToClipPos(v.vertex);
|
|
|
|
o.uv_custom.xy = v.uv.zw;
|
|
#if _MASK_UV_SPEED_CUSTOM
|
|
o.uv_custom.zw = v.uv1.xy;
|
|
#endif
|
|
|
|
// tex
|
|
o.color = v.color;
|
|
o.uv_tex = TRANSFORM_TEX(v.uv,_tex);
|
|
o.uv_tex_mask = TRANSFORM_TEX(v.uv,_tex_mask);
|
|
// dissove
|
|
o.uv_dissiove = TRANSFORM_TEX(v.uv, _diss_tex) + frac(_diss_tex_offset.xy * _Time.y);
|
|
return o;
|
|
}
|
|
|
|
fixed4 frag(v2f i):SV_Target
|
|
{
|
|
const fixed3 tbl = float3(0.299,0.587,0.114);
|
|
fixed4 col = fixed4(0,0,0,1);//i.color;//fixed4(1,1,1,1);
|
|
|
|
// main texture.
|
|
fixed2 uv = i.uv_tex;
|
|
if(_tex_rotate > 0.1)
|
|
{
|
|
float angle = 3.1415926/180*_tex_rotate;
|
|
float2 temp_uv = (uv-_tex_ST.zw)/_tex_ST.xy - float2(0.5,0.5);// - float2(_tex_ST.x, _tex_ST.y) * 0.5;
|
|
uv.x = temp_uv.x * cos(angle) + temp_uv.y * sin(angle);
|
|
uv.y = -temp_uv.x * sin(angle) + temp_uv.y * cos(angle);
|
|
uv = (uv+float2(0.5,0.5))*_tex_ST.xy + _tex_ST.zw;//uv += float2(_tex_ST.x, _tex_ST.y) * 0.5;
|
|
}
|
|
col = tex2D(_tex,uv + frac(_Time.y * _tex_uv_speed.xy) + i.uv_custom.xy);
|
|
col *= _tex_color*i.color;
|
|
//++
|
|
uv = i.uv_tex_mask;
|
|
if(_tex_mask_rotate > 0.1)
|
|
{
|
|
float angle = 3.1415926/180*_tex_mask_rotate;
|
|
float2 temp_uv = (uv-_tex_mask_ST.zw)/_tex_mask_ST.xy - float2(0.5,0.5);// - float2(_tex_mask_ST.x, _tex_mask_ST.y) * 0.5;
|
|
uv.x = temp_uv.x * cos(angle) + temp_uv.y * sin(angle);
|
|
uv.y = -temp_uv.x * sin(angle) + temp_uv.y * cos(angle);
|
|
uv = (uv+float2(0.5,0.5))*_tex_mask_ST.xy + _tex_mask_ST.zw;//uv += float2(_tex_mask_ST.x, _tex_mask_ST.y) * 0.5;
|
|
}
|
|
|
|
#if _MASK_UV_SPEED_CUSTOM
|
|
fixed4 mask = tex2D(_tex_mask,uv + frac(_Time.y * _tex_mask_uv_speed.xy) + i.uv_custom.zw);
|
|
#else
|
|
fixed4 mask = tex2D(_tex_mask,uv + frac(_Time.y * _tex_mask_uv_speed.xy));
|
|
#endif
|
|
fixed mask_key = dot(mask.rgb,tbl)*mask.a;
|
|
col.a *= mask_key;
|
|
|
|
fixed2 uv_dissiove = i.uv_dissiove;
|
|
if(_diss_tex_rotate > 0.1)
|
|
{
|
|
float angle = 3.1415926/180*_diss_tex_rotate;
|
|
float2 temp_uv = (uv_dissiove-_diss_tex_ST.zw)/_diss_tex_ST.xy - float2(0.5,0.5);// - float2(_diss_tex_ST.x, _diss_tex_ST.y) * 0.5;
|
|
uv_dissiove.x = temp_uv.x * cos(angle) + temp_uv.y * sin(angle);
|
|
uv_dissiove.y = -temp_uv.x * sin(angle) + temp_uv.y * cos(angle);
|
|
uv_dissiove = (uv_dissiove+float2(0.5,0.5))*_diss_tex_ST.xy + _diss_tex_ST.zw;//uv_dissiove += float2(_diss_tex_ST.x, _diss_tex_ST.y) * 0.5;
|
|
}
|
|
fixed4 dissove_clr = tex2D(_diss_tex, uv_dissiove);
|
|
fixed dissove = dot(dissove_clr.rgb,tbl);//*dissove_clr.a;
|
|
|
|
float dc = ((1.0-i.color.a)*step(0.001, i.color.a))*step(1, _diss_alpha_clip) + _diss_clip*step(_diss_alpha_clip, 0);
|
|
|
|
float dissove_offset = dissove - dc;
|
|
clip(dissove_offset);
|
|
float edge_area = saturate(1 - saturate((dissove_offset - _diss_edge_width) / max(0.00001, _diss_smoothness))) * step(0.0001,dc);
|
|
float clr_edge_area = _diss_edge_color.a*edge_area;
|
|
col.rgb = col.rgb * (1 - clr_edge_area)+ _diss_edge_color.rgb * clr_edge_area;
|
|
col.a = col.a*((1.0-edge_area) + _diss_edge_color.a*edge_area*saturate(pow(dissove_offset / max(0.00001, _diss_edge_width), _diss_edge_smoothness)));
|
|
|
|
return col;
|
|
}
|
|
|
|
ENDCG
|
|
|
|
SubShader
|
|
{
|
|
Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent"}
|
|
ZTest LEqual
|
|
ZWrite Off
|
|
|
|
CULL [_CULLENUM]
|
|
|
|
Pass
|
|
{
|
|
COLORMASK RGBA
|
|
Blend SrcAlpha One //[_src_blend_factory] [_dst_blend_factory]
|
|
|
|
CGPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
|
|
#pragma shader_feature_local _MASK_UV_SPEED_CUSTOM
|
|
|
|
ENDCG
|
|
}
|
|
}
|
|
} |