MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / noiseX

Method noiseX

Source/Utils/SimplexNoise.cpp:176–203  ·  view source on GitHub ↗

* 1D Perlin simplex noise * * Takes around 74ns on an AMD APU. * * @param[in] x float coordinate * * @return Noise value in the range[-1; 1], value of 0 on all integer coordinates. */

Source from the content-addressed store, hash-verified

174 * @return Noise value in the range[-1; 1], value of 0 on all integer coordinates.
175 */
176float SimplexNoise::noiseX(float x) {
177 float n0, n1; // Noise contributions from the two "corners"
178
179 // No need to skew the input space in 1D
180
181 // Corners coordinates (nearest integer values):
182 int32_t i0 = fastfloor(x);
183 int32_t i1 = i0 + 1;
184 // Distances to corners (between 0 and 1):
185 float x0 = x - i0;
186 float x1 = x0 - 1.0f;
187
188 // Calculate the contribution from the first corner
189 float t0 = 1.0f - x0*x0;
190// if(t0 < 0.0f) t0 = 0.0f; // not possible
191 t0 *= t0;
192 n0 = t0 * t0 * grad(hash(i0), x0);
193
194 // Calculate the contribution from the second corner
195 float t1 = 1.0f - x1*x1;
196// if(t1 < 0.0f) t1 = 0.0f; // not possible
197 t1 *= t1;
198 n1 = t1 * t1 * grad(hash(i1), x1);
199
200 // The maximum value of this noise is 8*(3/4)^4 = 2.53125
201 // A factor of 0.395 scales to fit exactly within [-1,1]
202 return 0.395f * (n0 + n1);
203}
204
205/**
206 * 2D Perlin simplex noise

Callers

nothing calls this directly

Calls 3

fastfloorFunction · 0.85
gradFunction · 0.85
hashFunction · 0.70

Tested by

no test coverage detected