LoginSignup
1
0

More than 5 years have passed since last update.

シェーダーの練習でパーティーボールもどきを作った

Last updated at Posted at 2018-04-04

パーティボールもどきをサーフェースシェーダーで書いてみた(もどきですらないけど)
コードは以下。

    Properties{
        _Diffuse("Diffuse Color", color) = (0, 0, 0, 1)
        _EmissionColor("Emission Color", color) = (1, 1, 1, 1)
    }

    SubShader{

        Tags {"RenderType" = "Opaque"}

        CGPROGRAM
        #pragma surface surf Lambert finalcolor:outemission vertex:yaxis

        struct Input {

            float customData_1;
            float customData_2;
        };

        float4 _Diffuse;
        float4 _EmissionColor;

        void yaxis(inout appdata_full v, out Input data) {

            UNITY_INITIALIZE_OUTPUT(Input, data);
            data.customData_1 = max(0, 0.5 * sin((v.vertex.y + _Time.x * 5) * 3.14159 * 8));
            data.customData_2 = max(0, 0.5 * sin((v.vertex.x + _Time.x * 5) * 3.14159 * 8));
        }

        void outemission(Input IN, SurfaceOutput o, inout fixed4 color) {
            color += (_EmissionColor * IN.customData_1 + _EmissionColor * IN.customData_2);
        }

        void surf(Input IN, inout SurfaceOutput o) {
            o.Albedo = _Diffuse;
        }
        ENDCG
    }
    FallBack "Diffuse"

実行時はこんな感じ。
スクリーンショット (3).png

このクロスした白線が時間に応じて動く感じです。サーフェースシェーダーのモディファイヤーを使って、アウトプットを加工してます。
個人的に、引数に戻り値を定義するところあたり、どうにも不快感があります。

1
0
1

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
0