321 lines
11 KiB
Plaintext
321 lines
11 KiB
Plaintext
Shader "NLD/Particles/shader_mix"
|
|
{
|
|
Properties
|
|
{
|
|
[Header(Option)]
|
|
// [Enum(UnityEngine.Rendering.BlendOp)] _BlendOp ("BlendOp", Float) = 0
|
|
[Enum(UnityEngine.Rendering.BlendMode)] _BlendSrc ("Blend mode Source", Int) = 5
|
|
[Enum(UnityEngine.Rendering.BlendMode)] _BlendDst ("Blend mode Destination", Int) = 10
|
|
|
|
[Enum(Off,0,On,1)] _ZWrite("ZWrite", Int) = 0
|
|
[Enum(UnityEngine.Rendering.CompareFunction)]_ZTestMode ("ZTestMode", Float) = 4
|
|
|
|
[Enum(UnityEngine.Rendering.CullMode)]_CullMode ("CullMode", float) = 0
|
|
|
|
_AlphaClip("AlphaClip", Range(0, 1.0)) = 0.1
|
|
|
|
[Header(Custom)]
|
|
[MainTexture] _BaseMap("主贴图", 2D) = "white" {}
|
|
[HDR][MainColor] _BaseColor("主贴图颜色", Color) = (1,1,1,1)
|
|
_BaseColorScale("主贴图颜色强度", Float) = 1
|
|
_UVMoveX("主贴图 UV移动X", Float) = 0
|
|
_UVMoveY("主贴图 UV移动Y", Float) = 0
|
|
|
|
[MaterialToggle(_TEX2_ON)] _Toggle2("附加贴图 启用", Float) = 0
|
|
_BaseMap2("附加贴图", 2D) = "white" {}
|
|
[HDR] _BaseColor2("附加贴图 颜色", Color) = (1,1,1,1)
|
|
_BlendProgress("附加贴图 混合进度", Range(0, 1.0)) = 0.5
|
|
_UVMove2X("附加贴图 UV移动X", Float) = 0
|
|
_UVMove2Y("附加贴图 UV移动Y", Float) = 0
|
|
|
|
[MaterialToggle(_DISTORTION_ON)] _Toggle3("扭曲 启用", Float) = 0
|
|
_DistortionMap("扭曲贴图", 2D) = "white" {}
|
|
_DistortionMaxStrength("扭曲 强度", Float) = 0.1
|
|
_DistortionStrength("扭曲 强度", Range(-1,1)) = 0
|
|
_DistortionMoveX("扭曲 UV流动X", Float) = 1
|
|
_DistortionMoveY("扭曲 UV流动Y", Float) = 1
|
|
|
|
[MaterialToggle(_MASK_ON)] _Toggle4("Alpha遮罩 启用", Float) = 0
|
|
_MaskMap("Alpha遮罩贴图", 2D) = "white" {}
|
|
_MaskStrength("Alpha遮罩 强度", Range(0, 1.0)) = 0.1
|
|
_MaskMoveX("Alpha遮罩 UV流动X", Float) = 1
|
|
_MaskMoveY("Alpha遮罩 UV流动Y", Float) = 1
|
|
|
|
[MaterialToggle(_DISSOLVE_ON)] _Toggle5("溶解 启用", Float) = 0
|
|
_DissolveMap("溶解贴图", 2D) = "white" {}
|
|
_DissolveLength("溶解 范围", Range(0, 1.0)) = 0.1
|
|
_DissolveProgress("溶解 进度", Range(0, 1.0)) = 0
|
|
|
|
[MaterialToggle(_POLAR_ON)] _Toggle6("极坐标 启用", Float) = 0
|
|
_PolarScale("极坐标 缩放", Range(-1, 5)) = 0
|
|
|
|
[MaterialToggle(_CUSTOMDATA_ON)] _Toggle1("使用粒子 Custom Data", Float) = 0
|
|
|
|
}
|
|
SubShader
|
|
{
|
|
Tags
|
|
{
|
|
"RenderType" = "Transparent"
|
|
"Queue"="Transparent"
|
|
"PreviewType" = "Plane"
|
|
"RenderPipeline" = "UniversalPipeline"
|
|
}
|
|
|
|
Pass
|
|
{
|
|
Name "Universal Forward"
|
|
Tags
|
|
{
|
|
// none
|
|
}
|
|
|
|
Cull [_CullMode]
|
|
ZWrite [_ZWrite]
|
|
ZTest [_ZTestMode]
|
|
// BlendOp [_BlendOp]
|
|
Blend [_BlendSrc] [_BlendDst]
|
|
// AlphaToMask On
|
|
|
|
HLSLPROGRAM
|
|
#pragma target 3.0
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#pragma multi_compile_instancing
|
|
#pragma multi_compile _CUSTOMDATA_OFF _CUSTOMDATA_ON
|
|
#pragma multi_compile _TEX2_OFF _TEX2_ON
|
|
#pragma multi_compile _DISTORTION_OFF _DISTORTION_ON
|
|
#pragma multi_compile _MASK_OFF _MASK_ON
|
|
#pragma multi_compile _DISSOLVE_OFF _DISSOLVE_ON
|
|
#pragma multi_compile _POLAR_OFF _POLAR_ON
|
|
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
|
|
|
|
struct appdata
|
|
{
|
|
float4 positionOS : POSITION;
|
|
float4 color: COLOR;
|
|
float4 uv : TEXCOORD0;
|
|
|
|
#if _CUSTOMDATA_ON
|
|
float4 customData: TEXCOORD1;
|
|
#endif
|
|
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct v2f
|
|
{
|
|
float4 vertex : SV_POSITION;
|
|
half4 vColor: COLOR;
|
|
half2 uv : TEXCOORD0;
|
|
|
|
#if _TEX2_ON
|
|
half2 uv2 : TEXCOORD1;
|
|
#endif
|
|
|
|
#if _DISTORTION_ON
|
|
half2 uvDistortion : TEXCOORD2;
|
|
#endif
|
|
|
|
#if _MASK_ON
|
|
half2 uvMask : TEXCOORD3;
|
|
#endif
|
|
|
|
#if _DISSOLVE_ON
|
|
half2 uvDissolve : TEXCOORD4;
|
|
half dissolveProgress : TEXCOORD5;
|
|
#endif
|
|
|
|
#if _CUSTOMDATA_ON
|
|
half4 customData: TEXCOORD6;
|
|
#endif
|
|
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
};
|
|
|
|
TEXTURE2D(_BaseMap);
|
|
SAMPLER(sampler_BaseMap);
|
|
|
|
#if _TEX2_ON
|
|
TEXTURE2D(_BaseMap2);
|
|
SAMPLER(sampler_BaseMap2);
|
|
#endif
|
|
|
|
#if _DISTORTION_ON
|
|
TEXTURE2D(_DistortionMap);
|
|
SAMPLER(sampler_DistortionMap);
|
|
#endif
|
|
|
|
#if _MASK_ON
|
|
TEXTURE2D(_MaskMap);
|
|
SAMPLER(sampler_MaskMap);
|
|
#endif
|
|
|
|
#if _DISSOLVE_ON
|
|
TEXTURE2D(_DissolveMap);
|
|
SAMPLER(sampler_DissolveMap);
|
|
#endif
|
|
|
|
|
|
CBUFFER_START(UnityPerMaterial)
|
|
half4 _BaseMap_ST;
|
|
half4 _BaseColor;
|
|
half _UVMoveX;
|
|
half _UVMoveY;
|
|
half _BaseColorScale;
|
|
half _AlphaClip;
|
|
|
|
#if _TEX2_ON
|
|
half4 _BaseMap2_ST;
|
|
half4 _BaseColor2;
|
|
half _BlendProgress;
|
|
half _UVMove2X;
|
|
half _UVMove2Y;
|
|
#endif
|
|
|
|
#if _DISTORTION_ON
|
|
half4 _DistortionMap_ST;
|
|
half _DistortionMaxStrength;
|
|
half _DistortionStrength;
|
|
half _DistortionMoveX;
|
|
half _DistortionMoveY;
|
|
#endif
|
|
|
|
#if _MASK_ON
|
|
half4 _MaskMap_ST;
|
|
half _MaskStrength;
|
|
half _MaskMoveX;
|
|
half _MaskMoveY;
|
|
#endif
|
|
|
|
#if _DISSOLVE_ON
|
|
half4 _DissolveMap_ST;
|
|
half _DissolveLength;
|
|
half _DissolveProgress;
|
|
#endif
|
|
|
|
#if _POLAR_ON
|
|
half _PolarScale;
|
|
#endif
|
|
CBUFFER_END
|
|
|
|
v2f vert(appdata v)
|
|
{
|
|
v2f o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_TRANSFER_INSTANCE_ID(v, o);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
|
|
|
o.vertex = TransformObjectToHClip(v.positionOS.xyz);
|
|
|
|
o.vColor = half4(v.color) * _BaseColor * _BaseColorScale;
|
|
|
|
half time = _TimeParameters.x;
|
|
|
|
o.uv = TRANSFORM_TEX(v.uv.xy, _BaseMap);
|
|
|
|
#if _CUSTOMDATA_ON
|
|
o.uv.x += v.customData.x;
|
|
o.uv.y += v.customData.y;
|
|
o.customData = v.customData;
|
|
#else
|
|
o.uv.x = mad(time, _UVMoveX, o.uv.x);
|
|
o.uv.y = mad(time, _UVMoveY, o.uv.y);
|
|
#endif
|
|
|
|
#if _TEX2_ON
|
|
o.uv2 = TRANSFORM_TEX(v.uv.xy, _BaseMap2);
|
|
o.uv2.x = mad(time, _UVMove2X, o.uv2.x);
|
|
o.uv2.y = mad(time, _UVMove2Y, o.uv2.y);
|
|
#endif
|
|
|
|
#if _DISTORTION_ON
|
|
o.uvDistortion = TRANSFORM_TEX(v.uv.xy, _DistortionMap);
|
|
o.uvDistortion.x = mad(time, _DistortionMoveX, o.uvDistortion.x);
|
|
o.uvDistortion.y = mad(time, _DistortionMoveY, o.uvDistortion.y);
|
|
#endif
|
|
|
|
#if _MASK_ON
|
|
o.uvMask = TRANSFORM_TEX(v.uv.xy, _MaskMap);
|
|
o.uvMask.x = mad(time, _MaskMoveX, o.uvMask.x);
|
|
o.uvMask.y = mad(time, _MaskMoveY, o.uvMask.y);
|
|
#endif
|
|
|
|
#if _DISSOLVE_ON
|
|
o.uvDissolve = TRANSFORM_TEX(v.uv.xy, _DissolveMap);
|
|
#if _CUSTOMDATA_ON
|
|
o.dissolveProgress = v.customData.z;
|
|
#else
|
|
o.dissolveProgress = _DissolveProgress;
|
|
#endif
|
|
#endif
|
|
|
|
return o;
|
|
}
|
|
|
|
half4 frag(v2f IN) : SV_Target
|
|
{
|
|
UNITY_SETUP_INSTANCE_ID(IN);
|
|
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(IN);
|
|
|
|
half2 uv = IN.uv;
|
|
|
|
#if _DISTORTION_ON
|
|
half4 distortionColor = SAMPLE_TEXTURE2D(_DistortionMap, sampler_DistortionMap, IN.uvDistortion);
|
|
half2 distortion = mad(distortionColor.xy, 2.0, -1.0) * (_DistortionStrength * _DistortionMaxStrength);
|
|
uv += distortion;
|
|
#endif
|
|
|
|
#if _POLAR_ON
|
|
half2 polarUV = uv - 0.5;
|
|
half polar = length(polarUV);
|
|
half angle = atan2(polarUV.x, polarUV.y) * (0.5 / PI);
|
|
uv = half2(polar * 2.0, angle);
|
|
|
|
#if _CUSTOMDATA_ON
|
|
uv.x += IN.customData.w;
|
|
#else
|
|
uv.x += _PolarScale;
|
|
#endif
|
|
#endif
|
|
|
|
half4 col = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, uv);
|
|
col *= IN.vColor;
|
|
|
|
#if _TEX2_ON
|
|
half4 col2 = SAMPLE_TEXTURE2D(_BaseMap2, sampler_BaseMap2, IN.uv2);
|
|
col2 *= _BaseColor2;
|
|
col2.a *= IN.vColor.a;
|
|
|
|
col = lerp(col, col2, _BlendProgress);
|
|
#endif
|
|
|
|
#if _DISSOLVE_ON
|
|
half dissolve = SAMPLE_TEXTURE2D(_DissolveMap, sampler_DissolveMap, IN.uvDissolve).r;
|
|
half dissolveProgress = IN.dissolveProgress;
|
|
|
|
clip(dissolve - dissolveProgress);
|
|
|
|
half dissolveLength = min(_DissolveLength, dissolveProgress);
|
|
half dissolveEdge = dissolveLength + dissolveProgress;
|
|
half edgeFade = saturate((dissolve - dissolveProgress) * rcp(dissolveLength));
|
|
half isInEdge = step(dissolve, dissolveEdge);
|
|
col.a *= lerp(1.0, edgeFade, isInEdge);
|
|
#endif
|
|
|
|
#if _MASK_ON
|
|
half maskAlpha = SAMPLE_TEXTURE2D(_MaskMap, sampler_MaskMap, IN.uvMask).a;
|
|
col.a = lerp(col.a, col.a * maskAlpha, _MaskStrength);
|
|
#endif
|
|
|
|
clip(col.a - _AlphaClip);
|
|
|
|
return col;
|
|
}
|
|
ENDHLSL
|
|
}
|
|
}
|
|
} |