FFmpeg
Loading...
Searching...
No Matches
perlin.h
Go to the documentation of this file.
1/*
2 * Perlin noise generator
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
22 * @file
23 * Perlin Noise generator
24 */
25
26#ifndef AVFILTER_PERLIN_H
27#define AVFILTER_PERLIN_H
28
29#include <stdint.h>
30
37
38/**
39 * Perlin generator context. This needs to be initialized with the
40 * parameters used to generate the Perlin noise.
41 */
42typedef struct FFPerlin {
43 /**
44 * spatial repeat period, if negative it is ignored
45 */
46 double period;
47
48 /**
49 * total number of components making up the noise, each one with
50 * doubled frequency
51 */
53
54 /**
55 * ratio used to compute the amplitude of the next octave
56 * component with respect to the previous component
57 */
59
60 /**
61 * permutations array used to compute the Perlin noise hash
62 */
63 uint8_t permutations[512];
64
65 /**
66 * define how to compute the permutations array
67 */
69
70 /**
71 * when random_mode is set FF_PERLIN_RANDOM_MODE_RANDOM, set random
72 * seed used to compute the permutations array
73 */
74 unsigned int random_seed;
75} FFPerlin;
76
77/**
78 * Initialize the Perlin noise generator with parameters.
79 *
80 * @param perlin Perlin noise generator context
81 * @param period spatial repeat period, if negative it is ignored
82 * @param octaves total number of components making up the noise, each one with doubled frequency
83 * @param persistence define ratio used to compute the amplitude of the next octave
84 * component with respect to the previous component
85 * @param random_mode define how to compute the permutations array
86 * @param random_seed when random_mode is set to FF_PERLIN_RANDOM_MODE_RANDOM, set random
87 * seed used to compute the permutations array
88 * @return a negative AVERROR code in case of error, a non negative value otherwise
89 */
90int ff_perlin_init(FFPerlin *perlin, double period, int octaves, double persistence,
91 enum FFPerlinRandomMode random_mode, unsigned int random_seed);
92
93/**
94 * Compute Perlin noise given the x, y, z coordinates.
95 *
96 * @param perlin Perlin noise generator context
97 * @return normalized value for the perlin noise, in the range [0, 1]
98 */
99double ff_perlin_get(FFPerlin *perlin, double x, double y, double z);
100
101#endif /* AVFILTER_PERLIN_H */
int ff_perlin_init(FFPerlin *perlin, double period, int octaves, double persistence, enum FFPerlinRandomMode random_mode, unsigned int random_seed)
Initialize the Perlin noise generator with parameters.
Definition perlin.c:101
double ff_perlin_get(FFPerlin *perlin, double x, double y, double z)
Compute Perlin noise given the x, y, z coordinates.
Definition perlin.c:208
FFPerlinRandomMode
Definition perlin.h:31
@ FF_PERLIN_RANDOM_MODE_NB
Definition perlin.h:35
@ FF_PERLIN_RANDOM_MODE_RANDOM
Definition perlin.h:32
@ FF_PERLIN_RANDOM_MODE_SEED
Definition perlin.h:34
@ FF_PERLIN_RANDOM_MODE_KEN
Definition perlin.h:33
Perlin generator context.
Definition perlin.h:42
unsigned int random_seed
when random_mode is set FF_PERLIN_RANDOM_MODE_RANDOM, set random seed used to compute the permutation...
Definition perlin.h:74
double period
spatial repeat period, if negative it is ignored
Definition perlin.h:46
enum FFPerlinRandomMode random_mode
define how to compute the permutations array
Definition perlin.h:68
double persistence
ratio used to compute the amplitude of the next octave component with respect to the previous compone...
Definition perlin.h:58
uint8_t permutations[512]
permutations array used to compute the Perlin noise hash
Definition perlin.h:63
int octaves
total number of components making up the noise, each one with doubled frequency
Definition perlin.h:52