Programming Perlin-like Noise (C++)

  Рет қаралды 105,585

javidx9

javidx9

Күн бұрын

Пікірлер: 126
@javidx9
@javidx9 7 жыл бұрын
Before all the complaints start streaming in - I'm aware that this is more of an "approximation" to Perlin noise rather than defacto Perlin noise, however it shares the same periodicity and distribution properties. Instead of using dot products of gradients, The original noise map is used as a height map, through which gradient is implied via linear interpolation between neighbouring heights at different spatial scales.
@whynot-vq2ly
@whynot-vq2ly 4 жыл бұрын
dont worry people are going to complain anyways :D, great tutorial thanks a lot
@graphics_gurunt
@graphics_gurunt 2 жыл бұрын
هجهححعحععض
@graphics_gurunt
@graphics_gurunt 2 жыл бұрын
عضغضضضضضضض
@graphics_gurunt
@graphics_gurunt 2 жыл бұрын
فضفضفضڤ في فض ففي في غ١٦غضغضضضضغضضضضضضضغغضغضغضععععععضضغغغضضغضضضضضضضضغضضغضضضضضغضضغضضغضضعضعغضععه
@graphics_gurunt
@graphics_gurunt 2 жыл бұрын
رح وز لءظاللذالننح مع ههشهشهههههههعععععععععععع٦ض١١ضضضع
@mime490
@mime490 6 жыл бұрын
I appreciate the void you fill in the youtube space for development tutorials, your explanations are excellent and have helpes me significantly in ways that channels like Brackeys are unable to. I see a lot of comments noting that the speed of your videos is too fast, I believe that there is a large community that will find your speed refreshing.
@javidx9
@javidx9 6 жыл бұрын
Hi Mime and thanks for the positive feedback, I appreciate that!
@andreaprovasi9786
@andreaprovasi9786 4 жыл бұрын
This! A hundred times! javidx speed is DEFINITELY refreshing compared to most tutorials (whatever the topic)
@danielrazulay
@danielrazulay 3 жыл бұрын
Agreed! I'm really enjoying this pace.
@sloppyprogrammer4373
@sloppyprogrammer4373 3 жыл бұрын
The creator Brackeys doesn't have a background in math nor programming. He's just a creative mind that happened to stumble across unity and picked up game development due to it. It's not bad perse, it just gives a whole different style of content because he doesn't know what is actually happening under the hood of the code or the engine. I still learned some stuff from brackeys and they were really good at showing how the engine (unity) works. But Javidx9 knows what actually is happening under the hood and that's why he can make a lot more educational focused content because he actually knows how to make an engine.
@avananana
@avananana 6 жыл бұрын
This is genius. Whilst it isn't "true" perlin noise, it's damn close to it, and I'm sure you could use this to get practically the same results in nearly every project you could think of. Well done :P
@javidx9
@javidx9 6 жыл бұрын
Thanks Avana - though I will say I've seen this method used in the wild, so I cant lay exclusive rights to it! It's closest relative is an algorithm called "Simplex Noise".
@benjamminholmes
@benjamminholmes 7 жыл бұрын
I like that you used musical elements as an example; really helps me out.
@javidx9
@javidx9 7 жыл бұрын
Thanks Benjamin! I'm pleased you've found it useful!
@remmo123
@remmo123 6 жыл бұрын
You are a great teacher. Thank you for making these. I'm learning a lot.
@olavman88
@olavman88 7 жыл бұрын
I've been searching for this for so long! Everybody else just uses functions already implimented so I don't really learn how the perlin noise works. Thanks :)
@javidx9
@javidx9 7 жыл бұрын
Hi Olav, no problem!
@MB-rc8ie
@MB-rc8ie 7 жыл бұрын
You make interesting and quality videos, hope your channel will grow soon
@javidx9
@javidx9 7 жыл бұрын
Thanks Black Magic!
@matthewe3813
@matthewe3813 4 жыл бұрын
@@javidx9 thats not his name?
@javidx9
@javidx9 4 жыл бұрын
It was 2 years ago 😁
@MB-rc8ie
@MB-rc8ie 4 жыл бұрын
@@javidx9 haha
@GregoryTheGr8ster
@GregoryTheGr8ster 5 жыл бұрын
The time passes so quickly when I watch your videos.
@suffysbert225
@suffysbert225 2 жыл бұрын
After looking through papers and tutorials, i just couldnt get my head around it. thanks to this tutorial i implemented it & fully understand it. thanks alot
@judgeomega
@judgeomega 4 жыл бұрын
that first picture of true random static was trippy. it started waving and flowing on me like one of those magic eye hidden image puzzles.
@yeeteronipizza
@yeeteronipizza 3 жыл бұрын
I started learning C++ about a month ago, coming in with knowing matlab from engineering and C# from making a lot of little games in Unity. You are a blessing, because you explain the topic so well I could probably write the code myself.
@kevinsmith-dn1px
@kevinsmith-dn1px 6 жыл бұрын
Omg, much respect to people who can code!
@javidx9
@javidx9 6 жыл бұрын
Hi and thanks Kevin, I think most people can code, like all things it just takes practice and patience and effort, which are traits that should be respected regardless of discipline.
@kevinsmith-dn1px
@kevinsmith-dn1px 6 жыл бұрын
@@javidx9 Maths isn't my friend lol! But you're right, you get out what you put in i guess👍 It may sound strange, but when i see code, to me it looks like art. It has a beauty to it - anyway much respect to you!
@obinator9065
@obinator9065 5 жыл бұрын
kevin smith That is what good is haha, you can achieve things differently. It truly is an art, you can do it really verbose and unreadable, or simple but yet effective.
@minsin56
@minsin56 5 жыл бұрын
free respect
@cheaterman49
@cheaterman49 5 жыл бұрын
@@kevinsmith-dn1px A recent quote I found that I really like, "code is art that does something". Other than that, you'd be surprised how little day-to-day programming has to do with maths! The only part they have in common is the general logic aspect (which applies to so many other disciplines that it's not fair to claim it makes programming close to maths) - I'd say the real crucially common part is being able to deconstruct complex operations into simpler ones to solve an issue, like you would when writing up a demonstration to a theorem (or anything else really) in maths for instance. EDIT: I'd say generally some types of programmers are math enthusiasts like OLC and (probably) much of the audience, but not really math nerds (what's a covector again? differential topology? no thanks) : I think high school maths is the most interesting and useful, having a basic understanding of moderately advanced geometry like vector dot product, as well as some calculus, but really most of the problems I think of as "interesting" that would involve me using those tools are essentially problems that are already solved, and I could just copypaste some maths formula in my code if I didn't enjoy solving the puzzle.
@deadlypoe5_710
@deadlypoe5_710 2 жыл бұрын
You probably wont see this, but you spared me a headache. Thanks for all the work you do!
@javidx9
@javidx9 2 жыл бұрын
Always appreciate feedback, cheers buddy!
@leonardosabomisseni3667
@leonardosabomisseni3667 3 жыл бұрын
I think you just saved my weekend and semester project as my method was getting increasingly repetitive. Thank you very much!!!
@TChapman500Gaming
@TChapman500Gaming 4 жыл бұрын
Thanks for the tutorial. I'm going to be implementing the 2D version of this algorithm into my game, Solar Lander.
@roganjosh6220
@roganjosh6220 3 жыл бұрын
brilliant video, clear explanation of an abstract concept then an implementation to demonstrate
@CharlesFerreira
@CharlesFerreira 6 жыл бұрын
When writing/showing code, you could use the Alt+Shift+Enter shortcut to show code in fullscreen. It makes code much easier to visualize and follow up.
@CharlesFerreira
@CharlesFerreira 6 жыл бұрын
All the toolbars, console, taskbar, solution explorer etc. are too distracting and add no useful information to the video.
@austin5359
@austin5359 Жыл бұрын
Another way of linear interpolation is ((nSample2 - nSample1) * fBlend) + nSample1 I code in Scratch (because I'm too lazy to learn Java, C++, python or literally anything else) and this helped me create some code that can create a map using your "Perlin noise." It may not be true Perlin noise, but it does the same job and works very similarly. Thanks!
@antiprime4665
@antiprime4665 Жыл бұрын
Bro move to c++ or something you'll like it better I promise
@CarstenMeyer
@CarstenMeyer 7 жыл бұрын
Great video, as always!
@javidx9
@javidx9 7 жыл бұрын
Thank you Carsten, was a bit worried about this one!
@philiphanhurst2655
@philiphanhurst2655 4 жыл бұрын
This was really useful for a fog effect I'm experimenting with. I put it into a header file as a couple classes. Only problem is I want the clouds to change over time, and for that I'd need noise with a 3 dimensional input. I've tried figuring it out myself, expanding on the 2D noise, but it seems I'm too stupid for it. Edit: nevermind, got it working... to an extent.
@dorjderemnamsraijav5182
@dorjderemnamsraijav5182 4 жыл бұрын
Hey javidx9! Can you do a tutorial about liquid simulation? I found that there arent any proper tutorial on how to do liquid simulation from scratch.
@GregoryTheGr8ster
@GregoryTheGr8ster 5 жыл бұрын
I would have given you a *big* thumb's up (as you request at 27:49) , but KZbin allows only an ordinary thumb's up. I hope that that is adequate. I have been in need of noise generation like this for a while. My own algorithms are fast-executing, but don't have the look and simple parameterization of the Perlin noise. Now I know what to do!
@smugtomato5972
@smugtomato5972 2 жыл бұрын
One thing to note about the seed array, Perlin's original algorithm uses a precomputed array containing 0-255(inclusive) in a randomized order, in my understanding this is done to prevent getting into situations where the majority of the numbers in the array are too similar to eachother(and of course performance, it was created in the 80s after all, memory and CPU cycles weren't cheap). What you can then instead do is randomly shuffle the elements in the array, that way you keep all numbers from 0-255 but in a new order. Although this implementation is completely different than the original Perlin noise, using a float array instead of int array, so I don't know how you would fit that in here. Not really a big deal, but sticking to the "true" perlin noise might give some slightly more predictable results, besides the video still shows very well how perlin noise is used and why it's useful
@Test-iv4pm
@Test-iv4pm Жыл бұрын
At 18:17, going from 1 octave to 2 octaves, it makes the line drop in the middle. Shouldn't octaves only be able to add on to what we already have? I am wondering if the seed noise somehow contains negative numbers.
@thyandyr7369
@thyandyr7369 5 жыл бұрын
I rellay like the idea of explaining this. I literally won't use anything unless I understand how it works. It just feels wrong to me. Any wathincg this was faster than figuring it out myself.
@DarkCloud7
@DarkCloud7 6 жыл бұрын
I've read about the >> operator but never used it before. So I just wanna make sure I got the concept. The expression (nWidth >> o) is there to divide nWidth by 2^o is that right? Furthermore do you only use it because it's faster to compute? Are there any drawbacks or other potential advantages?
@javidx9
@javidx9 6 жыл бұрын
Hi Flo, Yes your calculation is correct. In most cases, your compiler will choose the most optimal division strategy, but in the case of integers that are powers of 2, then bit shifting is the most optimal. The >> and
@KristijanPruzinac
@KristijanPruzinac 3 жыл бұрын
Thank you for this!
@erwinmulder1338
@erwinmulder1338 6 жыл бұрын
Just nitpicking here, but fScaleAcc will be the same number for all samples, so you you can compute it only once and re-use the value. You don't even need to calculate it inside one of the loops: fScaleAcc = 2.0 - 1.0/(float)(1
@javidx9
@javidx9 6 жыл бұрын
Thanks Erwin, I dont see things a nitpicks, I find them often to be valuable contributions, which I hope others get to see. I dont make any claim that my methods are the best, just a way to have fun coding. The challenge I face is I try to write code in such a way that things are obvious, so viewers can follow - but you are right of course.
@erwinmulder1338
@erwinmulder1338 6 жыл бұрын
I found it nitpicking, as the presentation is otherwise perfect. Especially because the second part where you can alter the divisor, the formula involves some quite advanced math and is quite obviously not on the level of the intended audience.
@trentf8607
@trentf8607 7 жыл бұрын
Hello! I have a question. I know that this is similar to Perlin noise, but is an approximation. I was wondering if one is better to use than the other. Is there a big difference? Also I really like how you explained how it worked first with the diagram. 😁
@javidx9
@javidx9 7 жыл бұрын
Hi Trent, then end results from the algorithms are pretty much the same, Perlin interpolates a little differently, focusing on interpolating the gradients directly, and is why I use the term "approximating", as I calculate the gradients and interpolate the lines instead. The approach shown in this video is quite common, as it is more visual to grasp.
@trentf8607
@trentf8607 6 жыл бұрын
javidx9 Thanks! :)
@Test-iv4pm
@Test-iv4pm Жыл бұрын
At 23:40, I see SampleT and SampleB. What do 'T' and 'B' stand for?
@javidx9
@javidx9 Жыл бұрын
Top and bottom
@Test-iv4pm
@Test-iv4pm Жыл бұрын
@@javidx9 Thank you
@nikims_
@nikims_ 3 жыл бұрын
I know this is a pretty old video, but i'd like to ask what this implementation is called exactly? Or did you make it up?
@adrianMT4U
@adrianMT4U 2 жыл бұрын
thank you ser! even I don't understands the code and the mathematical thing, but i get the idea of perlin noise hehe
@CJBurkey
@CJBurkey 6 жыл бұрын
I have f.lux, and it took me about half a minute to realize that you were probably using yellow, not white, on the white background.
@javidx9
@javidx9 6 жыл бұрын
lol, I shall be more late night yet sensible video watcher aware going forward!
@piotrjaga6929
@piotrjaga6929 2 жыл бұрын
thank you
@Test-iv4pm
@Test-iv4pm 6 ай бұрын
Can you make a video extending to 3D? 🙂 Maybe even 4D? 😀
@DaniiTheFox
@DaniiTheFox 3 жыл бұрын
wont work on linux, there are math errors that where not solved and also: int nSampleX1 = (x / nPitch) * nPitch; int nSampleY1 = (y / nPitch) * nPitch; why this? it's literally the same as just int nSampleX1 = x; int nSampleY1 = y;
@HerrHoldem
@HerrHoldem 6 жыл бұрын
Hello, Nice Video. Can you call which Graphic Library you use? Thank you!
@javidx9
@javidx9 6 жыл бұрын
Thanks Grub! Most of my videos use a custom library I created that exploits the windows command prompt as a graphical surface. All the source is available in the descriptions below each video.
@HerrHoldem
@HerrHoldem 6 жыл бұрын
Thanks. I will research this.
@bytelab3268
@bytelab3268 3 жыл бұрын
Int sample1 x = (x/npitch) * npitch ???? What's the difference with just int sample1x = x
@javidx9
@javidx9 3 жыл бұрын
Yeah it's a fun one this 😄 I'm taking advantages of the property of integer divide to round down X, before scaling it up to be a multiple of nPitch.
@bytelab3268
@bytelab3268 3 жыл бұрын
Ahhh now I understand.
@thatlevivw545
@thatlevivw545 2 жыл бұрын
@@javidx9 But doesn't that result in that a lot of the time the samples are 0? I have this problem where my samples are 0 a lot of the time which results in terrain with a smooth line from the top Left to the bottom right of my screen en the rest is still just noise?
@DaniloSouzaMoraes
@DaniloSouzaMoraes 3 жыл бұрын
I can't seem to find anything on the interpolation method you used ( linear interpolation between neighbouring heights). Any idea where I could read more about it?
@javidx9
@javidx9 3 жыл бұрын
It is nothing more complicated than simple linear interpolation. Even has it's own function now std::lerp()
@DaniloSouzaMoraes
@DaniloSouzaMoraes 3 жыл бұрын
@@javidx9 I was having a little problem seeing that x=(1-mu)*x0+mu*x1 was actually a linear interpolation formula. Tried it on Excel and that answered my question. Thanks and nice video!
@SuperToughnut
@SuperToughnut 4 жыл бұрын
Is this like the diamond square algorithm in 2d?
@pinurim9861
@pinurim9861 6 жыл бұрын
thanks
@Je3f0o
@Je3f0o 5 жыл бұрын
My humble understanding seeds length is 256. Which is 8 octaves. But how do I generate infinite continues noise? Can you make a video improve this algorithm to infinite continues noise generator?
@MarsCorporations
@MarsCorporations 5 жыл бұрын
You can still use everything as presented here but you will need to wrap the RNG so it can do stuff like: random(x, y, seed). Then you use this instead of a precalculated random array to create your fSampleT and fSampleB. Now you are no longer bound to any dimensions. Next you could remove any "array-like" stuff from the perlin function and use it to only calculate ONE sample at one specific (x,y). And here you go: A perlin-generator that takes x, y, bias, oct, etc (whatever you want) as input and outputs a single Value between 0 and 1. I havent coded it yet but i think it should work that way.
@FrostGamingHype
@FrostGamingHype 2 жыл бұрын
i wish javid made this without olc so it could be helpful for an person like me that is trying to implement this in his own console game engine
@rocketeer_TH
@rocketeer_TH 3 жыл бұрын
how do I make it to 3d mesh?
@GregoryTheGr8ster
@GregoryTheGr8ster 5 жыл бұрын
Also, why do you say that this is "only an approximation of Perlin noise" in the video description?
@megamech2268
@megamech2268 6 жыл бұрын
when i run the program, it tells me that "olcConsoleGameEngine.h" has no such file or directory.
@javidx9
@javidx9 6 жыл бұрын
Have you downloaded the "olcConsoleGameEngine.h" file as well?
@abirneji
@abirneji 5 жыл бұрын
I kinda wish I could use bicubic interpolation instead of bilinear but I just don't know how to get it working
@dutu000
@dutu000 4 жыл бұрын
it would be interesting to hear how perlin noise sounds
@oraz.
@oraz. 3 жыл бұрын
Did you make up this approximation?
@andresantana4086
@andresantana4086 7 жыл бұрын
Out of context, but, what font do u use at thumbnails?
@javidx9
@javidx9 7 жыл бұрын
Hey André, it's called Press Start and I stretch it vertically a little.
@deprogrammeur463
@deprogrammeur463 3 жыл бұрын
can you do 3d perlin noise?
@thefoolishgmodcube2644
@thefoolishgmodcube2644 7 жыл бұрын
Bisqwit and javidx9, which one is the best programmer?
@javidx9
@javidx9 7 жыл бұрын
Bisqwit. The guy's a machine.
@EximiusDux
@EximiusDux 6 жыл бұрын
javidx9 heh. His videos are alien in nature. His c++ nearly impossible to understand for me.
@samholland209
@samholland209 Жыл бұрын
Do you know Minecraft uses this algorithm to generate its terrain?
@1st_ProCactus
@1st_ProCactus 7 жыл бұрын
Cool, Im in.. Nice font size
@javidx9
@javidx9 7 жыл бұрын
Hi ProCactus!
@CreativeOven
@CreativeOven 4 жыл бұрын
that's cool for Worlds terrains.
@GTS00000
@GTS00000 7 жыл бұрын
Hey Javidx9! Beautiful work! Excellent theoretical intro. vey pedagogical. Questions: i) How compatible is olcConsole...h with linux? ii) Why windows man, why?
@javidx9
@javidx9 7 жыл бұрын
Hey Thanks GTS! I appreciate that. 1) Not very. Members of this community have tried with different levels of success. Fundamentally, the consoles between the two OSs are very different in their use and implementation. 2) See 1 :D Only displaying the screen is incompatible. The algorithms in my videos are very much cross compatible. Maybe it's time I took a look at a linux implementation. I don't think I'd be able to do much better than the others that have tried, it seems to be quite performance restricted due to how the linux terminal works. There was an SDL2 port made of the game engine via github, which could also help.
@Prolute
@Prolute 6 жыл бұрын
Your 2d function only works when the width and height are the same size.
@javidx9
@javidx9 6 жыл бұрын
Hi Joe, correct it also prefers power of 2 dimensions also.
@olasoderlind5685
@olasoderlind5685 5 жыл бұрын
cold you do one lloop whit (mod)% of 1,2,4,8,16
@NicoFye
@NicoFye 6 жыл бұрын
Maube someone can tell me how to make more plains?
@clementtarin9936
@clementtarin9936 3 жыл бұрын
wow
@tedeusz83
@tedeusz83 5 жыл бұрын
Worms terrain generator :)
@tangerian319
@tangerian319 6 жыл бұрын
this video's sadly WAY too fast and lacks a lot of the explanation needed to understand exactly how it works. I've needed to do LOADS of de-bugging in order to use this generation algorithm. I had troubles because I couldn't tell where my code went wrong, because I had to do a lot of blind faith in the code you had written. I'd recomend re-doing this tutorial and splitting it up into two parts, and explain every single bit in extream detail, and when going into 2D, explain the changes. Either way, this is prety much the only tutorial on generating your own perlin noise on youtube, so credit where credit is due.
@javidx9
@javidx9 6 жыл бұрын
Hi bysTaXx, I'm sorry you've not found this video very clear. It is quite a complicated subject matter. I probably won't redo the video, but I'll take on board your concerns. I often get criticized that my videos are too slow! I'm still new at this, so still working on finding a balance that suits everybody.
@tangerian319
@tangerian319 6 жыл бұрын
javidx9 well then, i find that in many casses it is better to have more videos with narrow subjects explained in depth rather than one video with multiple topics to be helpfull, for instance, having an "intro to perlin noise" then a "1D perlin noise" then a "2D perlin noise" video would be better, as an example. And you are correct, perlin noise is a complicated topic, like PRNG algorithms are complicated. I would recommend typing out the code as much as possible, rather than copying and pasting predefined code to be most effective. Another suggestion is that after finishing a block of code, pause for a few seconds to let the viewers pause the video to review the new code. Either way, you have excellent delivery, you are engaged with your viewers, and i'm happy you dive into topics that most people just use a pre-defined library for. So all in all, i'd say you are doing quite well, just could use a little improvement.
@ScibbieGames
@ScibbieGames 5 жыл бұрын
"Because I had to do a lot of blind faith in the code you had written" Are you very familiar with c++ or is it already going wrong there?
@toastyPredicament
@toastyPredicament 2 жыл бұрын
Screw everything I want to do Pc stuff
@peoplearecool1234
@peoplearecool1234 4 жыл бұрын
12550821, only true gamers know what this number means.
@365tito3
@365tito3 Жыл бұрын
I'm trying to convert your algorithm to generate a bitmap but somehow the bw_pixel value is always 4? Why is that?
Path Planning - A* (A-Star)
31:18
javidx9
Рет қаралды 162 М.
Procedural Generation: Programming The Universe
41:57
javidx9
Рет қаралды 207 М.
UFC 287 : Перейра VS Адесанья 2
6:02
Setanta Sports UFC
Рет қаралды 486 М.
Programming Pseudo 3D Planes aka MODE7 (C++)
27:16
javidx9
Рет қаралды 105 М.
Practical Polymorphism C++
41:44
javidx9
Рет қаралды 126 М.
Coding Challenge 11: 3D Terrain Generation with Perlin Noise in Processing
22:44
Line Of Sight or Shadow Casting in 2D
50:23
javidx9
Рет қаралды 144 М.
Programming Mazes
27:11
javidx9
Рет қаралды 198 М.
Programming & Using Splines - Part#1
23:56
javidx9
Рет қаралды 94 М.
Programming Balls #1 Circle Vs Circle Collisions C++
32:29
javidx9
Рет қаралды 140 М.
Programming Balls #2 Circles V Edges Collisions C++
32:28
javidx9
Рет қаралды 51 М.
C++: Perlin Noise Tutorial
8:52
Zipped
Рет қаралды 16 М.
Code-It-Yourself! Asteroids (Simple C++ and Maths!)
53:11
javidx9
Рет қаралды 172 М.
КОРОЧЕ ГОВОРЯ, НЕДЕЛЯ БЕЗ ТЕЛЕФОНА
3:54
СИЖУ БЕЗ ЕДЫ, ПЬЮ ОДНУ ВОДИЧКУ.
21:37
Быть Добру
Рет қаралды 79 М.