Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
illuna-minetest
Commits
77dbad72
Commit
77dbad72
authored
12 years ago
by
kwolekr
Browse files
Options
Downloads
Patches
Plain Diff
Fix and improve noise map functions
parent
75fe948b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/noise.cpp
+30
-35
30 additions, 35 deletions
src/noise.cpp
with
30 additions
and
35 deletions
src/noise.cpp
+
30
−
35
View file @
77dbad72
...
...
@@ -367,6 +367,7 @@ void Noise::resizeNoiseBuf(bool is3d) {
* values from the previous noise lattice as midpoints in the new lattice for the
* next octave.
*/
#define idx(x, y) ((y) * nlx + (x))
void
Noise
::
gradientMap2D
(
float
x
,
float
y
,
float
step_x
,
float
step_y
,
int
seed
)
{
float
v00
,
v01
,
v10
,
v11
,
u
,
v
,
orig_u
;
int
index
,
i
,
j
,
x0
,
y0
,
noisex
,
noisey
;
...
...
@@ -387,25 +388,26 @@ void Noise::gradientMap2D(float x, float y, float step_x, float step_y, int seed
noisebuf
[
index
++
]
=
noise2d
(
x0
+
i
,
y0
+
j
,
seed
);
//calculate interpolations
index
=
0
;
noisey
=
0
;
for
(
j
=
0
;
j
!=
sy
;
j
++
)
{
v00
=
noisebuf
[
noisey
*
nlx
];
v10
=
noisebuf
[
noisey
*
nlx
+
1
];
v01
=
noisebuf
[
(
noisey
+
1
)
*
nlx
];
v11
=
noisebuf
[
(
noisey
+
1
)
*
nlx
+
1
];
v00
=
noisebuf
[
idx
(
0
,
noisey
)
];
v10
=
noisebuf
[
idx
(
1
,
noisey
)
];
v01
=
noisebuf
[
idx
(
0
,
noisey
+
1
)];
v11
=
noisebuf
[
idx
(
1
,
noisey
+
1
)];
u
=
orig_u
;
noisex
=
0
;
for
(
i
=
0
;
i
!=
sx
;
i
++
)
{
buf
[
j
*
sx
+
i
]
=
biLinearInterpolation
(
v00
,
v10
,
v01
,
v11
,
u
,
v
);
buf
[
index
++
]
=
biLinearInterpolation
(
v00
,
v10
,
v01
,
v11
,
u
,
v
);
u
+=
step_x
;
if
(
u
>=
1.0
)
{
u
-=
1.0
;
noisex
++
;
v00
=
v10
;
v01
=
v11
;
v10
=
noisebuf
[
noise
y
*
nl
x
+
noise
x
+
1
];
v11
=
noisebuf
[(
noise
y
+
1
)
*
nlx
+
noise
x
+
1
];
v10
=
noisebuf
[
idx
(
noisex
+
1
,
noise
y
)
];
v11
=
noisebuf
[
idx
(
noise
x
+
1
,
noise
y
+
1
)
];
}
}
...
...
@@ -416,14 +418,16 @@ void Noise::gradientMap2D(float x, float y, float step_x, float step_y, int seed
}
}
}
#undef idx
#define idx(x, y, z) ((z) * nly * nlx + (y) * nlx + (x))
void
Noise
::
gradientMap3D
(
float
x
,
float
y
,
float
z
,
float
step_x
,
float
step_y
,
float
step_z
,
int
seed
)
{
float
v000
,
v010
,
v100
,
v110
;
float
v001
,
v011
,
v101
,
v111
;
float
u
,
v
,
w
,
orig_u
,
orig_
w
;
float
u
,
v
,
w
,
orig_u
,
orig_
v
;
int
index
,
i
,
j
,
k
,
x0
,
y0
,
z0
,
noisex
,
noisey
,
noisez
;
int
nlx
,
nly
,
nlz
;
...
...
@@ -434,49 +438,39 @@ void Noise::gradientMap3D(float x, float y, float z,
v
=
y
-
(
float
)
y0
;
w
=
z
-
(
float
)
z0
;
orig_u
=
u
;
orig_
w
=
w
;
orig_
v
=
v
;
//calculate noise point lattice
nlx
=
(
int
)(
u
+
sx
*
step_x
)
+
2
;
nly
=
(
int
)(
v
+
sy
*
step_y
)
+
2
;
nlz
=
(
int
)(
v
+
s
y
*
step_z
)
+
2
;
nlz
=
(
int
)(
w
+
s
z
*
step_z
)
+
2
;
index
=
0
;
for
(
k
=
0
;
k
!=
nlz
;
k
++
)
for
(
j
=
0
;
j
!=
nly
;
j
++
)
for
(
i
=
0
;
i
!=
nlx
;
i
++
)
noisebuf
[
index
++
]
=
noise3d
(
x0
+
i
,
y0
+
j
,
z0
+
k
,
seed
);
#define index(x, y, z) ((z) * nly * nlx + (y) * nlx + (x))
//calculate interpolations
index
=
0
;
noisey
=
0
;
noisez
=
0
;
for
(
k
=
0
;
k
!=
sz
;
k
++
)
{
v000
=
noisebuf
[
index
(
0
,
noisey
,
noisez
)];
v100
=
noisebuf
[
index
(
1
,
noisey
,
noisez
)];
v010
=
noisebuf
[
index
(
0
,
noisey
+
1
,
noisez
)];
v110
=
noisebuf
[
index
(
1
,
noisey
+
1
,
noisez
)];
v001
=
noisebuf
[
index
(
0
,
noisey
,
noisez
+
1
)];
v101
=
noisebuf
[
index
(
1
,
noisey
,
noisez
+
1
)];
v011
=
noisebuf
[
index
(
0
,
noisey
+
1
,
noisez
+
1
)];
v111
=
noisebuf
[
index
(
1
,
noisey
+
1
,
noisez
+
1
)];
w
=
orig_w
;
v
=
orig_v
;
noisey
=
0
;
for
(
j
=
0
;
j
!=
sy
;
j
++
)
{
v000
=
noisebuf
[
i
nde
x
(
0
,
noisey
,
noisez
)];
v100
=
noisebuf
[
i
nde
x
(
1
,
noisey
,
noisez
)];
v010
=
noisebuf
[
i
nde
x
(
0
,
noisey
+
1
,
noisez
)];
v110
=
noisebuf
[
i
nde
x
(
1
,
noisey
+
1
,
noisez
)];
v001
=
noisebuf
[
i
nde
x
(
0
,
noisey
,
noisez
+
1
)];
v101
=
noisebuf
[
i
nde
x
(
1
,
noisey
,
noisez
+
1
)];
v011
=
noisebuf
[
i
nde
x
(
0
,
noisey
+
1
,
noisez
+
1
)];
v111
=
noisebuf
[
i
nde
x
(
1
,
noisey
+
1
,
noisez
+
1
)];
v000
=
noisebuf
[
i
d
x
(
0
,
noisey
,
noisez
)];
v100
=
noisebuf
[
i
d
x
(
1
,
noisey
,
noisez
)];
v010
=
noisebuf
[
i
d
x
(
0
,
noisey
+
1
,
noisez
)];
v110
=
noisebuf
[
i
d
x
(
1
,
noisey
+
1
,
noisez
)];
v001
=
noisebuf
[
i
d
x
(
0
,
noisey
,
noisez
+
1
)];
v101
=
noisebuf
[
i
d
x
(
1
,
noisey
,
noisez
+
1
)];
v011
=
noisebuf
[
i
d
x
(
0
,
noisey
+
1
,
noisez
+
1
)];
v111
=
noisebuf
[
i
d
x
(
1
,
noisey
+
1
,
noisez
+
1
)];
u
=
orig_u
;
noisex
=
0
;
for
(
i
=
0
;
i
!=
sx
;
i
++
)
{
buf
[
j
*
sx
+
i
]
=
triLinearInterpolation
(
buf
[
index
++
]
=
triLinearInterpolation
(
v000
,
v100
,
v010
,
v110
,
v001
,
v101
,
v011
,
v111
,
u
,
v
,
w
);
...
...
@@ -486,12 +480,12 @@ void Noise::gradientMap3D(float x, float y, float z,
noisex
++
;
v000
=
v100
;
v010
=
v110
;
v100
=
noisebuf
[
i
nde
x
(
noisex
+
1
,
noisey
,
noisez
)];
v110
=
noisebuf
[
i
nde
x
(
noisex
+
1
,
noisey
+
1
,
noisez
)];
v100
=
noisebuf
[
i
d
x
(
noisex
+
1
,
noisey
,
noisez
)];
v110
=
noisebuf
[
i
d
x
(
noisex
+
1
,
noisey
+
1
,
noisez
)];
v001
=
v101
;
v011
=
v111
;
v101
=
noisebuf
[
i
nde
x
(
noisex
+
1
,
noisey
,
noisez
+
1
)];
v111
=
noisebuf
[
i
nde
x
(
noisex
+
1
,
noisey
+
1
,
noisez
+
1
)];
v101
=
noisebuf
[
i
d
x
(
noisex
+
1
,
noisey
,
noisez
+
1
)];
v111
=
noisebuf
[
i
d
x
(
noisex
+
1
,
noisey
+
1
,
noisez
+
1
)];
}
}
...
...
@@ -509,6 +503,7 @@ void Noise::gradientMap3D(float x, float y, float z,
}
}
}
#undef idx
float
*
Noise
::
perlinMap2D
(
float
x
,
float
y
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment