c# - 地形地面,城市中的草地和雪地 : Skylines

标签 c# unity3d cities-skylines-api

我正在为《城市:天际线》制作四季模组。我的方法有点不错,我找到了一种将地面纹理更改为雪地纹理的方法,方法是使用

mat.SetTexture("_TerrainGrassDiffuse", grassTexture);

所以这很好,但我不希望在季节之间进行硬切换。所以我想出了这个主意:在雪和草纹理之间进行 Lerping。谷歌搜索了很多,但我没有想出任何有用的东西。所以我想要一个在给定时间内淡出雪纹理并淡出草纹理的插值,所以我认为插值就在这里。我无法访问着色器,因为它是一个模组,我需要为此反编译.. 我尝试使用

someMat.Lerp();
但我不知道我需要为 someMat 使用哪种 Material 。 感谢您的帮助!

最佳答案

首先,我想指出 someMat.Lerp(); 不是您问题的解决方案。 material Lerp() 函数用于更改颜色,同时保留原始着色器和纹理。正如您希望对纹理进行 lerp,情况并非如此。

此外,我不认为有一种构建方式可以统一 lerp 纹理。但似乎您可以使用着色器来规避此问题。经过短暂的谷歌搜索后,我找到了这个 UnityScript 解决方案 source ,带有一个简单而漂亮的着色器实现解决方案示例

着色器和相关代码示例也可以在下面看到。

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"
}

关于c# - 地形地面,城市中的草地和雪地 : Skylines,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33782280/

相关文章:

c# - MaxDegreeOfParallelism 有什么作用?

c# - Selenium 如何使用 chromedriver 和 C# 清除缓存

unity3d - SceneManager LoadScene 在编辑器播放模式下不工作

git - 为什么忽略的文件没有被忽略?

unity3d - Unity UI 文本变黑

c# - 为什么这个添加的 UI 按钮的事件没有被调用?

C# 复杂的 TreeView 设计

c# - 计算二进制数中 1 的运行次数/集合