【发布时间】: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