1
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Unity】水面をゆらゆらしてみた(Shader)

Last updated at Posted at 2021-06-16

環境メモ
⭐️Mac Book Pro(Mac OS Catalina)
⭐️Unity 2019.4.22f1
⭐️Blender2.92
⭐️CLIP STUDIO PAINT PRO

↓完成内容
Unityで、水面のテクスチャを少し透明に設定。
↓こんな感じで出来た。
ezgif.com-gif-maker.gif

## 水面のテクスチャを作成する CLIP STUDIO PAINTで水面をデジタルイラストで描きました。 ![スクリーンショット 2021-06-17 1.00.53.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/93155/6d08830a-dfa3-10d2-b457-5202a8880367.png)

水面テクスチャをjpg形式でエクスポートしました。
スクリーンショット 2021-06-17 1.31.02.png

水面の3DモデルをBlenderで作成する

1.Blenderで、水面となる「Plane」(床)を作成する。
2.編集モードにして右クリックで細分化を選択する。
3.「10」ぐらいにして、細分化する。
スクリーンショット 2021-06-17 1.35.28.png
4.UV展開して、水面テクスチャを貼る。
5.FBX形式にエクスポートする。
スクリーンショット 2021-06-17 1.41.31.png
メッシュは必ず選んで、エクスポートすること。
スクリーンショット 2021-06-17 1.42.46.png

Unityで水面を揺らしてみる

1.水面の3Dモデル(FBX)を取り込む
2.水面のテクスチャを取り込む
3.水面のマテリアルを作成する。「Create」-「Material」で作成する。
4.水面のゆらゆらのシェダーを作成する。「Create」-「Shader」-「Unlit Shader」
5.水面のマテリアルに、シェダーを配置する。Drag&Dropで重ねると反映される。
スクリーンショット 2021-06-17 1.54.28.png

シェダーの作成

「Create」-「Shader」-「Unlit Shader」で作成しました。
1.水面の揺れのスピードを設定。
2.水面の揺れの周期を設定。
3.水面の揺れの振り幅を設定。
4.水面のテクスチャを少し透明に設定。

TrySea02Shader

Shader "Unlit/TrySea02Shader"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _Speed("Speed ",Range(0, 100)) = 2
        _SwingCycle ("SwingCycle", Range(0.0,30.0) ) = 9.0 // 揺れの周期
        _Amplitude ("Amplitude", Range(0,1.0) ) = 0.07 // 振り幅        
    }
    SubShader {
        // 水面を少し透明に設定する
        Tags { "RenderType"="Transparent"  "Queue" = "Transparent"}
        Blend SrcAlpha OneMinusSrcAlpha
        LOD 200

        CGPROGRAM
        #pragma surface surf Lambert vertex:vert alpha
        #pragma target 3.0

        sampler2D _MainTex;
        float _Speed;
        float _SwingCycle;
        float _Amplitude;
        fixed4 _Color;
        
        struct Input {
            float2 uv_MainTex;
        };

        void vert(inout appdata_full v) {
            // スピードを設定する
            float time     = _Time.y * _Speed;
            // 揺れ幅を設定
            float offsetY  = sin(time + v.vertex.x * _SwingCycle) + sin(time + v.vertex.z * _SwingCycle);
            offsetY         *= _Amplitude;
            v.vertex.y      += offsetY;   
        }

        void surf(Input IN, inout SurfaceOutput o) {            
            fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
            o.Albedo = c.rgb;
            // 水面の透明度を0.7に設定する
            c.a = 0.7f;
            o.Alpha = c.a;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

1
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?