如何在Unity3D中产生波浪效果

时间:2017-10-27 02:30:36

标签: unity3d

在Super Luigi Galaxy游戏中,当玩家陷入冷水时,屏幕会闪烁。有没有办法在Unity中实现这种效果?

效果如下所示:https://youtu.be/uj3TWvUlLqs?t=4m19s

https://i.imgur.com/1oR9ZFk.png

我不知道这个效果的名称,对不起我的细节感到抱歉。

1 个答案:

答案 0 :(得分:1)

抱歉愚蠢。

1)添加一个新的着色器,材质和C#脚本

2)脚本。
着色器(添加到底​​部,并删除颜色反转):

        uniform float _waveLength;
        uniform float _waveNumber;

        fixed4 frag (v2f IN) : SV_Target
        {
            fixed4 col = tex2D(_MainTex, IN.uv + float2(sin(IN.vertex.y / _waveLength + _Time[1]*50) / _waveNumber, 0));

            return col;
        }

C#:

using UnityEngine;

public class testscript : MonoBehaviour {

    public Material mat;

    public float waveNumber;
    public float waveLength;

    void Update()
    {
        Shader.SetGlobalFloat("_waveLength", waveNumber); // I know I switched the variables on accident. It still works though.
        Shader.SetGlobalFloat("_waveNumber", waveLength);
    }

    void OnRenderImage( RenderTexture src, RenderTexture dest)
    {
        Graphics.Blit(src, dest, mat);
    }
}

3)将C#脚本附加到相机,将着色器附加到材质,然后将材质附加到C#脚本。在场景中添加一个立方体以查看效果。转到Unity上的播放模式,并调整脚本上的设置。

4)变量有什么作用?

a)波数: 波浪的数量, 1 =很多波浪 30 =非常少的波浪

b)波长: 抵消波浪x的距离, 1 =非常宽的波浪 1000 =非常短波

我建议波数为1,波长为100。

相关问题