材质修改

This commit is contained in:
tianmo committed 2026-10-12 14:26:05 +08:00
1 parent ae5c4212dc
commit b26c7bbebd
20 files changed
+7820 -89

No files matched your search

+34 -17
View File
@@ -16,9 +16,11 @@ Properties {
[HideInInspector] _DstBlend ("Dst Blend", Float) = 1
[UIMaskRenderFace] _RenderFace ("渲染面", Float) = 2
[HideInInspector] _Cull ("Cull", Float) = 0
[HideInInspector] _ZWrite ("ZWrite", Float) = 0
[HDR]_TintColor ("着色", Color) = (0.5,0.5,0.5,0.5)
_GlowScale("发光强度", float) = 1
_AlphaScale("透明度", float) = 1
_SoftParticleFade ("软粒子过渡", Range(0, 5)) = 0
_MainTex ("主贴图", 2D) = "white" {}
[Toggle] _UseUvAni("启用", Float) = 0
_SpeedU("U 速度", Float) = 0
@@ -65,7 +67,7 @@ CustomEditor "UIMaskShaderGUI"
Category {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
Blend [_SrcBlend][_DstBlend]
Cull [_Cull] Lighting Off ZWrite Off
Cull [_Cull] Lighting Off ZWrite [_ZWrite]
SubShader {
Stencil
@@ -102,6 +104,9 @@ Category {
sampler2D _MainTex;
fixed4 _TintColor;
// 软粒子:拿相机深度图和粒子自身深度比较,贴近其它几何体时淡出(距离=0 时完全不生效)
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
float _SoftParticleFade;
#if _USEMASK_ON
sampler2D _Mask;
@@ -182,12 +187,9 @@ Category {
float4 customData : TEXCOORD1; // Custom1.xyzw
float4 customData2 : TEXCOORD6; // Custom2.xyzw
#if _USEMASK_ON
fixed2 texcoordMask : TEXCOORD2;
#endif
#if _USEUVDISTORTION_ON
fixed2 texcoordNoise : TEXCOORD3;
#if _USEMASK_ON || _USEUVDISTORTION_ON
// xy = 遮罩 UV,zw = 噪声 UV(合占一个插值器,给软粒子腾位置)
fixed4 uvPack : TEXCOORD2;
#endif
#if _USEDISSOLVE_ON
@@ -195,11 +197,14 @@ Category {
#endif
#if _USEUIMASKCLIP_ON
fixed4 worldPosition : TEXCOORD5;
fixed2 worldPosition : TEXCOORD5;
#endif
// 软粒子:xy/w = 屏幕 UV,w = 视空间深度
float4 screenPos : TEXCOORD3;
#if _USEVERTEXMASK_ON
fixed4 vertex2 : TEXCOORD7;
fixed2 vertex2 : TEXCOORD7;
#endif
UNITY_VERTEX_OUTPUT_STEREO
@@ -218,17 +223,18 @@ Category {
o.color = v.color * _TintColor;
o.texcoord.xy = TRANSFORM_TEX(v.texcoord,_MainTex);
o.texcoord.zw = v.texcoord.zw;
o.screenPos = ComputeScreenPos(o.vertex);
// 把打包在各 texcoord 里的粒子自定义数据还原成 Custom1.xyzw / Custom2.xyzw
o.customData = float4(v.texcoord.z, v.texcoord.w, v.texcoord1.x, v.texcoord1.y);
o.customData2 = float4(v.texcoord1.z, v.texcoord1.w, v.texcoord2.x, v.texcoord2.y);
#if _USEMASK_ON
o.texcoordMask = TRANSFORM_TEX(v.texcoord,_Mask);
o.uvPack.xy = TRANSFORM_TEX(v.texcoord,_Mask);
#endif
#if _USEUVDISTORTION_ON
o.texcoordNoise = TRANSFORM_TEX(v.texcoord,_UVNoiseTex);
o.uvPack.zw = TRANSFORM_TEX(v.texcoord,_UVNoiseTex);
#endif
#if _USEDISSOLVE_ON
@@ -236,11 +242,11 @@ Category {
#endif
#if _USEUIMASKCLIP_ON
o.worldPosition = mul(unity_ObjectToWorld, v.vertex);
o.worldPosition = mul(unity_ObjectToWorld, v.vertex).xy;
#endif
#if _USEVERTEXMASK_ON
o.vertex2 = v.vertex;
o.vertex2 = v.vertex.xy;
#endif
return o;
@@ -255,8 +261,8 @@ Category {
#if _USEUVDISTORTION_ON
float2 noiseScrollXY = _NoiseScroll.xy;
i.texcoordNoise += fixed2(_Time.g * noiseScrollXY);
i.texcoord.xy += tex2D(_UVNoiseTex, i.texcoordNoise).xy*_Distortion*_NoiseScroll.zw;
i.uvPack.zw += fixed2(_Time.g * noiseScrollXY);
i.texcoord.xy += tex2D(_UVNoiseTex, i.uvPack.zw).xy*_Distortion*_NoiseScroll.zw;
#endif
fixed4 col = 2.0f * i.color * tex2D(_MainTex, i.texcoord.xy);
@@ -265,9 +271,9 @@ Category {
#if _USEMASK_ON
#if _USEMASKUVANI_ON
i.texcoordMask += _Time.y * float2(_MaskSpeedU, _MaskSpeedV);
i.uvPack.xy += _Time.y * float2(_MaskSpeedU, _MaskSpeedV);
#endif
col.a = saturate(col.a * UIMaskSampleChannel(_Mask, i.texcoordMask, _MaskChannel));
col.a = saturate(col.a * UIMaskSampleChannel(_Mask, i.uvPack.xy, _MaskChannel));
#endif
#if _USEDISSOLVE_ON
@@ -298,6 +304,17 @@ Category {
col.a *= smoothstep(1, 0, ((i.vertex2.x - _VertexOffset.x) * _VertexOffset.z + (i.vertex2.y - _VertexOffset.y) * _VertexOffset.w) * _VertexFlipX);
#endif
// 软粒子:与相机深度图比较,贴近其它几何体(如地面)时按深度差淡出,消除生硬交线。
// _SoftParticleFade = 0(默认)时被 step 门控掉,完全不生效,也不产生分支/变体。
// 注意:正交相机下 screenPos.w != 视空间深度,此效果不适用。
{
float2 screenUV = i.screenPos.xy / i.screenPos.w;
float sceneEyeZ = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, screenUV));
float partEyeZ = i.screenPos.w;
float softFade = saturate((sceneEyeZ - partEyeZ) / max(_SoftParticleFade, 0.0001));
col.a *= lerp(1.0, softFade, step(0.0001, _SoftParticleFade));
}
return col;
}