Programming Perlin-like Noise (C++)

Поділитися
Вставка
  • Опубліковано 27 гру 2024

КОМЕНТАРІ • 126

  • @javidx9
    @javidx9  7 років тому +94

    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 роки тому +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 років тому +102

    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 років тому +22

      Hi Mime and thanks for the positive feedback, I appreciate that!

    • @andreaprovasi9786
      @andreaprovasi9786 4 роки тому +1

      This! A hundred times! javidx speed is DEFINITELY refreshing compared to most tutorials (whatever the topic)

    • @danielrazulay
      @danielrazulay 3 роки тому +1

      Agreed! I'm really enjoying this pace.

    • @sloppyprogrammer4373
      @sloppyprogrammer4373 3 роки тому +1

      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 років тому +29

    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 років тому +13

      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 років тому +7

    I like that you used musical elements as an example; really helps me out.

    • @javidx9
      @javidx9  7 років тому +1

      Thanks Benjamin! I'm pleased you've found it useful!

  • @remmo123
    @remmo123 6 років тому +20

    You are a great teacher. Thank you for making these. I'm learning a lot.

  • @judgeomega
    @judgeomega 4 роки тому +5

    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.

  • @olavman88
    @olavman88 7 років тому +15

    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 років тому +4

      Hi Olav, no problem!

  • @GregoryTheGr8ster
    @GregoryTheGr8ster 5 років тому +3

    The time passes so quickly when I watch your videos.

  • @MB-rc8ie
    @MB-rc8ie 7 років тому +23

    You make interesting and quality videos, hope your channel will grow soon

    • @javidx9
      @javidx9  7 років тому +2

      Thanks Black Magic!

    • @matthewe3813
      @matthewe3813 4 роки тому

      @@javidx9 thats not his name?

    • @javidx9
      @javidx9  4 роки тому +3

      It was 2 years ago 😁

    • @MB-rc8ie
      @MB-rc8ie 4 роки тому +1

      @@javidx9 haha

  • @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.

  • @suffysbert225
    @suffysbert225 2 роки тому +1

    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

  • @CharlesFerreira
    @CharlesFerreira 6 років тому +3

    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 років тому +1

      All the toolbars, console, taskbar, solution explorer etc. are too distracting and add no useful information to the video.

  • @TChapman500Gaming
    @TChapman500Gaming 4 роки тому +9

    Thanks for the tutorial. I'm going to be implementing the 2D version of this algorithm into my game, Solar Lander.

  • @leonardosabomisseni3667
    @leonardosabomisseni3667 3 роки тому +1

    I think you just saved my weekend and semester project as my method was getting increasingly repetitive. Thank you very much!!!

  • @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

  • @kevinsmith-dn1px
    @kevinsmith-dn1px 6 років тому +13

    Omg, much respect to people who can code!

    • @javidx9
      @javidx9  6 років тому +3

      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.

  • @dorjderemnamsraijav5182
    @dorjderemnamsraijav5182 4 роки тому +9

    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.

  • @roganjosh6220
    @roganjosh6220 3 роки тому

    brilliant video, clear explanation of an abstract concept then an implementation to demonstrate

  • @philiphanhurst2655
    @philiphanhurst2655 4 роки тому +2

    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.

  • @thyandyr7369
    @thyandyr7369 5 років тому +10

    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.

  • @GregoryTheGr8ster
    @GregoryTheGr8ster 5 років тому +1

    I would have given you a *big* thumb's up (as you request at 27:49) , but UA-cam 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!

  • @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.

  • @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

  • @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!

  • @DarkCloud7
    @DarkCloud7 6 років тому +3

    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 років тому +2

      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

  • @Test-iv4pm
    @Test-iv4pm Рік тому

    At 23:40, I see SampleT and SampleB. What do 'T' and 'B' stand for?

  • @trentf8607
    @trentf8607 7 років тому +5

    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 років тому +5

      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 років тому +2

      javidx9 Thanks! :)

  • @CarstenMeyer
    @CarstenMeyer 7 років тому +2

    Great video, as always!

    • @javidx9
      @javidx9  7 років тому

      Thank you Carsten, was a bit worried about this one!

  • @CJBurkey
    @CJBurkey 6 років тому +1

    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 років тому +2

      lol, I shall be more late night yet sensible video watcher aware going forward!

  • @erwinmulder1338
    @erwinmulder1338 6 років тому +1

    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 років тому +2

      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 років тому +1

      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.

  • @nikims_
    @nikims_ 3 роки тому +1

    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?

  • @DaniiTheFox
    @DaniiTheFox 3 роки тому +1

    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;

  • @oraz.
    @oraz. 3 роки тому

    Did you make up this approximation?

  • @SuperToughnut
    @SuperToughnut 4 роки тому

    Is this like the diamond square algorithm in 2d?

  • @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?

  • @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

  • @bytelab3268
    @bytelab3268 3 роки тому +1

    Int sample1 x = (x/npitch) * npitch ???? What's the difference with just int sample1x = x

    • @javidx9
      @javidx9  3 роки тому +1

      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?

  • @deprogrammeur463
    @deprogrammeur463 3 роки тому

    can you do 3d perlin noise?

  • @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

  • @Test-iv4pm
    @Test-iv4pm 6 місяців тому

    Can you make a video extending to 3D? 🙂 Maybe even 4D? 😀

  • @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 років тому +2

      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.

  • @DaniloSouzaMoraes
    @DaniloSouzaMoraes 3 роки тому +1

    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 роки тому +1

      It is nothing more complicated than simple linear interpolation. Even has it's own function now std::lerp()

    • @DaniloSouzaMoraes
      @DaniloSouzaMoraes 3 роки тому +1

      @@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!

  • @megamech2268
    @megamech2268 6 років тому +3

    when i run the program, it tells me that "olcConsoleGameEngine.h" has no such file or directory.

    • @javidx9
      @javidx9  6 років тому +3

      Have you downloaded the "olcConsoleGameEngine.h" file as well?

  • @HerrHoldem
    @HerrHoldem 6 років тому +3

    Hello, Nice Video.
    Can you call which Graphic Library you use? Thank you!

    • @javidx9
      @javidx9  6 років тому +3

      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 років тому +1

      Thanks. I will research this.

  • @Prolute
    @Prolute 6 років тому

    Your 2d function only works when the width and height are the same size.

    • @javidx9
      @javidx9  6 років тому +1

      Hi Joe, correct it also prefers power of 2 dimensions also.

  • @KristijanPruzinac
    @KristijanPruzinac 3 роки тому

    Thank you for this!

  • @dutu000
    @dutu000 4 роки тому

    it would be interesting to hear how perlin noise sounds

  • @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

  • @samholland209
    @samholland209 Рік тому

    Do you know Minecraft uses this algorithm to generate its terrain?

  • @andresantana4086
    @andresantana4086 7 років тому

    Out of context, but, what font do u use at thumbnails?

    • @javidx9
      @javidx9  7 років тому +1

      Hey André, it's called Press Start and I stretch it vertically a little.

  • @GTS00000
    @GTS00000 7 років тому +3

    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 років тому +2

      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.

  • @CreativeOven
    @CreativeOven 4 роки тому

    that's cool for Worlds terrains.

  • @thefoolishgmodcube2644
    @thefoolishgmodcube2644 7 років тому

    Bisqwit and javidx9, which one is the best programmer?

    • @javidx9
      @javidx9  7 років тому +2

      Bisqwit. The guy's a machine.

    • @EximiusDux
      @EximiusDux 6 років тому +1

      javidx9 heh. His videos are alien in nature. His c++ nearly impossible to understand for me.

  • @olasoderlind5685
    @olasoderlind5685 5 років тому

    cold you do one lloop whit (mod)% of 1,2,4,8,16

  • @piotrjaga6929
    @piotrjaga6929 2 роки тому

    thank you

  • @NicoFye
    @NicoFye 6 років тому +1

    Maube someone can tell me how to make more plains?

  • @1st_ProCactus
    @1st_ProCactus 7 років тому +1

    Cool, Im in.. Nice font size

    • @javidx9
      @javidx9  7 років тому +1

      Hi ProCactus!

  • @pinurim9861
    @pinurim9861 6 років тому +1

    thanks

  • @tedeusz83
    @tedeusz83 5 років тому

    Worms terrain generator :)

  • @clementtarin9936
    @clementtarin9936 3 роки тому

    wow

  • @tangerian319
    @tangerian319 6 років тому +4

    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 років тому +5

      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 років тому +2

      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 років тому +2

      "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 роки тому +1

    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?