naev 0.12.5
perlin.c File Reference

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

#include "perlin.h"
#include "rng.h"
Include dependency graph for perlin.c:

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)
#define FLOOR(a)
#define NOISE_SIMPLEX_GRADIENT_1D(n, h, x)

Functions

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

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)
Value:
( (int)( a ) - ( ( a ) < 0 && ( a ) != (int)( a ) ) )

Limits to 0.

Definition at line 65 of file perlin.c.

◆ NOISE_SIMPLEX_GRADIENT_1D

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

Definition at line 92 of file perlin.c.

◆ SIMPLEX_SCALE

#define SIMPLEX_SCALE   0.5f

Definition at line 51 of file perlin.c.

◆ SWAP

#define SWAP ( a,
b,
t )
Value:
( t ) = ( a ); \
( a ) = ( b ); \
( b ) = ( t )

Swaps two values.

Definition at line 61 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 135 of file perlin.c.

◆ noise_new()

perlin_data_t * noise_new ( void )

Creates a new perlin noise generator.

Definition at line 71 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 108 of file perlin.c.