一大波优化
This commit is contained in:
@@ -42,7 +42,6 @@ namespace IndianOceanAssets.Engine2_5D
|
||||
[SerializeField] private Transform followTarget;
|
||||
[SerializeField] private Transform maskPlane;
|
||||
[SerializeField] private Vector3 maskOffset = new Vector3(0f, 5f, 0f);
|
||||
[SerializeField] private float planeSize = 50f;
|
||||
|
||||
// Shader Property IDs
|
||||
private static readonly int LightDataID = Shader.PropertyToID("_LightData");
|
||||
|
||||
@@ -31,7 +31,7 @@ Material:
|
||||
- _EchoRadius: 39.41617
|
||||
- _EchoWidth: 2.5
|
||||
- _LightSoftness: 1
|
||||
- _MinBrightness: 0
|
||||
- _MinBrightness: 1
|
||||
m_Colors:
|
||||
- _DarknessColor: {r: 0.01, g: 0.01, b: 0.02, a: 1}
|
||||
- _EchoCenter: {r: -2.4399998, g: -1.5000057, b: 0, a: 0}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:yousandi.cn,2023:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: SpriteDissolve
|
||||
m_Shader: {fileID: 4800000, guid: 329aabb9d7e77d04295a944f844af20e, type: 3}
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords: []
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_LockedProperties:
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _CastShadow: 0
|
||||
- _DissolveAmount: 0
|
||||
- _DissolveEdgeWidth: 0.08
|
||||
- _DissolveNoiseScale: 10
|
||||
m_Colors:
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _DissolveEdgeColor: {r: 1, g: 0.8, b: 0.3, a: 1}
|
||||
m_BuildTextureStacks: []
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: XngdtS34U3q7jtUf6N0YEJu6txcsCpUWL91rvDjiR9mHR2rHf2SeiDQ=
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,154 @@
|
||||
Shader "Custom/SpriteDissolve"
|
||||
{
|
||||
// 敌人死亡消隐 Shader
|
||||
// 基于噪声的溶解效果,带发光边缘
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
_Color ("颜色", Color) = (1, 1, 1, 1)
|
||||
|
||||
[Header(Dissolve)]
|
||||
_DissolveAmount ("溶解进度", Range(0, 1)) = 0
|
||||
_DissolveEdgeWidth ("边缘宽度", Range(0, 0.3)) = 0.05
|
||||
_DissolveEdgeColor ("边缘颜色", Color) = (1, 0.8, 0.3, 1)
|
||||
_DissolveNoiseScale ("噪声缩放", Float) = 10
|
||||
|
||||
// 阴影设置(保持与项目一致)
|
||||
[MaterialToggle] _CastShadow ("投射阴影", Float) = 0
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"RenderPipeline" = "UniversalPipeline"
|
||||
"Queue" = "Transparent"
|
||||
"RenderType" = "Transparent"
|
||||
}
|
||||
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ZWrite Off
|
||||
Cull Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "SpriteDissolve"
|
||||
|
||||
HLSLPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 color : COLOR;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 color : COLOR;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
TEXTURE2D(_MainTex);
|
||||
SAMPLER(sampler_MainTex);
|
||||
|
||||
half4 _Color;
|
||||
half _DissolveAmount;
|
||||
half _DissolveEdgeWidth;
|
||||
half4 _DissolveEdgeColor;
|
||||
float _DissolveNoiseScale;
|
||||
|
||||
// 简单的哈希噪声
|
||||
float hash(float2 p)
|
||||
{
|
||||
float3 p3 = frac(float3(p.xyx) * 0.1031);
|
||||
p3 += dot(p3, p3.yzx + 33.33);
|
||||
return frac((p3.x + p3.y) * p3.z);
|
||||
}
|
||||
|
||||
// 值噪声(平滑插值)
|
||||
float valueNoise(float2 p)
|
||||
{
|
||||
float2 i = floor(p);
|
||||
float2 f = frac(p);
|
||||
f = f * f * (3.0 - 2.0 * f); // smoothstep
|
||||
|
||||
float a = hash(i);
|
||||
float b = hash(i + float2(1, 0));
|
||||
float c = hash(i + float2(0, 1));
|
||||
float d = hash(i + float2(1, 1));
|
||||
|
||||
return lerp(lerp(a, b, f.x), lerp(c, d, f.x), f.y);
|
||||
}
|
||||
|
||||
// 分形噪声(多层叠加)
|
||||
float fbm(float2 p)
|
||||
{
|
||||
float value = 0.0;
|
||||
float amplitude = 0.5;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
value += amplitude * valueNoise(p);
|
||||
p *= 2.0;
|
||||
amplitude *= 0.5;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
Varyings vert(Attributes input)
|
||||
{
|
||||
Varyings output;
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_TRANSFER_INSTANCE_ID(input, output);
|
||||
|
||||
output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
|
||||
output.uv = input.uv;
|
||||
output.color = input.color;
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 frag(Varyings input) : SV_Target
|
||||
{
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
|
||||
half4 texColor = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv);
|
||||
half4 color = texColor * _Color * input.color;
|
||||
|
||||
// 如果 alpha 太小,直接丢弃
|
||||
if (color.a < 0.01)
|
||||
discard;
|
||||
|
||||
// 计算噪声
|
||||
float noise = fbm(input.uv * _DissolveNoiseScale);
|
||||
|
||||
// 溶解判定
|
||||
float dissolveEdge = smoothstep(
|
||||
_DissolveAmount - _DissolveEdgeWidth,
|
||||
_DissolveAmount + _DissolveEdgeWidth,
|
||||
noise
|
||||
);
|
||||
|
||||
// 完全溶解区域
|
||||
if (noise < _DissolveAmount)
|
||||
discard;
|
||||
|
||||
// 边缘发光
|
||||
half edgeGlow = (1.0 - dissolveEdge) * step(_DissolveAmount, noise);
|
||||
color.rgb += _DissolveEdgeColor.rgb * edgeGlow * _DissolveEdgeColor.a;
|
||||
|
||||
// 整体淡出(溶解后期整体变淡)
|
||||
color.a *= lerp(1.0, 0.3, _DissolveAmount);
|
||||
|
||||
return color;
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
FallBack "Sprites/Default"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: DHgW5Hv/AXJ4FVCaTjexQVJQLVXJgr6jZu7Vz9GpO936bn5BeMA1Iv0=
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user