材质修改

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

+35 -7
View File
@@ -50,20 +50,48 @@ public abstract class UIMaskEnumDrawer : MaterialPropertyDrawer
}
}
// 混合模式:加色 / 普通混合
// 数值对应 UnityEngine.Rendering.BlendMode:SrcAlpha=5, One=1, OneMinusSrcAlpha=10
// 混合模式:Additive / Alpha / Alpha Premultiplied / Opaque
// 数值对应 UnityEngine.Rendering.BlendMode:SrcAlpha=5, One=1, OneMinusSrcAlpha=10, Zero=0
// Opaque 会同时打开 ZWrite(不透明需要写深度),其余模式 ZWrite = 0
public class UIMaskBlendMode : UIMaskEnumDrawer
{
private static readonly string[] Items = { "Additive", "AlphaBlend" };
private static readonly string[] Items = { "Additive", "Alpha", "Alpha Premultiplied", "Opaque" };
protected override string[] Options => Items;
protected override void Apply(MaterialEditor editor, int index)
{
SetValue(editor, "_SrcBlend", (float)UnityEngine.Rendering.BlendMode.SrcAlpha);
SetValue(editor, "_DstBlend", index == 0
? (float)UnityEngine.Rendering.BlendMode.One
: (float)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
const float srcAlpha = (float)UnityEngine.Rendering.BlendMode.SrcAlpha; // 5
const float one = (float)UnityEngine.Rendering.BlendMode.One; // 1
const float oneMinusSrcAlpha = (float)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha; // 10
const float zero = (float)UnityEngine.Rendering.BlendMode.Zero; // 0
switch (index)
{
case 1: // Alpha:标准透明混合
SetValue(editor, "_SrcBlend", srcAlpha);
SetValue(editor, "_DstBlend", oneMinusSrcAlpha);
SetValue(editor, "_ZWrite", 0f);
break;
case 2: // Alpha Premultiplied:颜色已预乘 alpha,源因子用 One
SetValue(editor, "_SrcBlend", one);
SetValue(editor, "_DstBlend", oneMinusSrcAlpha);
SetValue(editor, "_ZWrite", 0f);
break;
case 3: // Opaque:不混合 + 写深度
SetValue(editor, "_SrcBlend", one);
SetValue(editor, "_DstBlend", zero);
SetValue(editor, "_ZWrite", 1f);
break;
default: // Additive:SrcAlpha + One
SetValue(editor, "_SrcBlend", srcAlpha);
SetValue(editor, "_DstBlend", one);
SetValue(editor, "_ZWrite", 0f);
break;
}
}
}
+1 -1
View File
@@ -25,7 +25,7 @@ public class UIMaskShaderGUI : ShaderGUI
new Group
{
Label = "基础",
Props = new[] { "_BlendMode", "_RenderFace", "_TintColor", "_GlowScale|_AlphaScale", "_MainTex" }
Props = new[] { "_BlendMode", "_RenderFace", "_TintColor", "_GlowScale|_AlphaScale", "_MainTex", "_SoftParticleFade" }
},
new Group
{
+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;
}
+22 -20
View File
@@ -12,7 +12,9 @@ Material:
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords:
- _USEDISSOLVE_ON
- _USEMASK_ON
- _USEUVANI_ON
- _USEUVDISTORTION_ON
m_InvalidKeywords:
- _USEUVTRAIL_ON
m_LightmapFlags: 4
@@ -46,7 +48,7 @@ Material:
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _DissolveTex:
m_Texture: {fileID: 2800000, guid: 94c4ffff470a043f68f9d388161c3b2a, type: 3}
m_Texture: {fileID: 0}
m_Scale: {x: 0.5, y: 0.5}
m_Offset: {x: -2.91, y: 0}
- _EmissionMap:
@@ -54,11 +56,11 @@ Material:
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MainTex:
m_Texture: {fileID: 2800000, guid: 7ca288cbfc0684bbf876ce03dca16a9a, type: 3}
m_Texture: {fileID: 2800000, guid: 2bfaefa73861d4610817e7bcbd61868e, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _Mask:
m_Texture: {fileID: 0}
m_Texture: {fileID: 2800000, guid: d9727e1906dfa4caa8302f7d2d99c032, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _MetallicGlossMap:
@@ -82,7 +84,7 @@ Material:
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _UVNoiseTex:
m_Texture: {fileID: 0}
m_Texture: {fileID: 2800000, guid: 94c4ffff470a043f68f9d388161c3b2a, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_Lightmaps:
@@ -113,14 +115,14 @@ Material:
- _Cutoff: 0.5
- _DetailAlbedoMapScale: 1
- _DetailNormalMapScale: 1
- _Dissolve: 1
- _DissolveChannel: 0
- _DissolveCustomChannel: 1
- _Dissolve: 0
- _DissolveChannel: 3
- _DissolveCustomChannel: 0
- _DissolveCustomData: 1
- _DissolveEdgeSharpness: 0.001
- _DissolveHighlightWidth: 0.203
- _DissolveWidth: 0.174
- _Distortion: 0
- _DissolveEdgeSharpness: 2
- _DissolveHighlightWidth: 0.08
- _DissolveWidth: 0
- _Distortion: 0.5
- _DstBlend: 10
- _DstBlendAlpha: 0
- _EdgeGlow: 1
@@ -141,7 +143,7 @@ Material:
- _Smoothness: 0.5
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SpeedU: 0
- _SpeedU: -2
- _SpeedV: 0
- _SrcBlend: 5
- _SrcBlendAlpha: 1
@@ -151,14 +153,14 @@ Material:
- _StencilReadMask: 255
- _StencilWriteMask: 255
- _Surface: 0
- _UseDissolve: 1
- _UseDissolve: 0
- _UseHardEdge: 0
- _UseMask: 0
- _UseMask: 1
- _UseMaskUvAni: 0
- _UseReceiveFog: 0
- _UseUIMaskClip: 0
- _UseUvAni: 0
- _UseUvDistortion: 0
- _UseUvAni: 1
- _UseUvDistortion: 1
- _UseUvTrail: 1
- _UseVertexMask: 0
- _VertexFlipX: 1
@@ -168,12 +170,12 @@ Material:
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _ClipRect: {r: -1, g: -1, b: 1, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _DissolveEdgeColor: {r: 1, g: 0.03199675, b: 0, a: 1}
- _DissolveHighlightColor: {r: 4, g: 2.8794167, b: 0, a: 1}
- _DissolveEdgeColor: {r: 0, g: 0, b: 0, a: 1}
- _DissolveHighlightColor: {r: 0, g: 0, b: 0, a: 1}
- _EdgeColor: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _MainTexTiling: {r: 1, g: 1, b: 0, a: 0}
- _NoiseScroll: {r: 0, g: 0, b: 1, a: 1}
- _NoiseScroll: {r: -1, g: 0, b: 1, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
- _TintColor: {r: 0.5, g: 0.5, b: 0.5, a: 0.5}
- _VertexOffset: {r: 0, g: 0, b: 1, a: 1}