赞
踩
效果说明示例:
使用纹理贴图示例:
混合系数贴图示例:
- Shader "Custom/BasicDiffuse"
- {
- //属性
- Properties
- {
- _MainTint("Diffuse Tint",Color)=(1,1,1,1)
- _ColorA("Terrain Color A",Color)=(1,1,1,1)
- _ColorB("Terrain Color B",Color)=(1,1,1,1)
- _RTexture("Red Channel Texture",2D) = ""{}
- _GTexture("Green Channel Texture",2D) = ""{}
- _BTexture("Blue Channel Texture",2D) = ""{}
- _ATexture("Alpha Channel Texture",2D) = ""{}
- _BlendTex("Blend Texture",2D) = ""{}
- }
-
- SubShader
- {
- //渲染类型为不透明物体
- Tags{"RenderType" = "Opaque"}
-
- //层级细节
- LOD 200
-
- CGPROGRAM
-
- //编译指令,定义表面着色器和将要使用的光照模型Lambert(漫反射)
- #pragma surface surf Lambert
-
- //声明属性关联
- float4 _MainTint;
- float4 _ColorA;
- float4 _ColorB;
- sampler2D _RTexture;
- sampler2D _GTexture;
- sampler2D _BTexture;
- sampler2D _ATexture;
- sampler2D _BlendTex;
-
- //表面着色器输入结构体
- struct Input
- {
- //纹理的UV坐标值
- float2 uv_RTexture;
- float2 uv_GTexture;
- float2 uv_BTexture;
- float2 uv_ATexture;
- float2 uv_BlendTex;
- };
-
- //表面着色器
- void surf(Input IN, inout SurfaceOutput o)
- {
- float4 blendData = tex2D(_BlendTex, IN.uv_BlendTex);
- float4 rTexData = tex2D(_RTexture, IN.uv_BlendTex);
- float4 gTexData = tex2D(_GTexture, IN.uv_BlendTex);
- float4 bTexData = tex2D(_BTexture, IN.uv_BlendTex);
- float4 aTexData = tex2D(_ATexture, IN.uv_BlendTex);
-
- //使用线性插值对纹理进行混合
- float4 finalColor;
- finalColor = lerp(rTexData, gTexData, blendData.g);
- finalColor = lerp(finalColor, bTexData, blendData.g);
- finalColor = lerp(finalColor, aTexData, blendData.g);
- finalColor.a = 1.0;
-
- //将混合纹理与色调值相乘,并使用红色通道来确定两个不同地形将形成怎样的色调
- float4 terrainLayers = lerp(_ColorA, _ColorB, blendData.r);
- finalColor *= terrainLayers;
- finalColor = saturate(finalColor);
-
- o.Albedo = finalColor.rgb * _MainTint.rgb;
- o.Alpha = finalColor.a;
- }
- ENDCG
- }
- FallBack "Diffuse"
- }
材质球设置
效果图:
lerp()函数
lerp(a,b,f) ---功能描述--->(1-f)*a+b*f
效果示例:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。