2015年2月11日水曜日

Unityでvertex modifier関数からSurfaceShaderにパラメータを渡す


普通にInput構造体に自分独自のメンバ追加して渡せるみたい。

Shader "Custom/MyShader" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200

CGPROGRAM

#pragma surface surf BlinnPhong vertex:vert

sampler2D _MainTex;

struct Input {
float2 uv_MainTex;
float3 myvalue; // surf関数に渡したい値
};

void vert (inout appdata_full v, out Input o) { // 第二引数にout Input o追加
o.myvalue = 0.5; // 代入
}

void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb * IN.myvalue;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}

0 件のコメント:

コメントを投稿