95 lines
3.1 KiB
Plaintext
95 lines
3.1 KiB
Plaintext
Shader "IndianOcean/AbyssGlowParticle"
|
|
{
|
|
// 深渊荧光粒子 Shader
|
|
// 加法混合 + Queue 3200(在 DarknessOverlay 的 3100 之后渲染)
|
|
// 不受乘法黑暗遮罩影响,在纯黑虚空中也能发光
|
|
// 程序化软圆点,不需要贴图
|
|
//
|
|
// 使用方式:
|
|
// 1. 创建材质,选此 shader
|
|
// 2. 材质赋给 ParticleSystem 的 Renderer > Material
|
|
// 3. 粒子贴图留空(程序化圆点),用 Vertex Color 控制颜色/透明度
|
|
Properties
|
|
{
|
|
_Color ("颜色", Color) = (1.0, 0.85, 0.4, 1.0)
|
|
_Softness ("柔和度(边缘渐变宽度)", Range(0.01, 1.0)) = 0.5
|
|
_Intensity ("亮度倍数", Range(0.1, 5.0)) = 1.0
|
|
}
|
|
SubShader
|
|
{
|
|
Tags
|
|
{
|
|
"RenderType" = "Transparent"
|
|
"Queue" = "Transparent+200"
|
|
"RenderPipeline" = "UniversalPipeline"
|
|
}
|
|
// alpha 加法混合:finalColor = src.rgb * src.a + dst.rgb
|
|
// 粒子在黑暗遮罩之后渲染,直接往画面上加光
|
|
Blend SrcAlpha One
|
|
ZWrite Off
|
|
ZTest LEqual
|
|
Cull Off
|
|
|
|
Pass
|
|
{
|
|
Name "AbyssGlow"
|
|
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;
|
|
float2 uv : TEXCOORD0;
|
|
float4 color : COLOR; // 粒子系统顶点色(含生命周期 alpha)
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 positionCS : SV_POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
float4 color : COLOR;
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
CBUFFER_START(UnityPerMaterial)
|
|
float4 _Color;
|
|
float _Softness;
|
|
float _Intensity;
|
|
CBUFFER_END
|
|
|
|
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
|
|
{
|
|
// 程序化软圆点:UV 中心 (0.5,0.5) 到边缘的距离
|
|
float2 center = float2(0.5, 0.5);
|
|
float dist = distance(input.uv, center);
|
|
float softCircle = 1.0 - smoothstep(_Softness * 0.5, 0.5, dist);
|
|
softCircle = max(0.0, softCircle);
|
|
|
|
// 颜色 = 材质色 × 粒子顶点色 × 亮度 × 软圆形状
|
|
float3 col = _Color.rgb * input.color.rgb * _Intensity;
|
|
float alpha = softCircle * input.color.a;
|
|
|
|
return half4(col, alpha);
|
|
}
|
|
ENDHLSL
|
|
}
|
|
}
|
|
FallBack Off
|
|
}
|