{"action":"created","issue":{"url":"https://api.github.com/repos/cinder/Cinder/issues/1326","repository_url":"https://api.github.com/repos/cinder/Cinder","labels_url":"https://api.github.com/repos/cinder/Cinder/issues/1326/labels{/name}","comments_url":"https://api.github.com/repos/cinder/Cinder/issues/1326/comments","events_url":"https://api.github.com/repos/cinder/Cinder/issues/1326/events","html_url":"https://github.com/cinder/Cinder/issues/1326","id":135542078,"number":1326,"title":"Perlin noise 2d implementation problems","user":{"login":"deanm","id":56582,"avatar_url":"https://avatars.githubusercontent.com/u/56582?v=3","gravatar_id":"","url":"https://api.github.com/users/deanm","html_url":"https://github.com/deanm","followers_url":"https://api.github.com/users/deanm/followers","following_url":"https://api.github.com/users/deanm/following{/other_user}","gists_url":"https://api.github.com/users/deanm/gists{/gist_id}","starred_url":"https://api.github.com/users/deanm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deanm/subscriptions","organizations_url":"https://api.github.com/users/deanm/orgs","repos_url":"https://api.github.com/users/deanm/repos","events_url":"https://api.github.com/users/deanm/events{/privacy}","received_events_url":"https://api.github.com/users/deanm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-02-22T21:01:10Z","updated_at":"2016-02-22T23:27:46Z","closed_at":null,"body":"Basically the Cinder 2D Perlin noise is just 3D Perlin noise with a hardcoded z=0.  It uses the same 3D gradient dot products as 3D noise, but just again with z=0.  The problem with this is that 3D Perlin noise is designed with cube gradients, and behaves especially badly at z = 0 (and many others, integers probably being worse).  The 3D Perlin gradients are the midpoints on a cube, for a 2D implementation, for example, Stefan Gustavson says:\r\n\r\n\"A good choice for 2D and higher is to pick gradients of unit length but different directions. For 2D, 8 or 16 gradients distributed around the unit circle is a good choice. For 3D, Ken Perlin’s recommended set of gradients is the midpoints of each of the 12 edges of a cube centered on the origin.\"\r\n\r\nAttached is an image of Perlin noise with a z of 0, see the long horizontal lines, for example at Y=-1 when X < 0.  But in the image you can easily see several places where the entire edge of one or more neighbouring cells is zero across the entire cell.\r\n\r\n<img width=\"600\" src=\"https://cloud.githubusercontent.com/assets/56582/13232048/b4e61af4-d9ad-11e5-8518-5014d3b8c47e.png\">\r\n\r\nIf you were to do the same thing but with z = 0.1, you get something like this:\r\n\r\n<img width=\"600\" src=\"https://cloud.githubusercontent.com/assets/56582/13232218/80b44ff2-d9ae-11e5-8799-bbe3c9dcbcd1.png\">\r\n\r\nSo basically, it's not the best idea to implement 2D Perlin with 3D Perlin, and if you do it should at least be better to not use an integer value of z.  But really, you should implement it with a different set of 2d gradients altogether (ie distributed around a circle).  This would basically just involve a new Perlin::grad( int32_t hash, float x, float y ) function, which shouldn't be a very big change.\r\n\r\nJust mentioning @notlion and @meshula as they were part of other discussions on noise."},"comment":{"url":"https://api.github.com/repos/cinder/Cinder/issues/comments/187435669","html_url":"https://github.com/cinder/Cinder/issues/1326#issuecomment-187435669","issue_url":"https://api.github.com/repos/cinder/Cinder/issues/1326","id":187435669,"user":{"login":"deanm","id":56582,"avatar_url":"https://avatars.githubusercontent.com/u/56582?v=3","gravatar_id":"","url":"https://api.github.com/users/deanm","html_url":"https://github.com/deanm","followers_url":"https://api.github.com/users/deanm/followers","following_url":"https://api.github.com/users/deanm/following{/other_user}","gists_url":"https://api.github.com/users/deanm/gists{/gist_id}","starred_url":"https://api.github.com/users/deanm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deanm/subscriptions","organizations_url":"https://api.github.com/users/deanm/orgs","repos_url":"https://api.github.com/users/deanm/repos","events_url":"https://api.github.com/users/deanm/events{/privacy}","received_events_url":"https://api.github.com/users/deanm/received_events","type":"User","site_admin":false},"created_at":"2016-02-22T23:27:46Z","updated_at":"2016-02-22T23:27:46Z","body":"Simplex noise is something else, so wouldn't expect to see anything similar.\r\n\r\nI don't use GLM, but a quick look at:\r\n\r\nhttps://github.com/g-truc/glm/blob/master/glm/gtc/noise.inl\r\n\r\nMake it look like it's the GPU algorithm from McEwan/Gustavson, see 5.4 here:\r\n\r\nhttp://webstaff.itn.liu.se/~stegu/jgt2011/supplement.pdf\r\n\r\nPerhaps it is so they can match the same noise across CPU and GPU implementations, but using a permutation polynomial will be a bit different than how Cinder works currently.  But anyway, yes this algorithm should improve the output."}}