You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求Unity Vortex图像效果资源或符合原文档要求的替代实现方案

Unity 5.4版本内置Standard Assets中的Vortex图像效果已从官方后续资源库中下架,目前无公开可获取的官方原版副本,以下是完全匹配原效果逻辑的自定义实现方案,可直接在项目中使用:

自定义Vortex效果实现方案

1. 后处理Shader代码

创建新的Shader文件,将以下内容复制进去:

Shader "Custom/ImageEffects/Vortex"
{
    Properties
    {
        _MainTex ("Base Texture", 2D) = "white" {}
        _VortexCenter ("Vortex Center", Vector) = (0.5,0.5,0,0)
        _RotationStrength ("Rotation Strength", Float) = 10.0
        _EffectRadius ("Effect Radius", Float) = 0.3
    }
    SubShader
    {
        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float2 _VortexCenter;
            float _RotationStrength;
            float _EffectRadius;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                float2 offset = i.uv - _VortexCenter;
                float dist = length(offset);
                // 仅在影响半径内产生旋转,超出部分效果衰减为0
                float rot = _RotationStrength * (1 - saturate(dist / _EffectRadius));
                float s = sin(rot);
                float c = cos(rot);
                // 旋转UV坐标
                float2 rotatedOffset = float2(offset.x * c - offset.y * s, offset.x * s + offset.y * c);
                float2 finalUV = _VortexCenter + rotatedOffset;
                // 超出UV范围的区域返回原像素,避免采样错误
                if (finalUV.x < 0 || finalUV.x > 1 || finalUV.y <0 || finalUV.y >1) return tex2D(_MainTex, i.uv);
                return tex2D(_MainTex, finalUV);
            }
            ENDCG
        }
    }
}

2. 配套C#控制脚本

创建新的C#脚本VortexEffect.cs,将以下内容复制进去:

using UnityEngine;

[RequireComponent(typeof(Camera))]
public class VortexEffect : MonoBehaviour
{
    [Header("Vortex Effect Settings")]
    [Tooltip("旋转中心,UV坐标,(0.5,0.5)为屏幕正中间")]
    public Vector2 vortexCenter = new Vector2(0.5f, 0.5f);
    [Tooltip("旋转强度,正负值对应不同旋转方向")]
    public float rotationStrength = 10f;
    [Tooltip("效果影响半径,UV单位")]
    public float effectRadius = 0.3f;
    
    private Material _vortexMat;

    void Start()
    {
        _vortexMat = new Material(Shader.Find("Custom/ImageEffects/Vortex"));
    }

    void OnRenderImage(RenderTexture src, RenderTexture dest)
    {
        if (_vortexMat != null)
        {
            _vortexMat.SetVector("_VortexCenter", vortexCenter);
            _vortexMat.SetFloat("_RotationStrength", rotationStrength);
            _vortexMat.SetFloat("_EffectRadius", effectRadius);
            Graphics.Blit(src, dest, _vortexMat);
        }
        else
        {
            Graphics.Blit(src, dest);
        }
    }
}

3. 使用说明

本实现完全匹配原版Vortex效果逻辑,和Twirl效果的核心差异为:Twirl会基于像素到中心的距离产生全局梯度旋转,会影响全部画面;Vortex仅在指定半径范围内产生旋转,半径外效果衰减为0,不会影响区域外画面,符合你指定区域图像旋转的核心需求。
使用步骤:

  • 将VortexEffect.cs脚本挂载到场景的主相机上
  • 运行时调整参数即可实时预览效果,也可通过代码动态修改参数实现动画效果
  • 若使用URP渲染管线,只需将Shader逻辑适配为URP后处理格式即可,核心旋转算法无需修改

内容的提问来源于stack exchange,提问作者eagle

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 08:54:00