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 Bunnybomb7670 · May 29, 2013 at 03:42 PM · debugissueperlin noisenoiseperlin

Unity Perlin Noise Bug?

I was testing Perlin noise and I think I found a bug / issue with it. For some reason this code :

 float a = Mathf.PerlinNoise(16+i,16+j);

Works fine, but doing this :

 float a = Mathf.PerlinNoise(16+i/j,16+j/i);

Does not work, as in it does not calculate it, and trying to debug.log the value doesn't even call the debug function. I have no idea why this is not working. I am using Unity 4 ( latest ) and it is really starting to bug me

The whole function is :

     for( int i = 0;i<16;i++){
             for( int j = 0;j<16;j++){

                 float Perlin1 = Mathf.PerlinNoise(((float)i+chunkPosX)/x_,((float)j+chunkPosZ)/z_);
                 float Perlin2 = Mathf.PerlinNoise(((float)j+chunkPosZ)/z_,((float)i+chunkPosX)/x_);
                 int y = (int)Mathf.Round(Perlin1*20*Perlin2);
                 voxels[i,(int)y,j]=new Vox(voxelDatabase[1],1);
             }
         }
     }
Comment
Add comment · Show 1
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
avatar image Bunnybomb7670 · May 29, 2013 at 04:56 PM 0
Share

That seemed to work, the code you suggested but diving i by j or the other way round doesnt work at all. I rewrote my function, could you see what i would need to cast ?

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by hiddenspring81 · May 29, 2013 at 04:17 PM

According to the documentation on Unity's website, both i and j need to be floating point values from 0 to 1. Have you tried,

 float a = Mathf.PerlinNoise((float)i / 16.0f, (float)j / 16.0f);


Comment
Add comment · Show 6 · Share
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
avatar image Bunnybomb7670 · May 29, 2013 at 05:02 PM 0
Share

The thing is, the values, in Javascript work , the same values, but in c# they dont. I dont get why they wont work in c# but work in Js just fine. And yes, they are more than 0-1 but the JS ones were too but still returned values.

avatar image hiddenspring81 · May 29, 2013 at 05:40 PM 0
Share

Out of curiosity, are you running this on the main-thread, or are you spawning a background thread?

avatar image hiddenspring81 · May 29, 2013 at 05:42 PM 0
Share

Also, can you define what you mean by "they won't work in C#"?

avatar image Bunnybomb7670 · May 29, 2013 at 07:01 PM 0
Share

Seems to not work on a background thread, I am using multithreading to generate the values in the background, I also tried it inside the main thread and it didnt work either. I mean by not working in c# as that I converted the code from JS to C# using the same values, it works in JS but not in C#.

avatar image hiddenspring81 · May 29, 2013 at 07:08 PM 1
Share

You cannot use any Unity library on any other thread other than the main-thread. Weird shit happens if you try and use any Unity library function on a background thread.

Show more comments
avatar image
1

Answer by Llockham-Industries · Dec 03, 2015 at 11:59 AM

Okay, You are declaring 2 ints in C#. Dividing ints will always result in ints.. ie. whole integers.. if you were running this on the primary thread it would likely be giving you errors telling you it requires floats

cast one of your int's to a float and it should resolve the issue..

The reason the same method works in unityscript is because unityscript uses ambiguous variables, that become whatever they need to be.. in this case, mathf.perlin noise requests a float, so the variables become floats..

as for whether or not it's thread safe.. i see no reason it wouldn't be.. but test it, unity will generally log an error something along the lines of..

!Thread::EqualsCurrentThreadID(m_MainThreadID)

if your using something that's strictly not safe.. it's just a fixed equation that returns a fixed result, it uses no variables outside it's own scope.. so you should be okay..

Comment
Add comment · Share
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
avatar image
0

Answer by gameplaydev · Jun 20, 2014 at 04:38 PM

float a = Mathf.PerlinNoise(16+i/j,16+j/i);

Divide by zero?

Comment
Add comment · Share
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

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

16 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

Related Questions

Always same result from Mathf.PerlinNoise() 2 Answers

How to use Perlin Noise for waves 0 Answers

Perlin noise problem 0 Answers

Perlin Noise Issue 0 Answers

3D Perlin Noise mesh even in all axes 1 Answer


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