您的位置:首页 > 其它

通过顶点颜色,制作高级贴图混合效果····

2015-08-11 23:09 363 查看
这个技术在神秘海域和战争机器流行起来···
<img src="http://img.blog.csdn.net/20150811231022590?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
两个贴图融合的非常好···
Shader "Custom/7.4" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_SecondaryTex("Secondary Texture",2D) = "white"{}
_HeightMap("HeightMap",2D) = "white"{}
_Value("Value",Range(1,20))= 3
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200

CGPROGRAM
#pragma surface surf Lambert vertex:vert

sampler2D _MainTex;
sampler2D _SecondaryTex;
sampler2D _HeightMap;
float _Value;
struct Input {
float2 uv_MainTex;
float2 uv_SecondaryTex;
float3 vertColor;
};

void vert(inout appdata_full v,out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input,o);
o.vertColor = v.color.rgb;
}

void surf (Input IN, inout SurfaceOutput o) {
half4 base = tex2D (_MainTex, IN.uv_MainTex);
half4 secondTex=tex2D(_SecondaryTex,IN.uv_SecondaryTex);
float4 height = tex2D(_HeightMap,IN.uv_MainTex);

float redChannel = 1-IN.vertColor.r;//红色通道- - 红色越低就越高,越高就越低
float rHeight = height.r * redChannel;
float invertHeight = 1-height.r;
float finalHeight = (invertHeight * redChannel)*4;
float finalBlend = saturate(rHeight + finalHeight);
float hardness = ((1-IN.vertColor.g) * _Value) + 1;
finalBlend = pow(finalBlend,hardness);
float3 finalColor = lerp(base,secondTex,finalBlend);
o.Albedo = finalColor;
o.Alpha = base.a;
}
ENDCG
}
FallBack "Diffuse"
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: