naev 0.10.4
Data Structures | Macros | Functions
perlin.c File Reference

Handles creating noise based on perlin noise. More...

#include "perlin.h"
#include "log.h"
#include "nfile.h"
#include "nstring.h"
#include "rng.h"

Go to the source code of this file.

Data Structures

struct  perlin_data_t
 Structure used for generating noise. More...
 

Macros

#define SIMPLEX_SCALE   0.5f
 
#define SWAP(a, b, t)   (t) = (a); (a) = (b); (b) = (t)
 
#define FLOOR(a)   ((int)(a) - ((a) < 0 && (a) != (int)(a)))
 
#define NOISE_SIMPLEX_GRADIENT_1D(n, h, x)   { float grad; h &= 0xF; grad=1.0f+(h & 7); if ( h & 8 ) grad = -grad; n = grad * x; }
 

Functions

perlin_data_t * noise_new (void)
 Creates a new perlin noise generator. More...
 
float noise_simplex1 (perlin_data_t *pdata, float f[1])
 Gets 1D simplex noise for a position. More...
 
void noise_delete (perlin_data_t *pdata)
 Frees some noise data. More...
 

Detailed Description

Handles creating noise based on perlin noise.

Code tries to handle basically 2d/3d cases, without much genericness because it needs to be pretty fast. Originally sped up the code from about 20 seconds to 8 seconds per Nebula image with the manual loop unrolling.

Note
Tried to optimize a while back with SSE and the works, but because of the nature of how it's implemented in non-linear fashion it just wound up complicating the code without actually making it faster.

Definition in file perlin.c.

Macro Definition Documentation

◆ FLOOR

#define FLOOR (   a)    ((int)(a) - ((a) < 0 && (a) != (int)(a)))

Limits to 0.

Definition at line 71 of file perlin.c.

◆ NOISE_SIMPLEX_GRADIENT_1D

#define NOISE_SIMPLEX_GRADIENT_1D (   n,
  h,
 
)    { float grad; h &= 0xF; grad=1.0f+(h & 7); if ( h & 8 ) grad = -grad; n = grad * x; }

Definition at line 97 of file perlin.c.

◆ SIMPLEX_SCALE

#define SIMPLEX_SCALE   0.5f

Definition at line 60 of file perlin.c.

◆ SWAP

#define SWAP (   a,
  b,
 
)    (t) = (a); (a) = (b); (b) = (t)

Swaps two values.

Definition at line 70 of file perlin.c.

Function Documentation

◆ noise_delete()

void noise_delete ( perlin_data_t *  pdata)

Frees some noise data.

Parameters
pdataNoise data to free.

Definition at line 132 of file perlin.c.

◆ noise_new()

perlin_data_t * noise_new ( void  )

Creates a new perlin noise generator.

Definition at line 76 of file perlin.c.

◆ noise_simplex1()

float noise_simplex1 ( perlin_data_t *  pdata,
float  f[1] 
)

Gets 1D simplex noise for a position.

Parameters
pdataPerlin data to generate noise from.
fPosition of the noise.

Definition at line 105 of file perlin.c.