0

So I have been working on a piece of code that generates a perlin noise texture and applies it to a plane in order to create waves. But I can't get it to set the heightmap texture of the material. I have included material.EnableKeyword("_PARALLAXMAP"); but it does nothing. I have tried this with the normal map as well, without results. Here's the full code.

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;
    }
}    
Pang
  • 9,564
  • 146
  • 81
  • 122
Somebody
  • 333
  • 3
  • 12

2 Answers2

0

You need to include a Material that use this Parallax variant to notify Unity about you need this. This can be used in the scene or include in the resource folder. If not Unity omit this on build how unused.

joreldraw
  • 1,736
  • 1
  • 14
  • 28
0

Just use

ur_material.SetFloat("_Parallax",[value])
Pang
  • 9,564
  • 146
  • 81
  • 122