地形地面,在《城市:天际线》中平滑过渡草地和雪地

5

我正在为《城市:天际线》制作一个季节模组。我的方法还算不错,我找到了一种方法,可以通过使用HTML标签将地面纹理更改为雪地。

mat.SetTexture("_TerrainGrassDiffuse", grassTexture);

So that is working fine, but i dont want a hard cut between the seasons. So I came up with this idea: Lerping between the snow and the grass texture. Googled much, but I didn't come up with anything which works. So I want a lerp which fades in the snow texture and fades out the grass texture by a given amount of time, so I think a lerp is right here. I have no access to the shader, cause its a mod, and I would need decompiling for that.. I tried using

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

1个回答

1
首先我想指出,someMat.Lerp(); 不是 你问题的解决方案。 material Lerp() 函数用于更改颜色,同时保留原始着色器和纹理。由于您希望lerp纹理,因此情况并非如此。
此外,我认为在Unity中没有内置的方法来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"
}

好的,感谢您的回答,但正如我所说,我无法访问内置着色器,而创建自己的着色器会导致地面质量更差。也许我只需要从Unity文件中提取着色器,并构建类似的东西。所以我这样做了,但是这个着色器有30000行,我在这个混乱中找不到自己的位置。 - Johnny Verbeek
@iRedCraft 你可能想要查看一下修改论坛。许多着色器甚至被识别为原生的Unity着色器,这将大大简化操作。 - MX D
好的,我已经在Reddit上完成了:https://www.reddit.com/r/CitiesSkylinesModding/comments/3tb32u/changing_ground_textures_new_terrain_shader/ 无论如何还是谢谢 :) - Johnny Verbeek

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接