3

I have a couple of questions about Simplex Noise. I'm using Simplex Noise to generate a terrain in directx but I'm currently doing it using classes and such. I will probably use this for textures as well, so is it necessary to change it into a shader implementation? And if so, is this easily done?

Also, for textures is it better to use 3D or 2D noise?

3 Answers3

8

Yeah, you really should move this work to the GPU, it's what it's best at.

Simplex noise on the GPU is a solved problem. You can find a great paper on the subject here, or you can grab an implementation from here.

That implementation is in GLSL, but porting it is simply a matter of changing vec3's & vec4's to float3's and float4's.

Having used that, I have found that by far the fastest noise function implementation is an implementation of Perlin noise by inigo quilez (the implementation provided below is taken from code found on the shadertoy.com website. It's a great site, check it out!

#ifndef __noise_hlsl_
#define __noise_hlsl_

// hash based 3d value noise
// function taken from https://www.shadertoy.com/view/XslGRr
// Created by inigo quilez - iq/2013
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

// ported from GLSL to HLSL

float hash( float n )
{
    return frac(sin(n)*43758.5453);
}

float noise( float3 x )
{
    // The noise function returns a value in the range -1.0f -> 1.0f

    float3 p = floor(x);
    float3 f = frac(x);

    f       = f*f*(3.0-2.0*f);
    float n = p.x + p.y*57.0 + 113.0*p.z;

    return lerp(lerp(lerp( hash(n+0.0), hash(n+1.0),f.x),
                   lerp( hash(n+57.0), hash(n+58.0),f.x),f.y),
               lerp(lerp( hash(n+113.0), hash(n+114.0),f.x),
                   lerp( hash(n+170.0), hash(n+171.0),f.x),f.y),f.z);
}

#endif
fishfood
  • 4,092
  • 4
  • 28
  • 35
1

I'd like to complete the above answer with a picture of the above answer's marvellous function, so you can qualify it (it is similar to valuenoise from libnoise library)

as you can see it's awesome and it needs to be adapted to handle negative space values (absolute the x y z axes)... obviously it is 3d so expect the same morphology on y axis.

enter image description here

enter image description here

bandybabboon
  • 2,210
  • 1
  • 23
  • 33
-2

If your application is not using the noise mesh and textures dynamically then you should keep the offline creation that you currently use for your mesh. If however you would like to have your mesh and textures dynamically change over time (think deformable terrain) then it would be necessary to change it to a shader implementation if a high fps is important to you. It can be done, however im not sure of your level of ability to claim it to be easy. It would involve the use of geometry shaders (and maybe stream-out) for the case of your terrain mesh, and pixel shaders to create your textures.

As for using 2d or 3d noise for textures, it depends on your usage needs. 3d textures are good for representing things like force fields, voxel fields etc. They are however expensive create dynamically. If you just want to use the texture as a regular mesh material then 2d is the way to go.

alanw
  • 645
  • 6
  • 10
  • Thankyou for the above code, it awesome alhtough it doesnt work in negative values, i have made a picture of it so you can qualify, it is similar to libnoise value noise: [IMG]http://i59.tinypic.com/ff8zt0.jpg[/IMG] – bandybabboon Feb 07 '14 at 13:02