Skip to content
stegu edited this page Apr 11, 2011 · 40 revisions

Noise for GLSL 1.20

This repository contains GLSL source code for Perlin noise in 2D, 3D and 4D, both the modern simplex versions and the classic versions, including periodic noise similar to the pnoise() function in RenderMan SL. The functions have very good performance and no dependencies on external data. The code is open source, licensed under the terms of the OSI-approved and very permissive MIT license. For licensing details, please refer to the LICENSE file in the repository.

We have submitted a scientific paper about this to a peer review journal, so please bear with us for not explaining every detail while the paper is in review. However, while you are waiting for proper documentation, you can still download and use the functions. They require no setup or external data, just the GLSL source provided here, and they should work on any current OpenGL platform, including OpenGL 2.1, OpenGL 3.x and 4.x, OpenGL ES 2.x and WebGL 1.0.

NOTE: You do not need a super fast GPU to use these functions. They are useful even on low end hardware, old hardware and embedded OpenGL ES hardware with low performance.

The repository also contains C code for a cross-platform benchmark and a demo. To compile and run these programs, you need a desktop OS like Linux, Windows, MacOSX or some flavor of Unix with OpenGL support, and the GLFW library (http://glfw.sourceforge.net). Makefiles are provided for Linux, Windows and MacOS X.

The GLSL source files and the noise functions you will currently find here are:

  • noise2D.glsl - 2D simplex noise float snoise(vec2 x). Very fast, very compact code.

  • noise3D.glsl - 3D simplex noise float snoise(vec3 x). Fast, compact code.

  • noise4D.glsl - 4D simplex noise float snoise(vec4 x). Reasonably fast, reasonably compact code.

  • classicnoise2D.glsl - 2D classic Perlin noise float cnoise(vec2 x), and a periodic variant float pnoise(vec2 x, vec2 period). Fast and compact code, only slightly slower than 2D simplex noise.

  • classicnoise3D.glsl - 3D classic Perlin noise float cnoise(vec3 x), and a periodic variant float pnoise(vec3 x, vec3 period). Reasonably fast but not very compact code. Not quite as fast as 3D simplex noise.

  • classicnoise4D.glsl - 4D classic Perlin noise float cnoise(vec4 x), and a periodic variant float pnoise(vec4 x, vec4 period). Only about half as fast as 4D simplex noise, and rather bloated code, but still useful.

Other noise implementations

The motivation for these functions not using any textures is ease of use, self-sufficiency and scalability for massively parallel execution. Noise is seldom used by itself, and these functions can make use of the often untapped ALU resources when run concurrently with traditional texture-intensive real time rendering tasks. However, if you are generating noise by itself and using a lot of it, the texture-intensive noise implementations this work was based on are still up to twice as fast on current generation desktop GPU hardware with lots of texture units and smart texture caching. You can find the original release of the old noise code on http://www.itn.liu.se/~stegu/simplexnoise/GLSL-noise.zip (Windows binary, Windows-dependent source code). A newly written cross platform benchmark comparing it to this new version is on http://www.itn.liu.se/~stegu/simplexnoise/GLSL-noise-vs-noise.zip. For the convenience of Windows users, a version with a precompiled Windows binary is in http://www.itn.liu.se/~stegu/simplexnoise/GLSL-noise-vs-noise-Win32.zip.

Clone this wiki locally