Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terrain Ground, lerp Grass and Snow in Cities: Skylines

I am working on a Seasons Mod for Cities: Skylines. My way is kind of good, and I found a way to change the ground texture to a snowy one by using

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!
like image 793
Johnny Verbeek Avatar asked Nov 10 '22 01:11

Johnny Verbeek


1 Answers

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);
      }

 }
}

and the sample shader as given in the blog:

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"
}
like image 53
MX D Avatar answered Nov 14 '22 21:11

MX D