地形地面,城市里的草地和雪:天际线

本文关键字:天际线 草地 城市 | 更新日期: 2023-09-27 18:22:20

我正在为《城市的季节模型:天际线》工作。我的方法有点好,我找到了一种方法,通过使用将地面纹理更改为雪地纹理

mat.SetTexture("_TerrainGrassDiffuse", grassTexture);

所以这很好,但我不想在两个赛季之间有太大的差距。所以我想出了这个主意:在雪和草的纹理之间漫步。谷歌搜索了很多,但我没有找到任何有效的方法。所以我想要一个在一定时间内逐渐消失在雪纹理中并逐渐消失在草纹理中的lerp,所以我认为lerp就在这里。我无法访问着色器,因为它是一个mod,我需要为此进行反编译。。我试着用

someMat.Lerp();
but I don't know which material I need to use for the someMat. Thanks for help!

地形地面,城市里的草地和雪:天际线

First off I like to note that someMat.Lerp(); is not the solution for your problem. The material Lerp() function is used to change colors, while retaining the original shader and textures. As you wish to lerp the texture, this is not the case.

Further more I don't think there is a build in way to lerp textures in unity. But it seems you can use a shader to circumvent this issue. After a short googling trip I found this UnityScript solution source, with a simple and nice sample of the a shader implemented solution

Shader and relevant code sample can also be seen below.

public void Update ()
{
     changeCount = changeCount - 0.05;
     textureObject.renderer.material.SetFloat( "_Blend", changeCount );
      if(changeCount <= 0) {
           triggerChange = false;
           changeCount = 1.0;
           textureObject.renderer.material.SetTexture ("_Texture2", newTexture);
           textureObject.renderer.material.SetFloat( "_Blend", 1);
      }
 }
}

以及博客中给出的示例着色器:

Shader "TextureChange" {
Properties {
_Blend ("Blend", Range (0, 1) ) = 0.5 
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Texture 1", 2D) = "white" {}
_Texture2 ("Texture 2", 2D) = ""
_BumpMap ("Normalmap", 2D) = "bump" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 300
Pass {
    SetTexture[_MainTex]
    SetTexture[_Texture2] { 
        ConstantColor (0,0,0, [_Blend]) 
        Combine texture Lerp(constant) previous
    }       
  }
 CGPROGRAM
 #pragma surface surf Lambert
sampler2D _MainTex;
sampler2D _BumpMap;
fixed4 _Color;
sampler2D _Texture2;
float _Blend;
struct Input {
    float2 uv_MainTex;
    float2 uv_BumpMap;
    float2 uv_Texture2;
};
void surf (Input IN, inout SurfaceOutput o) {
    fixed4 t1 = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    fixed4 t2 = tex2D (_Texture2, IN.uv_MainTex) * _Color;
    o.Albedo = lerp(t1, t2, _Blend);
    o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
}
ENDCG  
}
FallBack "Diffuse"
}