Creating a radial gradient in c#

Hi, I’m currently playing with unity and learning c# while I’m at it. I’m having trouble creating some thing like a radial gradient to subtract from perlin noise.

The perlin noise is done. I use the sample value from that to create a sprite. The sprite its self is set depending on the value of sample value, for example so 0 is ocean and 1 is grass.

This is the current script (I’ve removed the irrelevant info):

public int mapWidth;
public int mapHeight;
public float xOrg;
public float yOrg;
public float scale = 10f;

public GameObject tSprite;

void Start()
    {
        CalcNoise();
    }

    void CalcNoise()
    {
        float y = 0.0F;
    while (y < mapHeight)
        {
            float x = 0.0F;
        while (x < mapWidth)
            {
                //Origin +
                float xCoord = xOrg + x / mapWidth * scale;
                float yCoord = yOrg + y / mapHeight * scale;
                float sample = Mathf.PerlinNoise(xCoord, yCoord);

                //Debug.Log (sample);
                Instantiate(tSprite, new Vector3(x, y), Quaternion.identity);
                x++;
            }
            y++;
        }
    }
}

What I need to do is create a radial fall off/gradient that I can subtract from the sample float in the perlin noise.
This would/should then result in:

This is what I currently have:

So as you can see I’m about half way through.

I need to figure out a way of creating the gradient in the same loop as the perlin noise so that I can then subtract the gradient from the sample float.

I’ve searched about the place but I’ve been unable to find info that will assist me.

Is any one willing to help?

Thanks!!!

Is there a particular reason you can’t have a static texture and use GetPixels() to get numbers, then subtract those from the perlin noise texture? If it doesn’t need to change, why make it at runtime?

Hey, Thanks for the response. That is deffo an option I’m considering now that I know that it is an option.

But say for example if I were to let the player decide the map size when they were starting a game? would this be possible?

I could give it ago and have multiple sizes of the gradient texture I suppose.

Can’t you just use polar coordinates, and have the radius define the height?

Texture lookups are a good idea for this, because they make it super easy to customise. You can easily scale to match the player size too.

That said, the mathematics for circles are easy. Just check the distance of the point from the centre of the circle.