Joh*_*eek 5 c# unity-game-engine cities-skylines-api
我正在为城市的四季Mod:Skylines工作.我的方式很好,我找到了一种方法,通过使用将地面纹理改为雪地纹理
mat.SetTexture("_TerrainGrassDiffuse", grassTexture);
Run Code Online (Sandbox Code Playgroud)
所以这很好,但我不希望季节之间有一个难切.所以我提出了这个想法:在雪和草纹理之间徘徊.谷歌搜索很多,但我没有提出任何有用的东西.所以我想要一个在雪纹理中消失的lerp,并在一定的时间内淡化草纹理,所以我认为lerp就在这里.我没有访问着色器,导致它的mod,我需要反编译..我尝试使用
someMat.Lerp();但我不知道我需要为someMat使用哪种材料.感谢帮助!
首先,我想指出这someMat.Lerp();并不是解决您问题的方法。该material Lerp()函数用于更改颜色,同时保留原始着色器和纹理。当您希望对纹理进行 lerp 处理时,情况并非如此。
此外,我认为没有一种构建方式可以统一 lerp 纹理。但似乎你可以使用着色器来规避这个问题。经过短暂的谷歌搜索后,我找到了这个 UnityScript 解决方案源,其中包含着色器实现的解决方案的简单而漂亮的示例
Shader和相关代码示例也可以参见下面。
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
以及博客中给出的示例着色器:
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"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
454 次 |
| 最近记录: |