Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Perlin noise in a fragment shader

  1. #1
    Intern Contributor
    Join Date
    Sep 2003
    Location
    Montreal, Canada
    Posts
    77

    Perlin noise in a fragment shader

    Did anyone ever come across a really good implementation of Perlin noise done in a fragment shader anywhere?

  2. #2
    Junior Member Regular Contributor
    Join Date
    Feb 2004
    Posts
    249

    Re: Perlin noise in a fragment shader

    Not Perlin noise but "simplex noise".
    Do a seach for it in the OpenGL Shading Forum.

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2003
    Location
    Zagreb, Croatia
    Posts
    14

    Re: Perlin noise in a fragment shader

    Here's the "improved" Perlin noise.

    http://free-zg.htnet.hr/KishBros/Kre...W/PerlinHW.htm

    I doubt you'll find it very useful, it pretty much eats up the entire instruction count on SM2 hardware.

  4. #4
    Senior Member OpenGL Pro cass's Avatar
    Join Date
    Feb 2000
    Location
    Austin, TX, USA
    Posts
    1,058

    Re: Perlin noise in a fragment shader

    In the NVSDK you can look at:
    MEDIA/programs/cg_gnoise/fp16noise.cg

    For an implementation of Perlin's traditional
    noise function.

    It's part of the cg_gnoise demo.

    I've been thinking about doing one for simplex noise as well.
    Cass Everitt -- cass@xyzw.us

  5. #5
    Junior Member Regular Contributor
    Join Date
    Aug 2001
    Posts
    204

    Re: Perlin noise in a fragment shader

    Have a look at simplex noise paper and implementation with source code:
    simplex noise

    and at the bottom of this page:
    noise example

    kon

  6. #6
    Junior Member Regular Contributor
    Join Date
    Feb 2003
    Location
    Waltham, MA
    Posts
    126

    Re: Perlin noise in a fragment shader

    I'm not sure if this helps, but I commonly use a lookup table for noise. I generate noise at startup and quantize into a reasonably sized 3D texture. I use 8x8x32 with a 32-bit RGBA (each component is 8 bits) color texture. On some of the more recent cards, a texture less than 8K will fit entirely in the texture cache (or so it seems from some of my perf tests). I address the texture using vec3 texcoord = gl_FragCoord.xyz * vec2(0.125, 0.125, sample / 32) with the addressing mode set to repeat and the filtering mode set to nearest. Hope this helps.

    Kevin B

  7. #7
    Junior Member Regular Contributor
    Join Date
    Aug 2001
    Location
    Norrkoping, Sweden
    Posts
    119

    Re: Perlin noise in a fragment shader

    That old GLSL demo of mine actually had regular Perlin noise as well as simplex noise in there, it was just not the default. Look at the shader source and you will see six functions: both regular and simplex noise for 2D, 3D and 4D noise. It's a pretty hefty shader, but it does run on any Nvidia card from FX5xxx and up, and with good performance on anything from FX6800 and up. On some older ATI cards the 3D and 4D versions exceed the maximum instruction count, but the 2D versions work fine even on pretty outdated hardware.

  8. #8
    Junior Member Regular Contributor
    Join Date
    Nov 2007
    Location
    London UK
    Posts
    242

    Re: Perlin noise in a fragment shader

    Quote Originally Posted by kon
    Have a look at simplex noise paper and implementation with source code:
    simplex noise

    and at the bottom of this page:
    noise example

    kon
    Hiya,

    thanks very much for sharing your code. I'm looking forward to giving it a go!
    Do you happen to have example textures for use with the example shaders, to get me started?

    Cheers,

    a|x
    http://machinesdontcare.wordpress.com

  9. #9
    Junior Member Regular Contributor
    Join Date
    Jan 2005
    Posts
    180

    Re: Perlin noise in a fragment shader

    There are builtin noise functions in GLSL.

    There currently is a discussion on the Mesa mailing list about how to implement noise the best way. The proposal currently discussed seems to work fine even on Intel cards.

    Philipp

  10. #10
    Junior Member Regular Contributor
    Join Date
    Nov 2007
    Location
    London UK
    Posts
    242

    Re: Perlin noise in a fragment shader

    Maybe I've got the wrong end of the stick here.. is the 4-channel noise texture kon mentions in the readme in the example zip (I downloaded the MacOS X port package) simply an RGBA texture with random values in all channels? Or, are the values in the alpha channel different to those in the other 3 channels?

    Sorry again for asking stupid questions,

    a|x
    http://machinesdontcare.wordpress.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •