強火で進め

このブログではプログラム関連の記事を中心に書いてます。

(Cg)Vertexシェーダで cos の値を使ってポリゴンを移動


以下のページの兵士の顔を膨張させるサンプルコードを元に作成。

Unity - Surface Shader Examples
http://unity3d.com/support/documentation/Components/SL-SurfaceShaderExamples.html

Vertexシェーダの部分を以下の様に変更。

    void vert (inout appdata_full v) {
        v.vertex.x += _CosTime.w * 10;
    }

プログラムの全体はこちら。

Shader "test" {
  Properties {
    _MainTex ("Texture", 2D) = "white" {}
  }
  SubShader {
    Tags { "RenderType" = "Opaque" }
    CGPROGRAM
    #pragma surface surf Lambert vertex:vert
    struct Input {
        float2 uv_MainTex;
    };
    void vert (inout appdata_full v) {
        v.vertex.x += _CosTime.w * 10;
    }
    sampler2D _MainTex;
    void surf (Input IN, inout SurfaceOutput o) {
        o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
    }
    ENDCG
  } 
  Fallback "Diffuse"
}