增加传送门
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
Shader "IndianOcean/PortalVortex"
|
||||
{
|
||||
// 传送门旋涡 Shader
|
||||
// 顺时针旋转 + 中心扭曲 + 发光效果
|
||||
// 基于 URP 管线
|
||||
Properties
|
||||
{
|
||||
_MainTex ("主贴图", 2D) = "white" {}
|
||||
_RotationSpeed ("旋转速度", Range(-5.0, 5.0)) = 1.5
|
||||
_VortexStrength ("扭曲强度", Range(0.0, 3.0)) = 1.0
|
||||
_CenterGlow ("中心发光强度", Range(0.0, 3.0)) = 1.5
|
||||
_Color ("色调", Color) = (1.0, 1.0, 1.0, 1.0)
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"RenderType" = "Transparent"
|
||||
"Queue" = "Transparent"
|
||||
"RenderPipeline" = "UniversalPipeline"
|
||||
}
|
||||
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ZWrite Off
|
||||
ZTest LEqual
|
||||
Cull Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "PortalVortex"
|
||||
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;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
float4 _MainTex_ST;
|
||||
float _RotationSpeed;
|
||||
float _VortexStrength;
|
||||
float _CenterGlow;
|
||||
float4 _Color;
|
||||
CBUFFER_END
|
||||
|
||||
TEXTURE2D(_MainTex);
|
||||
SAMPLER(sampler_MainTex);
|
||||
|
||||
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 = TRANSFORM_TEX(input.uv, _MainTex);
|
||||
return output;
|
||||
}
|
||||
|
||||
half4 frag(Varyings input) : SV_Target
|
||||
{
|
||||
// UV 中心点
|
||||
float2 center = float2(0.5, 0.5);
|
||||
float2 uvOffset = input.uv - center;
|
||||
|
||||
// 极坐标:距离和角度
|
||||
float dist = length(uvOffset);
|
||||
float angle = atan2(uvOffset.y, uvOffset.x);
|
||||
|
||||
// 顺时针旋转:角度减去时间 * 速度
|
||||
float rotation = _Time.y * _RotationSpeed;
|
||||
|
||||
// 扭曲强度随距离减小(中心扭曲更大)
|
||||
float twist = _VortexStrength * (1.0 - dist * 2.0);
|
||||
twist = max(twist, 0.0);
|
||||
|
||||
// 应用旋转 + 扭曲
|
||||
float finalAngle = angle - rotation - twist * 3.14159;
|
||||
|
||||
// 转换回 UV 坐标
|
||||
float2 vortexUV = center + float2(
|
||||
cos(finalAngle) * dist,
|
||||
sin(finalAngle) * dist
|
||||
);
|
||||
|
||||
// 采样主贴图
|
||||
half4 texColor = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, vortexUV);
|
||||
|
||||
// 中心发光:距离中心越近越亮
|
||||
float glow = _CenterGlow * (1.0 - dist * 2.0);
|
||||
glow = max(glow, 0.0);
|
||||
|
||||
// 边缘柔和过渡
|
||||
float edgeFade = 1.0 - smoothstep(0.35, 0.5, dist);
|
||||
|
||||
// 最终颜色 = 贴图色 + 中心发光 * 蓝色调
|
||||
float3 glowColor = float3(0.2, 0.6, 1.0) * glow;
|
||||
float3 finalColor = texColor.rgb * _Color.rgb + glowColor;
|
||||
|
||||
float alpha = texColor.a * edgeFade;
|
||||
|
||||
return half4(finalColor, alpha);
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
FallBack Off
|
||||
}
|
||||
Reference in New Issue
Block a user