【问题标题】:Terrain Ground, lerp Grass and Snow in Cities: Skylines城市中的地形地面、草和雪:天际线
【发布时间】:2015-11-18 14:11:09
【问题描述】:

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

mat.SetTexture("_TerrainGrassDiffuse", grassTexture);

所以效果很好,但我不想在季节之间进行硬切。所以我想出了这个想法:在雪和草的质地之间徘徊。谷歌搜索了很多,但我没有想出任何有效的方法。所以我想要一个 lerp 在给定的时间内淡化雪纹理并淡出草纹理,所以我认为 lerp 就在这里。我无法访问着色器,因为它是一个 mod,我需要为此反编译.. 我尝试使用

someMat.Lerp();
但我不知道 someMat 需要使用哪种材料。 感谢帮助!

【问题讨论】:

    标签: c# unity3d cities-skylines-api


    【解决方案1】:

    首先我想指出someMat.Lerp(); 不是解决您的问题的方法。 material 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"
    }
    

    【讨论】:

    • 嗯,感谢您的回答,但正如我所说,我无法使用内置着色器,创建自己的着色器会导致实际质量更差。也许我只需要从统一文件中提取着色器,并在其中构建一些相关的东西。所以我就这么做了,但是着色器有 30000 行,我很难在混乱中找到自己......
    • @iRedCraft 你可能想看看改装论坛。有时甚至会识别本机统一着色器的分配着色器。这将简化它的分配。
    • 好的,我在 reddit 上做到了:reddit.com/r/CitiesSkylinesModding/comments/3tb32u/… 无论如何谢谢 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-25
    • 1970-01-01
    • 1970-01-01
    • 2020-05-14
    • 2011-08-12
    相关资源
    最近更新 更多