perlin.h -> noise.h

This commit is contained in:
Marcin
2025-01-15 14:05:01 +00:00
parent 43c9f84c8c
commit a0d8803f76
15 changed files with 68 additions and 68 deletions

View File

@@ -93,7 +93,7 @@ add_library(${PROJECT_NAME}
src/mat4x2.c src/mat4x2.c
src/mat4x3.c src/mat4x3.c
src/plane.c src/plane.c
src/perlin.c src/noise.c
src/frustum.c src/frustum.c
src/box.c src/box.c
src/project.c src/project.c

View File

@@ -67,7 +67,7 @@ cglm_HEADERS = include/cglm/version.h \
include/cglm/util.h \ include/cglm/util.h \
include/cglm/quat.h \ include/cglm/quat.h \
include/cglm/plane.h \ include/cglm/plane.h \
include/cglm/perlin.h \ include/cglm/noise.h \
include/cglm/frustum.h \ include/cglm/frustum.h \
include/cglm/box.h \ include/cglm/box.h \
include/cglm/aabb2d.h \ include/cglm/aabb2d.h \
@@ -121,7 +121,7 @@ cglm_call_HEADERS = include/cglm/call/mat4.h \
include/cglm/call/quat.h \ include/cglm/call/quat.h \
include/cglm/call/euler.h \ include/cglm/call/euler.h \
include/cglm/call/plane.h \ include/cglm/call/plane.h \
include/cglm/call/perlin.h \ include/cglm/call/noise.h \
include/cglm/call/frustum.h \ include/cglm/call/frustum.h \
include/cglm/call/box.h \ include/cglm/call/box.h \
include/cglm/call/project.h \ include/cglm/call/project.h \
@@ -212,7 +212,7 @@ cglm_struct_HEADERS = include/cglm/struct/mat4.h \
include/cglm/struct/quat.h \ include/cglm/struct/quat.h \
include/cglm/struct/euler.h \ include/cglm/struct/euler.h \
include/cglm/struct/plane.h \ include/cglm/struct/plane.h \
include/cglm/struct/perlin.h \ include/cglm/struct/noise.h \
include/cglm/struct/frustum.h \ include/cglm/struct/frustum.h \
include/cglm/struct/box.h \ include/cglm/struct/box.h \
include/cglm/struct/aabb2d.h \ include/cglm/struct/aabb2d.h \
@@ -264,7 +264,7 @@ libcglm_la_SOURCES=\
src/mat4x2.c \ src/mat4x2.c \
src/mat4x3.c \ src/mat4x3.c \
src/plane.c \ src/plane.c \
src/perlin.c \ src/noise.c \
src/frustum.c \ src/frustum.c \
src/box.c \ src/box.c \
src/project.c \ src/project.c \

View File

@@ -66,7 +66,7 @@ Follow the :doc:`build` documentation for this
ivec4 ivec4
color color
plane plane
perlin noise
project project
util util
io io

View File

@@ -3,7 +3,7 @@
perlin perlin
================================================================================ ================================================================================
Header: cglm/perlin.h Header: cglm/noise.h
Classic Perlin noise implementation. Classic Perlin noise implementation.
@@ -12,13 +12,13 @@ Table of contents (click to go):
Functions: Functions:
1. :c:func:`glm_perlin` 1. :c:func:`glm_perlin_vec4`
Functions documentation Functions documentation
~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~
.. c:function:: float glm_perlin(vec4 point) .. c:function:: float glm_perlin_vec4(vec4 point)
| Classic Perlin noise | Classic Perlin noise

View File

@@ -32,7 +32,7 @@ extern "C" {
#include "call/quat.h" #include "call/quat.h"
#include "call/euler.h" #include "call/euler.h"
#include "call/plane.h" #include "call/plane.h"
#include "call/perlin.h" #include "call/noise.h"
#include "call/frustum.h" #include "call/frustum.h"
#include "call/aabb2d.h" #include "call/aabb2d.h"
#include "call/box.h" #include "call/box.h"

View File

@@ -5,8 +5,8 @@
* Full license can be found in the LICENSE file * Full license can be found in the LICENSE file
*/ */
#ifndef cglmc_perlin_h #ifndef cglmc_noise_h
#define cglmc_perlin_h #define cglmc_noise_h
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@@ -15,9 +15,9 @@ extern "C" {
CGLM_EXPORT CGLM_EXPORT
float float
glmc_perlin(vec4 point); glmc_perlin_vec4(vec4 point);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* cglmc_perlin_h */ #endif /* cglmc_noise_h */

View File

@@ -30,7 +30,7 @@
#include "quat.h" #include "quat.h"
#include "euler.h" #include "euler.h"
#include "plane.h" #include "plane.h"
#include "perlin.h" #include "noise.h"
#include "aabb2d.h" #include "aabb2d.h"
#include "box.h" #include "box.h"
#include "color.h" #include "color.h"

View File

@@ -5,8 +5,8 @@
* Full license can be found in the LICENSE file * Full license can be found in the LICENSE file
*/ */
#ifndef cglm_perlin_h #ifndef cglm_noise_h
#define cglm_perlin_h #define cglm_noise_h
#include "vec4.h" #include "vec4.h"
#include "vec4-ext.h" #include "vec4-ext.h"
@@ -109,7 +109,7 @@ _glm_vec4_muls(vec4 x, float y, vec4 dest) {
CGLM_INLINE CGLM_INLINE
float float
_glm_perlinDetail_mod289(float x) { _glm_noiseDetail_mod289(float x) {
return x - floorf(x * (1.0f / 289.0f)) * 289.0f; return x - floorf(x * (1.0f / 289.0f)) * 289.0f;
} }
@@ -121,11 +121,11 @@ _glm_perlinDetail_mod289(float x) {
// } // }
CGLM_INLINE CGLM_INLINE
void void
_glm_perlinDetail_permute(vec4 x, vec4 dest) { _glm_noiseDetail_permute(vec4 x, vec4 dest) {
dest[0] = _glm_perlinDetail_mod289((x[0] * 34.0f + 1.0f) * x[0]); dest[0] = _glm_noiseDetail_mod289((x[0] * 34.0f + 1.0f) * x[0]);
dest[1] = _glm_perlinDetail_mod289((x[1] * 34.0f + 1.0f) * x[1]); dest[1] = _glm_noiseDetail_mod289((x[1] * 34.0f + 1.0f) * x[1]);
dest[2] = _glm_perlinDetail_mod289((x[2] * 34.0f + 1.0f) * x[2]); dest[2] = _glm_noiseDetail_mod289((x[2] * 34.0f + 1.0f) * x[2]);
dest[3] = _glm_perlinDetail_mod289((x[3] * 34.0f + 1.0f) * x[3]); dest[3] = _glm_noiseDetail_mod289((x[3] * 34.0f + 1.0f) * x[3]);
} }
@@ -137,7 +137,7 @@ _glm_perlinDetail_permute(vec4 x, vec4 dest) {
CGLM_INLINE CGLM_INLINE
void void
_glm_perlinDetail_fade(vec4 t, vec4 dest) { _glm_noiseDetail_fade(vec4 t, vec4 dest) {
dest[0] = (t[0] * t[0] * t[0]) * (t[0] * (t[0] * 6.0f - 15.0f) + 10.0f); dest[0] = (t[0] * t[0] * t[0]) * (t[0] * (t[0] * 6.0f - 15.0f) + 10.0f);
dest[1] = (t[1] * t[1] * t[1]) * (t[1] * (t[1] * 6.0f - 15.0f) + 10.0f); dest[1] = (t[1] * t[1] * t[1]) * (t[1] * (t[1] * 6.0f - 15.0f) + 10.0f);
dest[2] = (t[2] * t[2] * t[2]) * (t[2] * (t[2] * 6.0f - 15.0f) + 10.0f); dest[2] = (t[2] * t[2] * t[2]) * (t[2] * (t[2] * 6.0f - 15.0f) + 10.0f);
@@ -146,7 +146,7 @@ _glm_perlinDetail_fade(vec4 t, vec4 dest) {
CGLM_INLINE CGLM_INLINE
void void
_glm_perlinDetail_taylorInvSqrt(vec4 x, vec4 dest) { _glm_noiseDetail_taylorInvSqrt(vec4 x, vec4 dest) {
dest[0] = 1.79284291400159f - 0.85373472095314f * x[0]; dest[0] = 1.79284291400159f - 0.85373472095314f * x[0];
dest[1] = 1.79284291400159f - 0.85373472095314f * x[1]; dest[1] = 1.79284291400159f - 0.85373472095314f * x[1];
dest[2] = 1.79284291400159f - 0.85373472095314f * x[2]; dest[2] = 1.79284291400159f - 0.85373472095314f * x[2];
@@ -163,7 +163,7 @@ _glm_perlinDetail_taylorInvSqrt(vec4 x, vec4 dest) {
*/ */
CGLM_INLINE CGLM_INLINE
void void
_glm_perlinDetail_gradNorm(vec4 g00__, vec4 g01__, vec4 g10__, vec4 g11__) { _glm_noiseDetail_gradNorm(vec4 g00__, vec4 g01__, vec4 g10__, vec4 g11__) {
// norm = taylorInvSqrt(vec4( // norm = taylorInvSqrt(vec4(
// dot(g00__, g00__), // dot(g00__, g00__),
@@ -176,7 +176,7 @@ _glm_perlinDetail_gradNorm(vec4 g00__, vec4 g01__, vec4 g10__, vec4 g11__) {
norm[1] = glm_vec4_dot(g01__, g01__); // norm.y = dot(g01__, g01__) norm[1] = glm_vec4_dot(g01__, g01__); // norm.y = dot(g01__, g01__)
norm[2] = glm_vec4_dot(g10__, g10__); // norm.z = dot(g10__, g10__) norm[2] = glm_vec4_dot(g10__, g10__); // norm.z = dot(g10__, g10__)
norm[3] = glm_vec4_dot(g11__, g11__); // norm.w = dot(g11__, g11__) norm[3] = glm_vec4_dot(g11__, g11__); // norm.w = dot(g11__, g11__)
_glm_perlinDetail_taylorInvSqrt(norm, norm); // norm = taylorInvSqrt(norm) _glm_noiseDetail_taylorInvSqrt(norm, norm); // norm = taylorInvSqrt(norm)
_glm_vec4_muls(g00__, norm[0], g00__); // g00__ *= norm.x _glm_vec4_muls(g00__, norm[0], g00__); // g00__ *= norm.x
_glm_vec4_muls(g01__, norm[1], g01__); // g01__ *= norm.y _glm_vec4_muls(g01__, norm[1], g01__); // g01__ *= norm.y
@@ -186,7 +186,7 @@ _glm_perlinDetail_gradNorm(vec4 g00__, vec4 g01__, vec4 g10__, vec4 g11__) {
CGLM_INLINE CGLM_INLINE
void void
_glm_perlinDetail_xy2g( _glm_noiseDetail_xy2g(
vec4 ixy, vec4 ixy,
/* out */ /* out */
vec4 gx, vec4 gx,
@@ -258,7 +258,7 @@ _glm_perlinDetail_xy2g(
*/ */
CGLM_INLINE CGLM_INLINE
float float
glm_perlin(vec4 point) { glm_perlin_vec4(vec4 point) {
// Integer part of p for indexing // Integer part of p for indexing
vec4 Pi0; vec4 Pi0;
_glm_vec4_floor(point, Pi0); // Pi0 = floor(point); _glm_vec4_floor(point, Pi0); // Pi0 = floor(point);
@@ -287,53 +287,53 @@ glm_perlin(vec4 point) {
// ixy = permute(permute(ix) + iy) // ixy = permute(permute(ix) + iy)
vec4 ixy; vec4 ixy;
_glm_perlinDetail_permute(ix, ixy); // ixy = permute(ix) _glm_noiseDetail_permute(ix, ixy); // ixy = permute(ix)
glm_vec4_add(ixy, iy, ixy); // ixy += iy; glm_vec4_add(ixy, iy, ixy); // ixy += iy;
_glm_perlinDetail_permute(ixy, ixy); // ixy = permute(ixy) _glm_noiseDetail_permute(ixy, ixy); // ixy = permute(ixy)
// ixy0 = permute(ixy + iz0) // ixy0 = permute(ixy + iz0)
vec4 ixy0; vec4 ixy0;
glm_vec4_add(ixy, iz0, ixy0); // ixy0 = ixy + iz0 glm_vec4_add(ixy, iz0, ixy0); // ixy0 = ixy + iz0
_glm_perlinDetail_permute(ixy0, ixy0); // ixy0 = permute(ixy0) _glm_noiseDetail_permute(ixy0, ixy0); // ixy0 = permute(ixy0)
// ixy1 = permute(ixy + iz1) // ixy1 = permute(ixy + iz1)
vec4 ixy1; vec4 ixy1;
glm_vec4_add(ixy, iz1, ixy1); // ixy1 = ixy, iz1 glm_vec4_add(ixy, iz1, ixy1); // ixy1 = ixy, iz1
_glm_perlinDetail_permute(ixy1, ixy1); // ixy1 = permute(ixy1) _glm_noiseDetail_permute(ixy1, ixy1); // ixy1 = permute(ixy1)
// ixy00 = permute(ixy0 + iw0) // ixy00 = permute(ixy0 + iw0)
vec4 ixy00; vec4 ixy00;
glm_vec4_add(ixy0, iw0, ixy00); // ixy00 = ixy0 + iw0 glm_vec4_add(ixy0, iw0, ixy00); // ixy00 = ixy0 + iw0
_glm_perlinDetail_permute(ixy00, ixy00); // ixy00 = permute(ixy00) _glm_noiseDetail_permute(ixy00, ixy00); // ixy00 = permute(ixy00)
// ixy01 = permute(ixy0 + iw1) // ixy01 = permute(ixy0 + iw1)
vec4 ixy01; vec4 ixy01;
glm_vec4_add(ixy0, iw1, ixy01); // ixy01 = ixy0 + iw1 glm_vec4_add(ixy0, iw1, ixy01); // ixy01 = ixy0 + iw1
_glm_perlinDetail_permute(ixy01, ixy01); // ixy01 = permute(ixy01) _glm_noiseDetail_permute(ixy01, ixy01); // ixy01 = permute(ixy01)
// ixy10 = permute(ixy1 + iw0) // ixy10 = permute(ixy1 + iw0)
vec4 ixy10; vec4 ixy10;
glm_vec4_add(ixy1, iw0, ixy10); // ixy10 = ixy1 + iw0 glm_vec4_add(ixy1, iw0, ixy10); // ixy10 = ixy1 + iw0
_glm_perlinDetail_permute(ixy10, ixy10); // ixy10 = permute(ixy10) _glm_noiseDetail_permute(ixy10, ixy10); // ixy10 = permute(ixy10)
// ixy11 = permute(ixy1 + iw1) // ixy11 = permute(ixy1 + iw1)
vec4 ixy11; vec4 ixy11;
glm_vec4_add(ixy1, iw1, ixy11); // ixy11 = ixy1 + iw1 glm_vec4_add(ixy1, iw1, ixy11); // ixy11 = ixy1 + iw1
_glm_perlinDetail_permute(ixy11, ixy11); // ixy11 = permute(ixy11) _glm_noiseDetail_permute(ixy11, ixy11); // ixy11 = permute(ixy11)
// ------------ // ------------
vec4 gx00, gy00, gz00, gw00; vec4 gx00, gy00, gz00, gw00;
_glm_perlinDetail_xy2g(ixy00, gx00, gy00, gz00, gw00); _glm_noiseDetail_xy2g(ixy00, gx00, gy00, gz00, gw00);
vec4 gx01, gy01, gz01, gw01; vec4 gx01, gy01, gz01, gw01;
_glm_perlinDetail_xy2g(ixy01, gx01, gy01, gz01, gw01); _glm_noiseDetail_xy2g(ixy01, gx01, gy01, gz01, gw01);
vec4 gx10, gy10, gz10, gw10; vec4 gx10, gy10, gz10, gw10;
_glm_perlinDetail_xy2g(ixy10, gx10, gy10, gz10, gw10); _glm_noiseDetail_xy2g(ixy10, gx10, gy10, gz10, gw10);
vec4 gx11, gy11, gz11, gw11; vec4 gx11, gy11, gz11, gw11;
_glm_perlinDetail_xy2g(ixy11, gx11, gy11, gz11, gw11); _glm_noiseDetail_xy2g(ixy11, gx11, gy11, gz11, gw11);
// ------------ // ------------
@@ -357,10 +357,10 @@ glm_perlin(vec4 point) {
vec4 g1011 = {gx11[1], gy11[1], gz11[1], gw11[1]}; // g1011 = vec4(gx11.y, gy11.y, gz11.y, gw11.y); vec4 g1011 = {gx11[1], gy11[1], gz11[1], gw11[1]}; // g1011 = vec4(gx11.y, gy11.y, gz11.y, gw11.y);
vec4 g1111 = {gx11[3], gy11[3], gz11[3], gw11[3]}; // g1111 = vec4(gx11.w, gy11.w, gz11.w, gw11.w); vec4 g1111 = {gx11[3], gy11[3], gz11[3], gw11[3]}; // g1111 = vec4(gx11.w, gy11.w, gz11.w, gw11.w);
_glm_perlinDetail_gradNorm(g0000, g0100, g1000, g1100); _glm_noiseDetail_gradNorm(g0000, g0100, g1000, g1100);
_glm_perlinDetail_gradNorm(g0001, g0101, g1001, g1101); _glm_noiseDetail_gradNorm(g0001, g0101, g1001, g1101);
_glm_perlinDetail_gradNorm(g0010, g0110, g1010, g1110); _glm_noiseDetail_gradNorm(g0010, g0110, g1010, g1110);
_glm_perlinDetail_gradNorm(g0011, g0111, g1011, g1111); _glm_noiseDetail_gradNorm(g0011, g0111, g1011, g1111);
// ------------ // ------------
@@ -427,7 +427,7 @@ glm_perlin(vec4 point) {
// ------------ // ------------
vec4 fade_xyzw; vec4 fade_xyzw;
_glm_perlinDetail_fade(Pf0, fade_xyzw); // fade_xyzw = fade(Pf0) _glm_noiseDetail_fade(Pf0, fade_xyzw); // fade_xyzw = fade(Pf0)
// n_0w = lerp(vec4(n0000, n1000, n0100, n1100), vec4(n0001, n1001, n0101, n1101), fade_xyzw.w) // n_0w = lerp(vec4(n0000, n1000, n0100, n1100), vec4(n0001, n1001, n0101, n1101), fade_xyzw.w)
vec4 n_0w1 = {n0000, n1000, n0100, n1100}; vec4 n_0w1 = {n0000, n1000, n0100, n1100};
@@ -458,4 +458,4 @@ glm_perlin(vec4 point) {
} }
#endif /* cglm_perlin_h */ #endif /* cglm_noise_h */

View File

@@ -31,7 +31,7 @@ extern "C" {
#include "struct/affine.h" #include "struct/affine.h"
#include "struct/frustum.h" #include "struct/frustum.h"
#include "struct/plane.h" #include "struct/plane.h"
#include "struct/perlin.h" #include "struct/noise.h"
#include "struct/box.h" #include "struct/box.h"
#include "struct/color.h" #include "struct/color.h"
#include "struct/io.h" #include "struct/io.h"

View File

@@ -5,17 +5,17 @@
* Full license can be found in the LICENSE file * Full license can be found in the LICENSE file
*/ */
#ifndef cglms_perlins_h #ifndef cglms_noises_h
#define cglms_perlins_h #define cglms_noises_h
#include "../common.h" #include "../common.h"
#include "../types-struct.h" #include "../types-struct.h"
#include "../perlin.h" #include "../noise.h"
#include "vec4.h" #include "vec4.h"
/* /*
Functions: Functions:
CGLM_INLINE float glms_perlin(vec4s point); CGLM_INLINE float glms_perlin_vec4(vec4s point);
*/ */
/*! /*!
@@ -26,8 +26,8 @@
*/ */
CGLM_INLINE CGLM_INLINE
float float
glms_perlin(vec4s point) { glms_perlin_vec4(vec4s point) {
return glm_perlin(point.raw); return glm_perlin_vec4(point.raw);
} }
#endif /* cglms_perlins_h */ #endif /* cglms_noises_h */

View File

@@ -56,7 +56,7 @@ cglm_src = files(
'src/mat4x2.c', 'src/mat4x2.c',
'src/mat4x3.c', 'src/mat4x3.c',
'src/plane.c', 'src/plane.c',
'src/perlin.c', 'src/noise.c',
'src/frustum.c', 'src/frustum.c',
'src/box.c', 'src/box.c',
'src/project.c', 'src/project.c',

View File

@@ -10,6 +10,6 @@
CGLM_EXPORT CGLM_EXPORT
float float
glmc_perlin(vec4 p) { glmc_perlin_vec4(vec4 p) {
return glm_perlin(p); return glm_perlin_vec4(p);
} }

View File

@@ -7,7 +7,7 @@
#include "test_common.h" #include "test_common.h"
TEST_IMPL(GLM_PREFIX, perlin) { TEST_IMPL(GLM_PREFIX, perlin_vec4) {
vec4 p1[] = { vec4 p1[] = {
{0.1f, 0.2f, 0.3f, 0.4f}, {0.1f, 0.2f, 0.3f, 0.4f},
{0.2f, 0.3f, 0.4f, 0.5f}, {0.2f, 0.3f, 0.4f, 0.5f},
@@ -36,7 +36,7 @@ TEST_IMPL(GLM_PREFIX, perlin) {
}; };
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
ASSERT(test_eq(GLM(perlin)(p1[i]), e[i])); ASSERT(test_eq(GLM(perlin_vec4)(p1[i]), e[i]));
} }
TEST_SUCCESS TEST_SUCCESS

View File

@@ -30,7 +30,7 @@
#include "test_quat.h" #include "test_quat.h"
#include "test_project.h" #include "test_project.h"
#include "test_plane.h" #include "test_plane.h"
#include "test_perlin.h" #include "test_noise.h"
#include "test_affine.h" #include "test_affine.h"
#include "test_affine2d.h" #include "test_affine2d.h"
#include "test_affine_mat.h" #include "test_affine_mat.h"
@@ -70,7 +70,7 @@
#include "test_quat.h" #include "test_quat.h"
#include "test_project.h" #include "test_project.h"
#include "test_plane.h" #include "test_plane.h"
#include "test_perlin.h" #include "test_noise.h"
#include "test_affine.h" #include "test_affine.h"
#include "test_affine2d.h" #include "test_affine2d.h"
#include "test_affine_mat.h" #include "test_affine_mat.h"

View File

@@ -356,9 +356,9 @@ TEST_DECLARE(glmc_project)
TEST_DECLARE(glm_plane_normalize) TEST_DECLARE(glm_plane_normalize)
TEST_DECLARE(glmc_plane_normalize) TEST_DECLARE(glmc_plane_normalize)
/* perlin */ /* noise */
TEST_DECLARE(glm_perlin) TEST_DECLARE(glm_perlin_vec4)
TEST_DECLARE(glmc_perlin) TEST_DECLARE(glmc_perlin_vec4)
/* utils */ /* utils */
TEST_DECLARE(clamp) TEST_DECLARE(clamp)
@@ -1538,9 +1538,9 @@ TEST_LIST {
TEST_ENTRY(glm_plane_normalize) TEST_ENTRY(glm_plane_normalize)
TEST_ENTRY(glmc_plane_normalize) TEST_ENTRY(glmc_plane_normalize)
/* perlin */ /* noise */
TEST_ENTRY(glm_perlin) TEST_ENTRY(glm_perlin_vec4)
TEST_ENTRY(glmc_perlin) TEST_ENTRY(glmc_perlin_vec4)
/* utils */ /* utils */
TEST_ENTRY(clamp) TEST_ENTRY(clamp)