Clip(x):如果X<0,则舍弃掉此片段
溶解效果
修改溶解效果的Tilling Offset
Shader "taecg/Character Unlit"
{
properties
{
[ Header (Base) ]
[NoScaleOffset] _MainTex ( "MainTex" , 2D ) = "White" { }
_Color ( "Color",color ) = (0,0,0,0)
[ Space (10) ]
[ Header (Dissolve) ]
_DissovlveTex(DissolveTex(R)", 2D ) = "White" { }
_Clip ( "Clip",Range(0,1)) = 0
}
SubShader
{
pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG/cginc"
spmpler 2D _MainTex;
fixed4 _color ;
sampler2D _DissolveTex;float4_DissolveTex_ST;
fixed _Clip;
struct appdata
{
float4 vertex : POSITION ;
float4 uv : TEXCOORD1;
} ;
struct v2f
{
float4 pos : SV_POSITION ;
float4 uv : TEXCOORD;
} ;
v2f vert (appdata v)
{
v2f o ;
o.pos = UnityObjectToClipPos ( v.vertex ) ;
o.uv.xy = v.uv.xy ;
// o.uv.zw = v.uv * DissolveTex_ST.xy+_DissolveTex_ST.zw ;
o.uv.zw = TRANSFORM_TEX( v.uv , _DissolveTex );
return 0 ;
}
fixed4 frag (v2f i) : sv_TARGET
{
fixed4 c;
fixed4 tex = tex2D( _MainTex, i.uv.xy);
c = tex ;
c + = _Color;
fixed4 dissolveTex = tex2D( _DissolveTex,i.uv.zw);
Clip( dissolveTex .r - _Clip );
return c;
}
ENGCG
}
}
}
希望体现火烧效果
溶解边缘有不同颜色变化
smoothstep ( min, max, x ) 在两个值之间进行平滑过渡 高消耗
saturate (x)线性过渡 低消耗
float smoothstep(min,max,x)
{
float t=saturate(x-min)/(max-min);
return t*t*(3-2*t);
}
溶解原理:
Shader "taecg/Character Unlit"
{
properties
{
[ Header (Base) ]
[NoScaleOffset] _MainTex ( "MainTex" , 2D ) = "White" { }
_Color ( "Color",color ) = (0,0,0,0)
[ Space (10) ]
[ Header (Dissolve) ]
_DissovlveTex(DissolveTex(R)", 2D ) = "White" { }
[ NoScaleOffset ]_RampTex ( " RampTex( RGB ) " ,2D ) = "White" { }
_Clip ( "Clip",Range(0,1)) = 0
}
SubShader
{
pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG/cginc"
spmpler 2D _MainTex;
fixed4 _color ;
sampler2D _DissolveTex;float4_DissolveTex_ST ;
sampler _RampTex ;
fixed _Clip;
struct appdata
{
float4 vertex : POSITION ;
float4 uv : TEXCOORD1;
} ;
struct v2f
{
float4 pos : SV_POSITION ;
float4 uv : TEXCOORD;
} ;
v2f vert (appdata v)
{
v2f o ;
o.pos = UnityObjectToClipPos ( v.vertex ) ;
o.uv.xy = v.uv.xy ;
// o.uv.zw = v.uv * DissolveTex_ST.xy+_DissolveTex_ST.zw ;
o.uv.zw = TRANSFORM_TEX( v.uv , _DissolveTex );
return 0 ;
}
fixed4 frag (v2f i) : sv_TARGET
{
fixed4 c;
fixed4 tex = tex2D( _MainTex, i.uv.xy);
c = tex ;
c + = _Color;
fixed4 dissolveTex = tex2D( _DissolveTex,i.uv.zw);
Clip( dissolveTex .r - _Clip );
fixed dissolveValue = saturate (( dissolveTex.r - _Clip ) / ( _Clip + 0.1 - _Clip )) ;
fixed4 rampTex = tex1D(_RampTex , dissolveValue ) ;
c+ = rampTex ;
return c ;
}
ENGCG
}
}
}
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- igbc.cn 版权所有 湘ICP备2023023988号-5
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务