[Explained] Perlin Noise and Unity

  Рет қаралды 9,866

BearTheCoder

BearTheCoder

3 жыл бұрын

Over the past month or so, I have been working with Perlin Noise all because I watched this video by Sam Hogan:
• I Made Minecraft in 24...
Turns out creating randomly generated terrain is mostly based around Perlin Noise. Also, turns out that Perlin Noise is really easy to use if you don't make KZfaq videos and have to explain why things work.
One month later and I finally complete understand almost every aspect of Perlin Noise and here we are. I still have made Minecraft in a day, though.
Here's a bunch of links that made this video a lot easier:
Sebastian Lague's 21 Part Series:
• Procedural Terrain Gen...
PBS Infinite Series - Pseudorandom Numbers:
• How to Generate Pseudo...
George Washington Video - Kensuke Koike:
• Avatar🕹
Sebastian Lague - 3 Simulations:
• Complex Behaviour from...
One of the best articles about Perlin Noise:
eev.ee/blog/2016/05/29/perlin...
Unit Vectors - Math is Fun:
www.mathsisfun.com/algebra/ve...
Unit Circles - Math is Fun:
www.mathsisfun.com/geometry/u...
Component Form of a Vector:
• How to find the compon...
Calculate Magnitude:
• How to find the magnit...
Dot Product Calculation - Math is Fun:
www.mathsisfun.com/algebra/ve...

Пікірлер: 58
@josephtipler8967
@josephtipler8967 2 жыл бұрын
Good explanation in this video! Sebastian's videos are good but your explain it a lot better! Hope part two comes soon :)
@BearTheCoder
@BearTheCoder 2 жыл бұрын
Thank you! Part two should come out in the next few months! I am working on it!
@olaxe360
@olaxe360 3 жыл бұрын
I'm looking forward for the next part!
@dood7625
@dood7625 2 жыл бұрын
Your videos are amazing you deserve more views!
@griffinvella8069
@griffinvella8069 Жыл бұрын
Awesome video! really well explained and clear to understand and focus on. sad there hasnt been a part 2 released yet tho.
@BearTheCoder
@BearTheCoder Жыл бұрын
I’m sorry 😭part 2 has been in the works for months. I’m just a lazy creator.
@MSouzaGameDev
@MSouzaGameDev Жыл бұрын
what a nerdy video. loved it. also, very well explained.
@Auios
@Auios 3 жыл бұрын
Your videos are awesome. Keep it up! :)
@BearTheCoder
@BearTheCoder 3 жыл бұрын
Thank you! I have a lot of fun making them!
@ichikunk
@ichikunk 2 жыл бұрын
> here is a screenshot of a code if you want to copy it Ah, I see you're a man of culture as well
@simondhoine
@simondhoine 2 жыл бұрын
Nice work, really !! Still waiting for part 2
@BearTheCoder
@BearTheCoder 2 жыл бұрын
Part 2 coming soon!
@koushikvss6277
@koushikvss6277 Жыл бұрын
How your videos are such underrated
@BearTheCoder
@BearTheCoder Жыл бұрын
:') Thank you.
@crckrbrrs
@crckrbrrs Жыл бұрын
WHAT i looked down at your subscription counmt and you desperately need about a thousand times more PLEASE make more
@BearTheCoder
@BearTheCoder Жыл бұрын
I’m working on it!
@BearTheCoder
@BearTheCoder Жыл бұрын
Thank you!
@ThankYouESM
@ThankYouESM 2 жыл бұрын
I figured on my own how to make 4 Perlin Noise generators in PYS60 (Python for Nokia) many years ago. The first one is from having a floating-point variable representing the bell curving offset by at least by 5 pixels to see it beautifully. The 2nd and 3rd is quite the same as the 1st... but made into 2D and 3D. The 4th... is from layering sine waves of various sizes which I can have absolute control of... and also can seamlessly wrap around, able to even make animated 3D blobs.
@kech-agmaio8620
@kech-agmaio8620 2 жыл бұрын
Why do you have so little followers? This is a top notch coding KZfaq channel, you should have blown up by now!
@BearTheCoder
@BearTheCoder 2 жыл бұрын
Huge compliment! Thank you!
@razanomer10
@razanomer10 2 жыл бұрын
Awesome video! Thanks dude
@malukp_nopedaco7220
@malukp_nopedaco7220 Жыл бұрын
very very nice
@ludboy9333
@ludboy9333 2 жыл бұрын
I love the videos
@BearTheCoder
@BearTheCoder 2 жыл бұрын
Thank you!
@zmichael4114
@zmichael4114 2 жыл бұрын
Amazing
@BearTheCoder
@BearTheCoder 2 жыл бұрын
Thank you very much!
@ian.ambrose
@ian.ambrose 11 ай бұрын
Great and professionally presented video! May I ask you some mathematical questions regarding some parts of your video? Thank you.
@BearTheCoder
@BearTheCoder 11 ай бұрын
Of course, I may be a bit rusty, but the math is still in there somewhere.
@insideyrmind4873
@insideyrmind4873 2 жыл бұрын
awesome video
@BearTheCoder
@BearTheCoder 2 жыл бұрын
Thank you!
@anonphil
@anonphil Жыл бұрын
Wheres the second video!!!
@daedalusrasmus3278
@daedalusrasmus3278 Жыл бұрын
Wow cool, could you make one for Simplex noise too? and other noises as well hahaha, this is easier to understand
@sekvojs
@sekvojs Жыл бұрын
+1 sub *Don't be discourage from nerding out ;)
@nagillbeats
@nagillbeats Жыл бұрын
Next part please
@Shlenx
@Shlenx 8 ай бұрын
Any news on part 2? :)
@BearTheCoder
@BearTheCoder 8 ай бұрын
I've had the script written for probably about a year, just haven't gotten around to it.
@maftplays
@maftplays 10 ай бұрын
I liked you just for that intro
@rediculaid
@rediculaid Жыл бұрын
this tutorial was confusing or im stupid but why is it looking around for neighbouring points and they are all aligned so wont it make so it will be 0.5?
@BearTheCoder
@BearTheCoder Жыл бұрын
Hmm? At which point are we talking?
@rediculaid
@rediculaid Жыл бұрын
@@BearTheCoder 3:36 i understand why its 0.5 but if i divide sample points by 2 for coordinates wont they point still be aligned so they gradient will stay the same? im sorry if im being stupid
@BearTheCoder
@BearTheCoder Жыл бұрын
@@rediculaid Ok, I think I know what you are thinking. Each pixel of Perlin noise, when taken in the context of 2d noise, is a combination of 4 different gradients, one for each adjacent coordinate. So, I think what you are asking is, why isn't the output the same as the gradient shown, how do we get perlin noise and not the gradient? Because, the sample's coordinates doesn't change, but the context from which we are grabbing the sample changes based on the coordinate and the angle assigned to the coordinate. The sample's location, the coordinate, and the angle are then used to determine the gradient using the dot product. So, for that one sample you are give 4 different numbers 0.25, 0.1,0 .9, and 0.7 for example, and then those are blended together. It can be confusing not understanding the math, if you want, join my discord and I can explain it in more detail if you want. discord.gg/mZ5vKkS7
@CopiousAmountsOfDerp
@CopiousAmountsOfDerp 2 жыл бұрын
Nice 1984 reference, touché! (2+2=5)
@FilmFactry
@FilmFactry Жыл бұрын
This was very good. Coming from a novice, I just want to understand how Text to image AI like MidJourney/Stable Diffusion works. Thanks.
@crckrbrrs
@crckrbrrs Жыл бұрын
a good way to visualize it is: the dataset that the model uses is like a bucket of legos. the algorithm is told to create a certain type of structure, so it looks at other structures like the one it's being asked to make, then picks up the pieces used to make those previous structures and throws something together. essentially its looking at things it knows about the prompt subject, chopping up all the elements making up those images, then attempts to imitate the qualities with those elements, picked out randomly. im sorry if this made you even more confused lmao im not a very good explainer
@lirmi9469
@lirmi9469 Жыл бұрын
r u know how to add some octaves?
@BearTheCoder
@BearTheCoder Жыл бұрын
github.com/BearTheCoder/p5/blob/master/Perlin%20Noise/p5%20Noise/main_p5.js
@BearTheCoder
@BearTheCoder Жыл бұрын
Here’s an example using JavaScript but it should be the same in any other language. Basically you add another for loop that iterates over the amount of octaves you want and change the input with a opacity and frequency value. Hard to explain, hopefully the code will be enough to get you going.
@easemakesbeats828
@easemakesbeats828 Жыл бұрын
I’m tracking so far you know how to teach
@ian.ambrose
@ian.ambrose 11 ай бұрын
Thanks for your response! Here are my (rather lengthy) questions. I’m not a programmer and all the questions below are purely for mathematical understanding purposes. I also skipped all the coding parts because I don’t understand them. ----------- Q1. 3:21 People call this random vector (arrow) as “Gradient” Vector, do you have any idea on why it’s called that? Is it because it’s involved in the Dot Product to create values that form a gradual transition (aka a “gradient”) inside a cell (aka grid tile)? ----------- Q2. 3:28 You said that the Dot Product values inside a cell has the Range of [0,1], but there’s always a chance for Dot Product to output negative values, isn’t it? ----------- Q3. (Please read the whole Q3 before answering) 3:30 About the “4 cells forming *ONE* gradient”, doesn’t *EACH* (sorry, I'm not screaming, I'm emphasizing) cell have its own “gradient”? Like it’s illustrated in this video's timestamp here: kzfaq.info/get/bejne/kNl1odFzl93Wkn0.html As explained in many other videos, the visual “gradient” we see is formed by placing hundreds of pixels (that are evaluated by performing Dot Product between one Gradient Vector and hundred of distance vectors) together. Each cell (aka grid tile) possesses 4 Gradient Vectors at its 4 corners, if we are using only 1 out of 4 to create a “gradient”, that means each cell has a completely separate “gradient” (4 Gradient Vectors means 4 different “gradient”) from the neighboring cells, that means there will be a sudden jump in value at the border in between 2 cells, leading to the visual that you see in the link I sent above. To visually smooth out those “sudden jumps”, we use Linear / SmoothStep / SmootherStep Interpolators. Does *your* Perlin Noise use the same algorithm that I addressed above? If it does, then there’s no way that the gradients of 4 adjacent cells would connect that smoothly as you illustrated. Also, if the transitions of values between cells were that smooth, then there would be no reason for any interpolator to be involved because there’s no sudden transitions at the borders. OR, were you showing what it would look like if *ONE* Gradient Vector was used to perform Dot Product with *ALL* distance vectors across *ALL* cells instead of just the distance vectors inside of *ONE* cell? ----------- Q4. I’ve watched and read almost 20 videos / articles and you are the only person to say that Perlin Noise function interpolates the Dot Product values using Cosine Interpolator, whereas all other resources said the interpolators were either SmoothStep or SmootherStep Interpolator. Or is your video here specifically made for Unity’s Perlin Noise implemented function? I’m not familiar with Unity though. ----------- Thank you so much!
@BearTheCoder
@BearTheCoder 11 ай бұрын
Q1. A random unit vector (arrow) is not a gradient vector until you get the dot product involved. A unit vector is strictly an arrow with length 1 and a direction. The dot product is what makes it a gradient vector.
@BearTheCoder
@BearTheCoder 11 ай бұрын
Q2. Correct. The dot product outputs a value from -1 to 1 if using the unit vector and an input coordinate with less than length 1 . I may have explained it poorly in the video, but you can see at the time stamp the values are originally from -1 to 1 but I say “the values are then shifted to 0 to 1” which is a somewhat incorrect statement to make as the value isn’t shifted until the last step. But for explanation purposes it kinda works out.
@BearTheCoder
@BearTheCoder 11 ай бұрын
Q4. Yes smooth step is more common and probably the correct way to do it. Years ago when I wrote my first Perlin Noise algorithm I had quite a few gaps in my knowledge that I filled with poor research. Earlier this year, because of a request in my discord, I wrote a new Perlin Noise script and started editing a new video overviewing the correct algorithm but was scrapped because ChatGPT came out and for quite a while I've had the mood of "Why make a video, they can just ask ChatGPT to write the script for them". But if you are interested, here is the algorithm I wrote in JavaScript using p5js for that video: github.com/BearTheCoder/p5/blob/master/Perlin%20Noise/VanillaJS/main.js
@BearTheCoder
@BearTheCoder 11 ай бұрын
Q3. Is a dense one, and something that I would like to talk at length using discord. discord.gg/aeAukyWn You are not wrong, but also not right. Probably more of a misunderstanding. If we take a single point on a grid, let's say (1, 1), that single point is the center of the dot product. Which is why if you reference whole number coordinates in a Perlin Noise algorithm, the result comes back 50% gray every time. But also at the same time, if you are observing the gradient vector around (1, 1) with an angle of 45 degrees, if you pull the dot product from a coordinate closer to (2, 2), the output will be closer to 1 or "white", if you pull using a coordinate closer to (0, 0) it will be -1 or "black". Meaning that the gradient spans 4 grid tiles centered around (1, 1). So, when you refence a pixel at location (0.2, 0.4) or (1.5, 1.2), they both will reference the same gradient that is at (1, 1). This is also why if you put the same values into a Perlin noise algorithm, the result will always return the same. Also this is why you can feed Minecraft (which is basically Perlin Noise the Game) a seed and end up at the same spot every time although the world is fairly endless. As far as the actual output, yes, if we pull the value for (0.2, 0.4) the output will be an combination of values from the gradient at (0 0), (0, 1), (1, 0) , and (1, 1)
@pirateskeleton7828
@pirateskeleton7828 Жыл бұрын
This video would have been great to see two years ago. I also home brewed a Perlin noise function for a game I’m making. For my random function, I had a very long array deterministic “random” values, and I pull values from the array using a sort of shifting cipher algorithm, so that the values don’t repeat themselves as I get farther away. Otherwise it just uses normal bilinear interpolation.
@jozejerse6777
@jozejerse6777 2 жыл бұрын
good video. too bad you never made the follow up video tho.
@BearTheCoder
@BearTheCoder 2 жыл бұрын
It’s still in the works. Life gets in the way, ya know.
@jozejerse6777
@jozejerse6777 2 жыл бұрын
@@BearTheCoder Very true. Hope you're doing well.
How to turn a few Numbers into Worlds (Fractal Perlin Noise)
15:24
The Taylor Series
Рет қаралды 187 М.
Randomness is calculated - Linear Congruential Generators Explained
10:48
Nastya and SeanDoesMagic
00:16
Nastya
Рет қаралды 17 МЛН
C++: Perlin Noise Tutorial
8:52
Zipped
Рет қаралды 11 М.
Minecraft terrain generation in a nutshell
25:49
Henrik Kniberg
Рет қаралды 150 М.
Programming Perlin-like Noise (C++)
27:54
javidx9
Рет қаралды 103 М.
Perlin Noise Explained Tutorial 2
21:58
Fataho
Рет қаралды 66 М.
I.7 : What is OpenSimplex Noise?
17:46
The Coding Train
Рет қаралды 109 М.
Using AI to Create the Perfect Keyboard
12:05
adumb
Рет қаралды 1,4 МЛН
What is Perlin Noise?
7:49
Suboptimal Engineer
Рет қаралды 12 М.