Shader "JianZe/CustomTransparent"
{
Properties
{
[Header(______________________ Blend Mode ______________________)]
[Enum(SrcAlpha,5)] _Src ("Src", Float) = 5
[Enum(One,1,OneMinusSrcAlpha,10)] _Dst ("Dst", Float) = 10
//主贴图
[Header(________________________ Main Module________________________)]
[Enum(material,0,custom1_xy,1)] _UVMain("UVMain", Float) = 0
[HDR]_MainColor("MainColor",Color)=(1,1,1,1)
[Enum(alpha,0,r,1)]_MainAlpha("MainAlpha", float)=0
_MainTex("MainTex", 2D) = "white" {}
_MainTexU("MainTexU",float)=0
_MainTexV("MainTexV",float)=0
[Header(___________________________Dissolve Module___________________________)]
[Toggle]_NoiseDissovle("NoiseDissovle",float)=1
[Toggle]_DissolveReverse("DissolveReverse",float)=0
[Enum(default,0,center,1,U,2,V,3)]_BlendDissolveMoudle("BlendDissolveMoudle",float)=0
[Enum(material,0,custom1_z,1)] _UVDissolve("UVDissolve", Float) = 0
[HDR]_EdgeColor("DissolveEdges",Color)=(1,1,1,1)
_NoiseTex("NoiseTex",2D)="white" {}
_NoiseTexU("NoiseTexU",float)=0
_NoiseTexV("NoiseTexV",float)=0
_Dissolve("Dissolve",Range(0,1))=0
_EdgeStrength("EdgesStrength",Range(0,0.5))=0
_EdgeWidth("EdgeWidth",Range(0,1))=0
_BlendStrength("BlendStrength",Range(0,1 ))=0.5
[Header(_________________________Mask Module___________________________)]
[Enum(material,0,custom2_xy,1)] _UVMask("UVMask", Float) = 0
[Enum(alpha,0,r,1)]_MaskAlpha("MaskAlpha", float)=1
_MaskMap("MaskMap",2D)="white" {}
_MaskTexH("MaskTexU",float)=0
_MaskMapV("MaskMapV",float)=0
[Header(_________________________Distort Module___________________________)]
_DistortTex("DistortTex",2D)="black" {}
_DistortMain("DistortMain",Range(0,1))=0
_DistortDissolve("DistortDissolve",Range(0,1))=0
_DistortU("DistortU",float)=0
_DistortV("DistortV",float)=0
[Header(_________________________Alpha Module____________________________)]
Alpha("Alpha",float)=1
}
SubShader
{
Tags { "Queue"="Transparent" "RenderType" = "Transparent" "IgnoreProjector" = "True" "RenderPipeline" = "UniversalPipeline" }
LOD 100
Pass
{
Name "Unlit"
Blend [_Src] [_Dst]
ZWrite off
ZTest LEqual
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles
#pragma exclude_renderers d3d11_9x
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
inline half remap(half x, half t1, half t2, half s1, half s2)
{
return (x - t1) / (t2 - t1) * (s2 - s1) + s1;
}
struct Attributes
{
float4 positionOS: POSITION;
float4 texcoord : TEXCOORD0;
float4 texcoord1: TEXCOORD1;
float4 texcoord2: TEXCOORD2;
float4 vertexColor:Color;
};
struct Varyings
{
float4 pos :SV_POSITION;
float4 vertexColor :TEXCOORD6;
float4 uv1 :TEXCOORD0;
float2 uv2 :TEXCOORD1;
float4 uv3 :TEXCOORD2;
float4 uv4 :TEXCOORD3;
float4 uv5 :TEXCOORD4;
float4 uv6 :TEXCOORD5;
};
CBUFFER_START(UnityPerMaterial)
half4 _EdgeColor;
half4 _MainTex_ST;
half4 _NoiseTex_ST;
half4 _MaskMap_ST;
half4 _FlowMap_ST;
half _Dissolve;
half _EdgeStrength;
half _EdgeWidth;
half _MainTexU;
half _MainTexV;
half _NoiseTexU;
half _NoiseTexV;
half4 _MainColor;
half _MaskTexH;
half _MaskTexV;
half4 _DistortTex_ST;
half _DistortMain;
half _DistortDissolve;
half _DistortU;
half _DistortV;
half _NoiseDissovle;
half _BlendDissolveMoudle;
half _MainAlpha;
half _MaskAlpha;
half _BlendStrength;
//Toggle
half _DissolveReverse;
half _UVMain;
half _UVDissolve;
// half _CustomNoiseFlowToggle;
half _UVMask;
half Alpha;
CBUFFER_END
TEXTURE2D (_MainTex);SAMPLER(sampler_MainTex);
TEXTURE2D (_NoiseTex);SAMPLER(sampler_NoiseTex);
TEXTURE2D (_MaskMap);SAMPLER(sampler_MaskMap);
TEXTURE2D (_DistortTex);SAMPLER(sampler_DistortTex);
Varyings vert(Attributes v)
{
Varyings o;
o.pos = TransformObjectToHClip(v.positionOS.xyz);
o.uv3=v.texcoord1;
o.uv4=v.texcoord2;
o.vertexColor=v.vertexColor;
//o.uv1.xy = TRANSFORM_TEX(v.texcoord.xy, _MainTex);
o.uv1.xy=((_UVMain==1)?(v.texcoord.xy*_MainTex_ST.xy+o.uv3.xy):(v.texcoord.xy*_MainTex_ST.xy+_MainTex_ST.zw));
//o.uv1.zw=TRANSFORM_TEX(v.texcoord.xy,_NoiseMapTex);
o.uv1.zw=(v.texcoord.xy*_NoiseTex_ST.xy+_NoiseTex_ST.zw);
// o.uv2.xy = TRANSFORM_TEX(v.texcoord.xy, _MaskMap);
o.uv2.xy=((_UVMask==1)?(v.texcoord.xy*_MaskMap_ST.xy+o.uv4.xy):(v.texcoord.xy*_MaskMap_ST.xy+_MaskMap_ST.zw));
o.uv5.xy=TRANSFORM_TEX(v.texcoord.xy,_FlowMap);
o.uv5.zw=TRANSFORM_TEX(v.texcoord.xy,_DistortTex);
o.uv6.xy=v.texcoord.xy;
o.uv6.zw=v.texcoord.xy;
return o;
}
half4 frag(Varyings i) : SV_Target
{
half3 final_color=half3(0,0,0);
half final_alpha=1;
half dissolve_progress=((_UVDissolve==1)?(i.uv3.z):(_Dissolve));
i.uv5.zw= i.uv5.zw+half2(_DistortU,_DistortV)*_Time.y;
half Distort_tex=saturate(SAMPLE_TEXTURE2D(_DistortTex,sampler_DistortTex,i.uv5.zw).r);
i.uv1.xy= i.uv1.xy+half2(Distort_tex,Distort_tex)*_DistortMain;
i.uv1.xy=i.uv1.xy+half2(_MainTexU,_MainTexV)*_Time.y;
i.uv1.zw= i.uv1.zw+half2(Distort_tex,Distort_tex)*_DistortDissolve;
i.uv1.zw=i.uv1.zw+half2(_NoiseTexU,_NoiseTexV)*_Time.y;
half4 base_Map = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.uv1.xy)*_MainColor;
i.uv2.xy=i.uv2.xy+half2(_MaskTexH,_MaskTexV)*_Time.y;
half2 base_Mask=SAMPLE_TEXTURE2D(_MaskMap,sampler_MaskMap,i.uv2.xy).ra;
half base_mask=((_MaskAlpha==1)?(base_Mask.x):(base_Mask.y));
final_alpha=((_MainAlpha==1)?(final_alpha*base_Map.r):(final_alpha*base_Map.a));
final_color+=base_Map;
//随机溶解
half noise_map=saturate(SAMPLE_TEXTURE2D(_NoiseTex,sampler_NoiseTex,i.uv1.zw).r);
half dissolve_horizontal=i.uv6.x;
half dissolve_vertical=i.uv6.y;
half distance_dir=length(i.uv6.zw-0.5)*2;
half final_noise=1;
final_noise=((_NoiseDissovle)? saturate(final_noise*noise_map):final_noise);
final_noise=((_BlendDissolveMoudle==2)? saturate(lerp(final_noise,dissolve_horizontal,_BlendStrength) ):final_noise);
final_noise=((_BlendDissolveMoudle==3)? saturate(lerp(final_noise,dissolve_vertical,_BlendStrength)):final_noise);
final_noise=((_BlendDissolveMoudle==1)? saturate(lerp(final_noise,distance_dir,_BlendStrength)):final_noise);
final_noise=((_DissolveReverse)? saturate(1-final_noise):final_noise);
final_noise+=1;
final_noise =saturate(final_noise-2*dissolve_progress);
half edge_strength=1-_EdgeStrength;
half rim1=smoothstep(_EdgeStrength,edge_strength,final_noise);
half rim2=smoothstep(_EdgeStrength,edge_strength,saturate(final_noise+remap(_EdgeWidth,0,1,0,_EdgeStrength)));
rim1=saturate(rim2-rim1);
half3 rim_color=_EdgeColor.rgb*rim1;
final_alpha=((_NoiseDissovle)?(final_alpha*rim2):(final_alpha));
final_color=((_NoiseDissovle)?(lerp(base_Map.xyz,rim_color,rim1)):(final_color))*i.vertexColor.xyz;
final_alpha*=base_mask;
final_alpha=saturate(final_alpha*i.vertexColor.a*Alpha);
return float4(final_color,final_alpha);
}
ENDHLSL
}
}
}
URP手撸基本基础功能
于 2023-03-08 11:02:02 首次发布