Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by thizzhead · Apr 14, 2021 at 09:12 PM · procedural generationperlin noise

Perlin noise low resolution when scaling

Hi I've been playing around with perlin noise for a while. The issue occurred when I tried to scale down the perlin noise coordinates to create a texture which has much lower value differences but also perserving as much detail as possible. Creating a 4096x4096 texture with a scale factor of 0.1 creates a texture which is heavily pixelated. Here is the output:

Generating a map with resolution of 512x512 and scale of 0.1 results in exactly the same image but with lower output resolution. Changing the scale to 1 makes the squares (that somewhat resemble pixels) much smaller on both resolutions but it also makes the perlin noise features much smaller, as can be seen in the image below.

My expected result would be that the amount of these squares or "pixels" would be the same as the pixel count of the generated texture but that's not the case. For the purpose of generating the noise I'm using the built in Math.PerlinNoise() method.

Here is the code that I used for the purpose of generating the noise:

 public static float[,] GenerateNoiseMap(int width, int height, float scale, int seed, int octaves, float persistance, float lacunarity, Vector2 offset)
 {
     float[,] noiseMap = new float[width, height];
 
     System.Random prng = new System.Random(seed);
 
     Vector2[] octaveOffsets = new Vector2[octaves];
 
     for (int o = 0; o < octaves; o++)
     {
         float offsetX = prng.Next(-100000, 100000);
         float offsetY = prng.Next(-100000, 100000);
         octaveOffsets[o] = new Vector2(offsetX, offsetY);
     }
 
     scale = Mathf.Clamp(scale, 0.0001f, float.MaxValue);
 
     float maxNoiseHeight = float.MinValue;
     float minNoiseHeight = float.MaxValue;
 
     for (int y = 0; y < height; y++)
     {
         for (int x = 0; x < width; x++)
         {
             float amplitude = 1;
             float frequency = 1;
             float noiseHeight = 0;
 
             for (int o = 0; o < octaves; o++)
             {
                 float sampleX = (float) x / width * scale * frequency + octaveOffsets[o].x + offset.x;
                 float sampleY = (float) y / height * scale * frequency + octaveOffsets[o].y + offset.y;
 
                 float perlinValue = Mathf.PerlinNoise(sampleX, sampleY) / 2 - 1;
                 noiseHeight += perlinValue * amplitude;
 
                 amplitude *= persistance;
                 frequency *= lacunarity;
             }
             if (noiseHeight > maxNoiseHeight)
             {
                 maxNoiseHeight = noiseHeight;
             } else if (noiseHeight < minNoiseHeight)
             {
                 minNoiseHeight = noiseHeight;
             }
             noiseMap[x, y] = noiseHeight;
         }
     }
 
     for (int y = 0; y < height; y++)
     {
         for (int x = 0; x < width; x++)
         {
             noiseMap[x, y] = Mathf.InverseLerp(minNoiseHeight, maxNoiseHeight, noiseMap[x, y]);
         }
     }
 
     return noiseMap;
 }

The settings that I used during generation: height=4096, width = 4096, scale = 0.1, octaves = 8, persistance = 0.2, lacunarity = 2, seed = 0, offset = (0, 0).

And here is the code I used to convert the perlin noise float array to a Texture:

 public static Texture2D Float2DToTexture2D(float[,] array)
 {
     int width = array.GetLength(0);
     int height = array.GetLength(1);
 
     Texture2D noiseTexture = new Texture2D(width, height);
 
     Color32[] colorMap = new Color32[width * height];
 
     for (int y = 0; y < height; y++)
     {
         for (int x = 0; x < width; x++)
         {
             colorMap[y * width + x] = Color32.Lerp(Color.black, Color.white, array[x, y]);
         }
     }
 
     noiseTexture.SetPixels32(colorMap);
     noiseTexture.Apply();
 
     return noiseTexture;
 }

Am I missing something in my usage of the PerlinNoise() method or is this a limitation of its implementation in Unity?

I'm using Unity 2021.1.0f.

Thank you in advance.

409601.png (40.3 kB)
40961.png (86.8 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

117 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unexpected period length with Unity Mathematics pnoise method 0 Answers

Strange texture2d behaviour 0 Answers

Perlin Noise not working properly when using offset 0 Answers

Advice on 2D Surface Terrain Generation Using Noise 1 Answer

I wanna know how to randomize perlin noise 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges