概要
v2f vert(appdata_t v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); o.color = v.color; return o; } fixed4 frag(v2f i): SV_Target { fixed4 col = 2.0f * i.color * _TintColor * tex2D(_MainTex, i.texcoord); return col; }
例えば、上記のようにフラグメントシェーダで色の計算を行うのではなく
v2f vert(appdata_t v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex); o.color = 2.0f * v.color * _TintColor; return o; } fixed4 frag(v2f i): SV_Target { fixed4 col = i.color * tex2D(_MainTex, i.texcoord); return col; }
事前に頂点シェーダで色の計算を済ませるほうが良いパフォーマンスになる