【问题标题】:Unity 5 renderer.material.setTexture("_PARALLAXMAP"); Won't change the heightmapUnity 5 renderer.material.setTexture("_PARALLAXMAP");不会改变高度图
【发布时间】:2016-01-12 20:17:20
【问题描述】:

所以我一直在研究一段代码,它可以生成柏林噪声纹理并将其应用于平面以创建波浪。但我无法设置材质的高度图纹理。我已经包含了material.EnableKeyword("_PARALLAXMAP");,但它什么也没做。我也用法线贴图试过这个,但没有结果。这是完整的代码。

using UnityEngine;
using System.Collections;    

public class NoiseGenerator : MonoBehaviour {
    private Texture2D noiseTex;
    private float x = 0.0F;
    private float y = 0.0F;
    public int scale = 10;
    private Color[] pixels;
    public float speed;
    public float move = 0.0F;
    void Start () {
        Renderer render = GetComponent<Renderer>();
        noiseTex = new Texture2D(scale,scale);
        render.material = new Material(Shader.Find("Standard"));
        render.material.EnableKeyword("_PARALLAXMAP");
        render.material.SetTexture("_PARALLAXMAP", noiseTex);
        pixels = new Color[noiseTex.width * noiseTex.height];
    }
    void Update () {
        float y = 0.0F;
        while (y < noiseTex.height)
        {
            float x = 0.0F;
            while (x < noiseTex.width)
            {
                float xCoord = move + x / noiseTex.width * scale;
                float yCoord = move + y / noiseTex.height * scale;
                float sample = Mathf.PerlinNoise(xCoord, yCoord);
                pixels[Mathf.RoundToInt(y) * noiseTex.width + Mathf.RoundToInt(x)] = new Color(sample, sample, sample);
                x++;
            }
            y++;
        }
        noiseTex.SetPixels(pixels);
        noiseTex.Apply();
        move = move + speed;
    }
}    

【问题讨论】:

  • 是shader中纹理参数的实际名称_PARALLAXMAP?
  • 根据统一的站点,我尝试了其他变体,例如_parallaxmap、_ParallaxMap、_BumpMap、_NormalMap。没有任何效果。
  • 只有设置为_MainTex才有效。
  • 存在哪些值将完全取决于相关着色器。在我自己的代码中,我能够使用“_SecondaryTexture”,因为我使用的着色器具有该属性,我知道它确实如此,因为我编写了着色器。
  • heigtmap 槽中是否应用了初始纹理?正在使用哪个着色器?

标签: c# unity3d textures perlin-noise


【解决方案1】:

您需要包含一个使用此视差变体的材质,以通知 Unity 您需要它。 这可以在场景中使用或包含在资源文件夹中。 如果不是 Unity,请在构建时忽略这一点。

【讨论】:

    【解决方案2】:

    随便用

    ur_material.SetFloat("_Parallax",[value])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-24
      • 1970-01-01
      相关资源
      最近更新 更多