Hi all, I have some issues generating a perlin noise texture and assigning it to a Quad (tried plane as well to no avail).
It’s very likely that I’m doing something rather stupid, I’m still very new with Unity. I spent the last day making changes and narrowing down the problem but I’ve hit a roadblock. I even looked at examples and other forum posts but it didn’t make me any wiser. If I overlooked a post that you think could help me please do! ![]()
I used the code found in Unity Reference and converted it to C#, not sure it went wrong in the conversion somewhere?
The Quad is 360 x 360 units. I already have a pixel perfect camera set up where 1 unit is a pixel.
As you can see in the code below I added a couple extra lines for reference pixels to make sure it’s not related to UV problems on the quad. That doesn’t seem to be the case as “noiseTex.SetPixel (50, 50, Color.White);” does render a white pixel at 50,50 (and 310,310).
It doesn’t seem to be a lighting problem either because if I add a texture from my assets list and assign it to the Quad it shows up just fine. Cast receive shadows is disabled on the Quad in any case.
So I’ve reached the end of my abilities so it seems.
The problem I’m getting is that the whole Quad is colored grey and does not look like a perlin noise map with greyscale values per pixel. Expected: The whole Quad to look like this, obviously a bit different according to what scale and origin values I use (I did try a whole range of values but none made it look any different).

using UnityEngine;
using System.Collections;
public class PerlinNoiseTexture : MonoBehaviour
{
// Use this for initialization
// Create a texture and fill it with Perlin noise.
// Try varying the xOrg, yOrg and scale values in the inspector
// while in Play mode to see the effect they have on the noise.
// Width and height of the texture in pixels.
int pixWidth = 360;
int pixHeight = 360;
// The origin of the sampled area in the plane.
float xOrg = 0.0f;
float yOrg = 0.0f;
// The number of cycles of the basic noise pattern that are repeated
// over the width and height of the texture.
float scale = 1.0f;
Texture2D noiseTex;
Color[] pix;
void Start ()
{
// Set up the texture and a Color array to hold pixels during processing.
noiseTex = new Texture2D(pixWidth, pixHeight, TextureFormat.RGB24, false);
pix = new Color[noiseTex.width * noiseTex.height];
renderer.material.mainTexture = noiseTex;
CalcNoise();
}
// Update is called once per frame
void Update ()
{
//CalcNoise ();
}
void CalcNoise()
{
// For each pixel in the texture...
for (int y = 0; y < noiseTex.height; y++)
{
for (int x = 0; x < noiseTex.width; x++)
{
// Get a sample from the corresponding position in the noise plane
// and create a greyscale pixel from it.
float xCoord = xOrg + x / noiseTex.width * scale;
float yCoord = yOrg + y / noiseTex.height * scale;
float sample = Mathf.PerlinNoise(xCoord, yCoord);
pix[y * noiseTex.width + x] = new Color(sample, sample, sample);
}
}
// Copy the pixel data to the texture and load it into the GPU.
noiseTex.SetPixels(pix);
noiseTex.SetPixel (50, 50, Color.white);
noiseTex.SetPixel (310, 310, Color.white);
noiseTex.Apply();
}
}