Software-OK
≡... News | ... Home | ... FAQ | Impressum | Contact | Listed at | Thank you |

  
HOME ► Faq ► FAQ - Windows-CPP-und-C ► ««« »»»

What is Perlin Noise?


At some point while programming you are confronted with the term Perlin or Noise or Perlin-Noise and ask yourself what kind of function it is and what is it good for!



Here it is explained nicely but dryly ►  wikipedia.... Perlin-Noise . In short, they are pattern generation algorithms based on random numbers that are intended to simulate random-based but still orderly behavior! As we know from nature, all leaves are identical in some way but not the same. Or all birds  are similar, but not all are chickens, ... etc.



1.) ... Example of a simple Perlin noise as a simple cloud!
2.) ... Why should I know this, do I have to understand Perlin noise!
​​3.) ... Simple Perlin noise example code in CPP


1.) Example of a simple Perlin noise as a simple cloud!

https://thebookofshaders.com/edit.php?log=161127235422
https://thebookofshaders.com/edit.php#10/ikeda-03.frag
https://thebookofshaders.com/edit.php#11/2d- vnoise.frag


https://thebookofshaders.com/edit.php#11/2d-vnoise.frag


(Picture-3) Perlin-Noise Wood!
Perlin-Noise Wood!


-
▲ Back to the top ▲


https://web.archive.org/web/20160604173317/http://freespace.virgin.net/hugo.elias/models/m_clouds.htm

Real-time Perlin noise coded to generate the clouds and all the rest of the graphics stuff, and Matt designed the overall program and wrote the all-important inner loop that actually makes the clouds as good as they are.

(Image-4) Clouds with Perlin noise as a function!
Clouds with Perlin Noise as a function!




-
▲ Back to the top ▲



2.) Why do I need this knowledge? I need to understand Perlin Noise!

Large game companies, film industries, ... can hire armies of artists and developers to create the impossible that make up the virtual world of the game or 3D graphics for movies. If you want to design a game or 3D task without such financial means and extensive resources to generate an attractive alternative for certain natural phenomena such as terrain, trees and atmospheric effects, then by using auto-generation you will achieve the same or even better. With the help of a simple random number generator, a high quality auto-generation system can produce remarkably realistic models and objects.


Other useful links: 
►  https://www.cs.umd.edu/class/fall2019/cmsc425/handouts/lect14-perlin.pdf
Even an Oscar:
►  https://web.archive.org/web/20211208192020/https://mrl.cs.nyu.edu/~perlin/doc/oscar.html

Ken Perlin page:
►  https://mrl.cs.nyu.edu/~perlin/


(Image-1) Ken Perlin and more features!
Ken Perlin and more features!

-
▲ Back to the top ▲




Or to generate an entire city 
►  https://www.shadertoy.com/view/XtsSWs


(Image-2) Perlin noise and city with or from random numbers!
Perlin noise and city with or from random numbers!

-
▲ Back to the top ▲


3.) Simple Perlin-Noise example code in CPP


Your C++ code implements Perlin noise generation and uses the C++ standard library for some functions. Here is a commented version of your code in English:

//Here's the translated and explained C++ code for generating Perlin noise, including comments on the functionality:
 
 
#include <iostream>
#include <cmath>
#include <vector>
#include <conio.h>  // For _getch to wait for a key press
 
std::vector<int> permutation = std::vector<int>(512);
 
class PerlinNoise 
{
public:
 PerlinNoise() {
  int i = 0;
  // Initialize the permutation vector with values from 0 to 255
  for (i = 0; i < 256; ++i) {
   permutation[i] = i;
  }
 
  // Shuffle the permutation vector using a custom random number generator
  int seed = 42; // You can change the seed for different patterns
  shufflePermutation(seed);
 
  // Duplicate the permutation vector to make wrapping easier
  for (i = 0; i < 256; ++i) {
   permutation[256 + i] = permutation[i];
  }
 }
 
 double noise(double x, double y, double z) const {
  int X = static_cast<int>(floor(x)) & 255;
  int Y = static_cast<int>(floor(y)) & 255;
  int Z = static_cast<int>(floor(z)) & 255;
 
  x -= floor(x);
  y -= floor(y);
  z -= floor(z);
 
  double u = fade(x);
  double v = fade(y);
  double w = fade(z);
 
  int A = permutation[X] + Y;
  int AA = permutation[A] + Z;
  int AB = permutation[A + 1] + Z;
  int B = permutation[X + 1] + Y;
  int BA = permutation[B] + Z;
  int BB = permutation[B + 1] + Z;
 
  double p1 = grad(permutation[AA], x, y, z);
  double p2 = grad(permutation[BA], x - 1, y, z);
  double p3 = grad(permutation[AB], x, y - 1, z);
  double p4 = grad(permutation[BB], x - 1, y - 1, z);
  double p5 = grad(permutation[AA + 1], x, y, z - 1);
  double p6 = grad(permutation[BA + 1], x - 1, y, z - 1);
  double p7 = grad(permutation[AB + 1], x, y - 1, z - 1);
  double p8 = grad(permutation[BB + 1], x - 1, y - 1, z - 1);
 
  double x1 = lerp(u, p1, p2);
  double x2 = lerp(u, p3, p4);
  double x3 = lerp(u, p5, p6);
  double x4 = lerp(u, p7, p8);
 
  double y1 = lerp(v, x1, x2);
  double y2 = lerp(v, x3, x4);
 
  return lerp(w, y1, y2);
 }
 
private:
 double fade(double t) const {
  return t * t * t * (t * (t * 6 - 15) + 10);
 }
 
 double lerp(double t, double a, double b) const {
  return a + t * (b - a);
 }
 
 double grad(int hash, double x, double y, double z) const {
  int h = hash & 15;
  double u = h < 8 ? x : y;
  double v = h < 4 ? y : (h == 12 || h == 14 ? x : z);
  return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
 }
 
 void shufflePermutation(int seed) {
  int size = permutation.size();
  for (int i = size - 1; i > 0; --i) {
   int j = seed % (i + 1);
   std::swap(permutation[i], permutation[j]);
  }
 }
};
 
int main() {
 PerlinNoise perlin;
 double x = 5.0, y = 10.0, z = 15.0;
 double noiseValue = perlin.noise(x, y, z);
 std::cout << "Perlin noise at (" << x << ", " << y << ", " << z << ") = " << noiseValue << std::endl;
 
 std::cout << "Press any key to continue...\n";
 
 // Wait for a key press
 _getch();
 
 return 0;
}


FAQ 35: Updated on: 4 September 2024 11:03 Windows
Windows-CPP-und-C

Dark theme in Win32 applications with menu and title bar!


It is not that easy to activate and use Dark Theme in Win32 applications with menu and title bar for Windows 11 & 10 Here I have found two open source projects
Windows-CPP-und-C

Visual Studio 2022 takes forever and is slow, why?


It is difficult to work with Visual Studio 2022 on old hardware, it takes a long time and is very slow, thats why you need the latest hardware Ideally
Windows-CPP-und-C

Use WebView2?


Is a new control and is a browser control in Microsoft called WebView2, successor to CHtmlView or IWebBrowser Contents: 1. The new Microsoft browser
Windows-CPP-und-C

Is a number a prime number in C++?


The function IsPrime returns true if the given number is a prime number; otherwise, it returns false 1. Prime Number Detection in C++: 2. Explanation of
Windows-CPP-und-C

Using arrays and strings in C programs!


This C program explains and demonstrates some important concepts related to the use of arrays and strings. Lets walk through the different aspects of this
Windows-CPP-und-C

Find and replace words in clean C program?


Searching and replacing words or substrings in text is not necessarily simple or difficult in C 1. Search and Replace in a C Program: 2. Tips for Searching
Windows-CPP-und-C

Rename files in C++ with wildcards across directories?


Renaming Files in C++ Across Directories with Placeholders, and the Simplicity of Renaming Files in Windows 1. Renaming Files Across Directories with Placeholders

»»

  My question is not there in the FAQ
Asked questions on this answer:
Keywords: cpp, windows, what, perlin, noise, some, point, while, programming, confronted, with, term, perlin-noise, yourself, kind, function, Questions, Answers, Software




  

  + Freeware
  + Order on the PC
  + File management
  + Automation
  + Office Tools
  + PC testing tools
  + Decoration and fun
  + Desktop-Clocks
  + Security

  + SoftwareOK Pages
  + Micro Staff
  + Freeware-1
  + Freeware-2
  + Freeware-3
  + FAQ
  + Downloads

  + Top
  + Desktop-OK
  + The Quad Explorer
  + Don't Sleep
  + Win-Scan-2-PDF
  + Quick-Text-Past
  + Print Folder Tree
  + Find Same Images
  + Experience-Index-OK
  + Font-View-OK


  + Freeware
  + ShortDoorNote
  + AutoHideDesktopIcons
  + BlankAndSecure
  + AlwaysMouseWheel
  + NewFileTime
  + DesktopClock3D
  + PointerStick
  + DesktopImages3D
  + WinPing
  + PAD-s


Home | Thanks | Contact | Link me | FAQ | Settings | Windows 10 | gc24b | English-AV | Impressum | Translate | PayPal | PAD-s

 © 2025 by Nenad Hrg softwareok.de • softwareok.com • softwareok.com • softwareok.eu


► Where is the Windows 10/11 Start Sound, Logoff, Logon (enable, activate)? ◄
► Remove a WiFi connection from Windows 10 / 11, how to? ◄
► How can I handle drives in Windows? ◄
► Can I change my Windows-10 homegroup password? ◄


This website does not store personal data. However, third-party providers are used to display ads,
which are managed by Google and comply with the IAB Transparency and Consent Framework (IAB-TCF).
The CMP ID is 300 and can be individually customized at the bottom of the page.
more Infos & Privacy Policy

....