93 lines
3.0 KiB
Plaintext
93 lines
3.0 KiB
Plaintext
Shader "IndianOcean/EchoRing"
|
|
{
|
|
// 回声红圈 Shader —— 配合 EchoSystem 使用
|
|
// 在地面(XZ平面)上绘制一个红色渐变圆环,圆环位置跟随全局 _EchoRadius
|
|
// 边缘使用 smoothstep 渐变,从圆环中心满透明度向两侧柔和消散
|
|
Properties
|
|
{
|
|
_RingColor ("Ring Color", Color) = (1, 0.15, 0.1, 1)
|
|
_RingWidth ("Ring Width (world units)", Float) = 2.5
|
|
}
|
|
SubShader
|
|
{
|
|
Tags
|
|
{
|
|
"RenderType" = "Transparent"
|
|
"Queue" = "Transparent+250"
|
|
"RenderPipeline" = "UniversalPipeline"
|
|
}
|
|
Blend SrcAlpha OneMinusSrcAlpha
|
|
ZWrite Off
|
|
ZTest Always
|
|
Cull Off
|
|
|
|
Pass
|
|
{
|
|
Name "EchoRing"
|
|
HLSLPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#pragma multi_compile_instancing
|
|
|
|
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
|
|
|
struct Attributes
|
|
{
|
|
float4 positionOS : POSITION;
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 positionCS : SV_POSITION;
|
|
float3 worldPos : TEXCOORD0;
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
CBUFFER_START(UnityPerMaterial)
|
|
float4 _RingColor;
|
|
float _RingWidth;
|
|
CBUFFER_END
|
|
|
|
// 全局回声参数(由 EchoSystem 通过 Shader.SetGlobalX 设置)
|
|
float4 _EchoCenter; // xy = 回声中心世界坐标 XZ
|
|
float _EchoRingRadius; // 红圈独立扩散半径
|
|
float _EchoRingAlpha; // 红圈独立透明度(独立于描边强度)
|
|
|
|
Varyings vert(Attributes input)
|
|
{
|
|
Varyings output;
|
|
UNITY_SETUP_INSTANCE_ID(input);
|
|
UNITY_TRANSFER_INSTANCE_ID(input, output);
|
|
|
|
output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
|
|
output.worldPos = TransformObjectToWorld(input.positionOS.xyz);
|
|
return output;
|
|
}
|
|
|
|
half4 frag(Varyings input) : SV_Target
|
|
{
|
|
// 世界空间 XZ 平面上的距离
|
|
float2 wp = input.worldPos.xz;
|
|
float dist = distance(wp, _EchoCenter.xy);
|
|
|
|
// 距离圆环中心的偏差
|
|
float distFromRing = abs(dist - _EchoRingRadius);
|
|
|
|
// 渐变:圆环中心满强度,两侧柔和消散
|
|
float halfW = max(0.001, _RingWidth * 0.5);
|
|
float alpha = 1.0 - smoothstep(0.0, halfW, distFromRing);
|
|
|
|
// 乘以红圈独立透明度(独立于描边消散时序)
|
|
alpha *= _EchoRingAlpha;
|
|
|
|
if (alpha < 0.001) discard;
|
|
|
|
return half4(_RingColor.rgb, alpha * _RingColor.a);
|
|
}
|
|
ENDHLSL
|
|
}
|
|
}
|
|
FallBack Off
|
|
}
|