FreshRSS

Normální zobrazení

Jsou dostupné nové články, klikněte pro obnovení stránky.
PředevčíremHlavní kanál
  • ✇Recent Questions - Game Development Stack Exchange
  • Why is my perlin-noise generated texture a uniform grey?FNaF_Master109
    I'm following Brackeys' tutorial for perlin noise and i'm at the point where he's just done the offset thing but this whole time all that i'm seeing in my project is a plain gray square, no matter what settings i change. Here's my code: using UnityEngine; public class PerlinNoise : MonoBehaviour { public int width = 256; public int height = 256; public float scale = 20f; public float offsetX = 100f; public float offsetY = 100f; void Update () { Renderer re
     

Why is my perlin-noise generated texture a uniform grey?

I'm following Brackeys' tutorial for perlin noise and i'm at the point where he's just done the offset thing but this whole time all that i'm seeing in my project is a plain gray square, no matter what settings i change. Here's my code:

using UnityEngine;

public class PerlinNoise : MonoBehaviour
{
    public int width = 256;
    public int height = 256;

    public float scale = 20f;

    public float offsetX = 100f;
    public float offsetY = 100f;

    void Update ()
    {
        Renderer renderer = GetComponent<Renderer>();
        renderer.material.mainTexture = GenerateTexture();
    }

    Texture2D GenerateTexture ()
    {
        Texture2D texture = new Texture2D(width, height);

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                Color color = CalculateColor(x, y);
                texture.SetPixel(x, y, color);
            }
        }

        texture.Apply();
        return texture;
    }

    Color CalculateColor (int x, int y)
    {
        float xCoord = (float)x / width * scale + offsetX;
        float yCoord = (float)y / height * scale + offsetY;

        float sample = Mathf.PerlinNoise(x, y);
        return new Color(sample, sample, sample);
    }
}

Here's the result i get: A gray square with no visible noise.

and here's the settings in the editor: Unity editor script settings.

❌
❌