参考ページ。今回は地形。普段ホロばっかなので地形を触るのは新鮮。 nn-hokuson.hatenablog.com
今回はブレンドする2枚のテクスチャ、またブレンドパターンが必要になります。
素材はpower p(以下略
Texture1
Texture2
マスク
ブレンドするシェーダ
Shader "Custom/sample" { Properties{ //Texture 1 _MainTex("Main Texture", 2D) = "white" {} //Texture 2 _SubTex("Sub Texture", 2D) = "white" {} //マスク _MaskTex("Mask Texture", 2D) = "white" {} } SubShader{ Tags{ "RenderType" = "Opaque" } LOD 200 CGPROGRAM #pragma surface surf Standard fullforwardshadows #pragma target 3.0 sampler2D _MainTex; sampler2D _SubTex; sampler2D _MaskTex; struct Input { //テクスチャのuv座標を使うため、 //Input構造体にuv_MainTexを宣言 float2 uv_MainTex; }; void surf(Input IN, inout SurfaceOutputStandard o) { fixed4 c1 = tex2D(_MainTex, IN.uv_MainTex); fixed4 c2 = tex2D(_SubTex, IN.uv_MainTex); fixed4 p = tex2D(_MaskTex, IN.uv_MainTex); //マスクが白(1)に近い場合 テクスチャ1を強め //マスクが黒(0)に近い場合 テクスチャ2を強め //Color = Texture1 * p + Texture2 * (1-p) //RGBで書くと //color.r = c1.r * p + c2.r * (1-p); //color.g = c1.g * p + c2.g * (1-p); //color.b = c1.b * p + c2.b * (1-p); //lerp(c2, c1, p) c1とc2の間を補間する //p = 0 (黒) -> c2のテクスチャのみ表示 //p = 1 (白) -> c1のテクスチャのみ表示 o.Albedo = lerp(c2, c1, p); } ENDCG } FallBack "Diffuse" }
結果
ブレンドするノード
完成図
PropertyにTextureを3つAddします。
Math->Interpolation(補間)->Lerpのノードを作成し、
AにSubTexture
BにMainTexture
TにMaskを適応します。
最後にoutをAlbedoに入れてやれば完成です。
Textureの利用が増えてきたので、素材作りも何か考えないといけないですね…