GPU优化

This commit is contained in:
SoulliesOfficial
2026-04-06 09:32:56 -04:00
parent 1bc9af280b
commit f4068baf4a
108 changed files with 2813 additions and 1073 deletions

View File

@@ -7,7 +7,8 @@ Shader "Soullies/DTM_RandomGridTube"
[Header(Pattern Settings)]
_PatternSize("Pattern Size (X, Y)", Vector) = (2.0, 2.0, 0, 0)
_GridDensity("Grid Density (Quantity Multiplier)", Float) = 1.0
_TimeAngle("Time Angle (Speed)", Float) = 1.0
_BaseSpeed("Base Speed (Static)", Float) = 1.0
_TimeAngle("Time Angle / Offset (Dynamic)", Float) = 0.0
[Header(Edge Settings)]
_StepA("Step A", Range(0, 1)) = 0.293
@@ -27,7 +28,7 @@ Shader "Soullies/DTM_RandomGridTube"
[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend("Src Blend", Float) = 5 // SrcAlpha
[Enum(UnityEngine.Rendering.BlendMode)] _DstBlend("Dst Blend", Float) = 10 // OneMinusSrcAlpha
[Enum(Off, 0, On, 1)] _ZWrite("Z Write", Float) = 0
[Enum(Front, Back, Off)] _CullMode("Cull Mode", Float) = 1 // Front (Inside)
[Enum(Front, 0, Back, 1, Off, 2)] _CullMode("Cull Mode", Float) = 1 // Front (Inside)
}
SubShader
@@ -82,6 +83,7 @@ Shader "Soullies/DTM_RandomGridTube"
half4 _Color0;
float4 _PatternSize;
float _GridDensity;
float _BaseSpeed;
float _TimeAngle;
float _StepA;
float _StepB;
@@ -94,32 +96,47 @@ Shader "Soullies/DTM_RandomGridTube"
CBUFFER_END
// -------------------------------------
// Custom Helper Functions
float2 VoronoiHash(float2 p)
// 极限优化工具库组 (无三角函数全MAD指令)
// Fast 2D Hash (纯乘加与小数截断,干掉 sin)
float2 FastHash22(float2 p)
{
p = float2(dot(p, float2(127.1, 311.7)), dot(p, float2(269.5, 183.3)));
return frac(sin(p) * 43758.5453);
float3 p3 = frac(float3(p.xyx) * float3(0.1031, 0.1030, 0.0973));
p3 += dot(p3, p3.yzx + 33.33);
return frac((p3.xx + p3.yz) * p3.zy);
}
// Manhattan-based Voronoi optimized for Mobile URP
float VoronoiDistance(float2 v, float t)
// Extreme Optimized 4-Tap Voronoi for Mobile (从9次循环砍至4次)
float VoronoiDistanceFast(float2 v, float t)
{
float2 n = floor(v);
float2 f = frac(v);
// 象限锚定算出像素所处方格的偏向完美剔除背面5个不可能相邻的远格
float2 mg = step(0.5, f);
float minDist = 8.0;
UNITY_UNROLL
for (int j = -1; j <= 1; j++)
for (int j = 0; j <= 1; j++)
{
UNITY_UNROLL
for (int i = -1; i <= 1; i++)
for (int i = 0; i <= 1; i++)
{
float2 g = float2((float)i, (float)j);
float2 o = VoronoiHash(n + g);
// Oscillating movement
o = sin(t + o * 6.2831853) * 0.5 + 0.5;
// 检索偏向象限的核心 4 个格子
float2 g = mg + float2(i - 1.0, j - 1.0);
float2 hash = FastHash22(n + g);
// 剔除昂贵的 sin 并换用平滑三角波:
// t * 0.1591549 即相当于 t / (2*PI) 把时间归一化到周期
float2 phase = frac(t * 0.1591549 + hash);
float2 tri = abs(phase * 2.0 - 1.0); // 线性三角波 1 -> 0 -> 1
float2 o = tri * tri * (3.0 - 2.0 * tri); // 光滑三次曲线,模拟 sin 的柔顺运动
float2 r = f - g - o;
// Manhattan distance for rectangular frames
// Manhattan 曼哈顿距离
float d = 0.5 * (abs(r.x) + abs(r.y));
minDist = min(minDist, d);
}
@@ -177,8 +194,9 @@ Shader "Soullies/DTM_RandomGridTube"
// Convert adjusted angle to U coordinate
float u = angle * _TubeRadius;
// V is driven by World Z to maintain seamless tiling
float v = input.positionWS.z;
// V is driven by Object Z scaled by World Scale to maintain seamless tiling and resist rotation stretching
float scaleZ = length(float3(unity_ObjectToWorld[0].z, unity_ObjectToWorld[1].z, unity_ObjectToWorld[2].z));
float v = input.positionOS.z * scaleZ;
float2 cylindricalUV = float2(u, v);
@@ -193,11 +211,11 @@ Shader "Soullies/DTM_RandomGridTube"
float s = 0.707106;
float2 rotatedUV = mul(scaledUV, float2x2(c, -s, s, c));
// Time driven animation
float t = _TimeAngle * _TimeParameters.x;
// Time driven animation (Base Time + Phase Offset)
float t = _TimeParameters.x * _BaseSpeed + _TimeAngle;
// Voronoi mathematical noise
float voronoiV = VoronoiDistance(rotatedUV, t);
// [TA 极限计算压缩] 使用 4-Tap、零三角函数的极简数学方法保持无限分辨率。
float voronoiV = VoronoiDistanceFast(rotatedUV, t);
// Anti-aliased border mask computation
float fw = fwidth(voronoiV);