34 return (
x << k) | (
x >> (32 - k));
80 a =
b = c = 0xdeadbeef + (1 << 2) + 13;
88uint32_t
hash(uint32_t kx, uint32_t ky)
91 a =
b = c = 0xdeadbeef + (2 << 2) + 13;
100uint32_t
hash(uint32_t kx, uint32_t ky, uint32_t kz)
103 a =
b = c = 0xdeadbeef + (3 << 2) + 13;
113uint32_t
hash(uint32_t kx, uint32_t ky, uint32_t kz, uint32_t kw)
116 a =
b = c = 0xdeadbeef + (4 << 2) + 13;
168 return float(k) / float(0xFFFFFFFFu);
279template<
typename T>
T static mix(
T v0,
T v1,
float x)
281 return (1 -
x) * v0 +
x * v1;
297 return (1.0 -
y) * (v0 * x1 + v1 *
x) +
y * (
v2 * x1 + v3 *
x);
333 return z1 * (y1 * (v0 * x1 + v1 *
x) +
y * (
v2 * x1 + v3 *
x)) +
334 z * (y1 * (v4 * x1 + v5 *
x) +
y * (v6 * x1 + v7 *
x));
359 return mix(
mix(v0, v1,
v2, v3, v4, v5, v6, v7,
x,
y,
z),
360 mix(v8, v9, v10, v11, v12, v13, v14, v15,
x,
y,
z),
366 return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
371 return (condition != 0u) ? -value : value;
376 uint32_t h =
hash & 15u;
377 float g = 1u + (h & 7u);
383 uint32_t h =
hash & 7u;
384 float u = h < 4u ?
x :
y;
385 float v = 2.0 * (h < 4u ?
y :
x);
391 uint32_t h =
hash & 15u;
392 float u = h < 8u ?
x :
y;
393 float vt =
ELEM(h, 12u, 14u) ?
x :
z;
394 float v = h < 4u ?
y : vt;
400 uint32_t h =
hash & 31u;
401 float u = h < 24u ?
x :
y;
402 float v = h < 16u ?
y :
z;
403 float s = h < 8u ?
z :
w;
518 float precision_correction = 0.5f * float(
math::abs(position) >= 1000000.0f);
521 position =
math::mod(position, 100000.0f) + precision_correction;
529 float(
math::abs(position.y) >= 1000000.0f));
533 position =
math::mod(position, 100000.0f) + precision_correction;
541 float(
math::abs(position.y) >= 1000000.0f),
542 float(
math::abs(position.z) >= 1000000.0f));
546 position =
math::mod(position, 100000.0f) + precision_correction;
554 float(
math::abs(position.y) >= 1000000.0f),
555 float(
math::abs(position.z) >= 1000000.0f),
556 float(
math::abs(position.w) >= 1000000.0f));
560 position =
math::mod(position, 100000.0f) + precision_correction;
591#if defined(_MSC_VER) && _MSC_VER >= 1930
600 const float roughness,
601 const float lacunarity,
614 fscale *= lacunarity;
619 float sum2 =
sum + t * amp;
620 return normalize ?
mix(0.5f *
sum / maxamp + 0.5f, 0.5f * sum2 / (maxamp + amp) + 0.5f, rmd) :
629 const float roughness,
630 const float lacunarity,
635 const float roughness,
636 const float lacunarity,
661 T p,
const float detail,
const float roughness,
const float lacunarity,
const float offset)
663 float pwr = roughness;
679 value += rmd * increment;
688 const float roughness,
689 const float lacunarity,
697 for (
int i = 0; (weight > 0.001f) && (
i <= int(
detail));
i++) {
698 weight = std::min(weight, 1.0f);
702 value += weight * signal;
703 weight *= gain * signal;
708 if ((rmd != 0.0f) && (weight > 0.001f)) {
709 weight = std::min(weight, 1.0f);
711 value += rmd * weight * signal;
720 const float roughness,
721 const float lacunarity,
725 float pwr = roughness;
729 float value = signal;
734 weight = std::clamp(signal * gain, 0.0f, 1.0f);
738 value += signal * pwr;
946 position,
detail, roughness, lacunarity, offset, gain, type,
normalize),
977 position,
detail, roughness, lacunarity, offset, gain, type,
normalize),
1008 position,
detail, roughness, lacunarity, offset, gain, type,
normalize),
1070 return std::abs(
b - a);
1079 return std::abs(a.x -
b.x) + std::abs(a.y -
b.y);
1081 return std::max(std::abs(a.x -
b.x), std::abs(a.y -
b.y));
1083 return std::pow(std::pow(std::abs(a.x -
b.x),
params.exponent) +
1084 std::pow(std::abs(a.y -
b.y),
params.exponent),
1099 return std::abs(a.x -
b.x) + std::abs(a.y -
b.y) + std::abs(a.z -
b.z);
1101 return std::max({std::abs(a.x -
b.x), std::abs(a.y -
b.y), std::abs(a.z -
b.z)});
1103 return std::pow(std::pow(std::abs(a.x -
b.x),
params.exponent) +
1104 std::pow(std::abs(a.y -
b.y),
params.exponent) +
1105 std::pow(std::abs(a.z -
b.z),
params.exponent),
1120 return std::abs(a.x -
b.x) + std::abs(a.y -
b.y) + std::abs(a.z -
b.z) + std::abs(a.w -
b.w);
1123 {std::abs(a.x -
b.x), std::abs(a.y -
b.y), std::abs(a.z -
b.z), std::abs(a.w -
b.w)});
1125 return std::pow(std::pow(std::abs(a.x -
b.x),
params.exponent) +
1126 std::pow(std::abs(a.y -
b.y),
params.exponent) +
1127 std::pow(std::abs(a.z -
b.z),
params.exponent) +
1128 std::pow(std::abs(a.w -
b.w),
params.exponent),
1152 return {0.0f, 0.0f, 0.0f, coord};
1157 float cellPosition =
floorf(coord);
1158 float localPosition = coord - cellPosition;
1161 float targetOffset = 0.0f;
1162 float targetPosition = 0.0f;
1163 for (
int i = -1;
i <= 1;
i++) {
1164 float cellOffset =
i;
1165 float pointPosition = cellOffset +
1168 if (distanceToPoint < minDistance) {
1169 targetOffset = cellOffset;
1170 minDistance = distanceToPoint;
1171 targetPosition = pointPosition;
1184 const bool calc_color)
1186 float cellPosition =
floorf(coord);
1187 float localPosition = coord - cellPosition;
1189 float smoothDistance = 0.0f;
1190 float smoothPosition = 0.0f;
1191 float3 smoothColor = {0.0f, 0.0f, 0.0f};
1193 for (
int i = -2;
i <= 2;
i++) {
1194 float cellOffset =
i;
1195 float pointPosition = cellOffset +
1201 0.0f, 1.0f, 0.5f + 0.5f * (smoothDistance - distanceToPoint) /
params.smoothness);
1202 float correctionFactor =
params.smoothness * h * (1.0f - h);
1203 smoothDistance =
mix(smoothDistance, distanceToPoint, h) - correctionFactor;
1204 correctionFactor /= 1.0f + 3.0f *
params.smoothness;
1208 smoothColor =
mix(smoothColor, cellColor, h) - correctionFactor;
1210 smoothPosition =
mix(smoothPosition, pointPosition, h) - correctionFactor;
1215 octave.
color = smoothColor;
1222 float cellPosition =
floorf(coord);
1223 float localPosition = coord - cellPosition;
1227 float offsetF1 = 0.0f;
1228 float positionF1 = 0.0f;
1229 float offsetF2 = 0.0f;
1230 float positionF2 = 0.0f;
1231 for (
int i = -1;
i <= 1;
i++) {
1232 float cellOffset =
i;
1233 float pointPosition = cellOffset +
1236 if (distanceToPoint < distanceF1) {
1237 distanceF2 = distanceF1;
1238 distanceF1 = distanceToPoint;
1239 offsetF2 = offsetF1;
1240 offsetF1 = cellOffset;
1241 positionF2 = positionF1;
1242 positionF1 = pointPosition;
1244 else if (distanceToPoint < distanceF2) {
1245 distanceF2 = distanceToPoint;
1246 offsetF2 = cellOffset;
1247 positionF2 = pointPosition;
1260 float cellPosition =
floorf(coord);
1261 float localPosition = coord - cellPosition;
1266 float distanceToMidLeft =
fabsf((midPointPosition + leftPointPosition) / 2.0f - localPosition);
1267 float distanceToMidRight =
fabsf((midPointPosition + rightPointPosition) / 2.0f - localPosition);
1269 return math::min(distanceToMidLeft, distanceToMidRight);
1274 float cellPosition =
floorf(coord);
1275 float localPosition = coord - cellPosition;
1277 float closestPoint = 0.0f;
1278 float closestPointOffset = 0.0f;
1280 for (
int i = -1;
i <= 1;
i++) {
1281 float cellOffset =
i;
1282 float pointPosition = cellOffset +
1284 float distanceToPoint =
fabsf(pointPosition - localPosition);
1285 if (distanceToPoint < minDistance) {
1286 minDistance = distanceToPoint;
1287 closestPoint = pointPosition;
1288 closestPointOffset = cellOffset;
1293 float closestPointToClosestPoint = 0.0f;
1294 for (
int i = -1;
i <= 1;
i++) {
1298 float cellOffset =
i + closestPointOffset;
1299 float pointPosition = cellOffset +
1301 float distanceToPoint =
fabsf(closestPoint - pointPosition);
1302 if (distanceToPoint < minDistance) {
1303 minDistance = distanceToPoint;
1304 closestPointToClosestPoint = pointPosition;
1308 return fabsf(closestPointToClosestPoint - closestPoint) / 2.0f;
1315 return {coord.x, coord.y, 0.0f, 0.0f};
1321 float2 localPosition = coord - cellPosition;
1324 float2 targetOffset = {0.0f, 0.0f};
1325 float2 targetPosition = {0.0f, 0.0f};
1326 for (
int j = -1; j <= 1; j++) {
1327 for (
int i = -1;
i <= 1;
i++) {
1329 float2 pointPosition = cellOffset +
1332 if (distanceToPoint < minDistance) {
1333 targetOffset = cellOffset;
1334 minDistance = distanceToPoint;
1335 targetPosition = pointPosition;
1349 const bool calc_color)
1352 float2 localPosition = coord - cellPosition;
1354 float smoothDistance = 0.0f;
1355 float3 smoothColor = {0.0f, 0.0f, 0.0f};
1356 float2 smoothPosition = {0.0f, 0.0f};
1358 for (
int j = -2; j <= 2; j++) {
1359 for (
int i = -2;
i <= 2;
i++) {
1361 float2 pointPosition = cellOffset +
1368 0.5f + 0.5f * (smoothDistance - distanceToPoint) /
params.smoothness);
1369 float correctionFactor =
params.smoothness * h * (1.0f - h);
1370 smoothDistance =
mix(smoothDistance, distanceToPoint, h) - correctionFactor;
1371 correctionFactor /= 1.0f + 3.0f *
params.smoothness;
1375 smoothColor =
mix(smoothColor, cellColor, h) - correctionFactor;
1377 smoothPosition =
mix(smoothPosition, pointPosition, h) - correctionFactor;
1383 octave.
color = smoothColor;
1391 float2 localPosition = coord - cellPosition;
1395 float2 offsetF1 = {0.0f, 0.0f};
1396 float2 positionF1 = {0.0f, 0.0f};
1397 float2 offsetF2 = {0.0f, 0.0f};
1398 float2 positionF2 = {0.0f, 0.0f};
1399 for (
int j = -1; j <= 1; j++) {
1400 for (
int i = -1;
i <= 1;
i++) {
1402 float2 pointPosition = cellOffset +
1405 if (distanceToPoint < distanceF1) {
1406 distanceF2 = distanceF1;
1407 distanceF1 = distanceToPoint;
1408 offsetF2 = offsetF1;
1409 offsetF1 = cellOffset;
1410 positionF2 = positionF1;
1411 positionF1 = pointPosition;
1413 else if (distanceToPoint < distanceF2) {
1414 distanceF2 = distanceToPoint;
1415 offsetF2 = cellOffset;
1416 positionF2 = pointPosition;
1431 float2 localPosition = coord - cellPosition;
1433 float2 vectorToClosest = {0.0f, 0.0f};
1435 for (
int j = -1; j <= 1; j++) {
1436 for (
int i = -1;
i <= 1;
i++) {
1438 float2 vectorToPoint = cellOffset +
1441 float distanceToPoint =
math::dot(vectorToPoint, vectorToPoint);
1442 if (distanceToPoint < minDistance) {
1443 minDistance = distanceToPoint;
1444 vectorToClosest = vectorToPoint;
1450 for (
int j = -1; j <= 1; j++) {
1451 for (
int i = -1;
i <= 1;
i++) {
1453 float2 vectorToPoint = cellOffset +
1456 float2 perpendicularToEdge = vectorToPoint - vectorToClosest;
1457 if (
math::dot(perpendicularToEdge, perpendicularToEdge) > 0.0001f) {
1458 float distanceToEdge =
math::dot((vectorToClosest + vectorToPoint) / 2.0f,
1460 minDistance =
math::min(minDistance, distanceToEdge);
1471 float2 localPosition = coord - cellPosition;
1473 float2 closestPoint = {0.0f, 0.0f};
1474 float2 closestPointOffset = {0.0f, 0.0f};
1475 float minDistanceSq =
FLT_MAX;
1476 for (
int j = -1; j <= 1; j++) {
1477 for (
int i = -1;
i <= 1;
i++) {
1479 float2 pointPosition = cellOffset +
1482 if (distanceToPointSq < minDistanceSq) {
1483 minDistanceSq = distanceToPointSq;
1484 closestPoint = pointPosition;
1485 closestPointOffset = cellOffset;
1491 float2 closestPointToClosestPoint = {0.0f, 0.0f};
1492 for (
int j = -1; j <= 1; j++) {
1493 for (
int i = -1;
i <= 1;
i++) {
1494 if (
i == 0 && j == 0) {
1498 float2 pointPosition = cellOffset +
1501 if (distanceToPointSq < minDistanceSq) {
1502 minDistanceSq = distanceToPointSq;
1503 closestPointToClosestPoint = pointPosition;
1508 return math::distance(closestPointToClosestPoint, closestPoint) / 2.0f;
1515 return {coord.x, coord.y, coord.z, 0.0f};
1521 float3 localPosition = coord - cellPosition;
1524 float3 targetOffset = {0.0f, 0.0f, 0.0f};
1525 float3 targetPosition = {0.0f, 0.0f, 0.0f};
1526 for (
int k = -1; k <= 1; k++) {
1527 for (
int j = -1; j <= 1; j++) {
1528 for (
int i = -1;
i <= 1;
i++) {
1530 float3 pointPosition = cellOffset +
1533 if (distanceToPoint < minDistance) {
1534 targetOffset = cellOffset;
1535 minDistance = distanceToPoint;
1536 targetPosition = pointPosition;
1551 const bool calc_color)
1554 float3 localPosition = coord - cellPosition;
1556 float smoothDistance = 0.0f;
1557 float3 smoothColor = {0.0f, 0.0f, 0.0f};
1558 float3 smoothPosition = {0.0f, 0.0f, 0.0f};
1560 for (
int k = -2; k <= 2; k++) {
1561 for (
int j = -2; j <= 2; j++) {
1562 for (
int i = -2;
i <= 2;
i++) {
1564 float3 pointPosition = cellOffset +
1571 0.5f + 0.5f * (smoothDistance - distanceToPoint) /
params.smoothness);
1572 float correctionFactor =
params.smoothness * h * (1.0f - h);
1573 smoothDistance =
mix(smoothDistance, distanceToPoint, h) - correctionFactor;
1574 correctionFactor /= 1.0f + 3.0f *
params.smoothness;
1578 smoothColor =
mix(smoothColor, cellColor, h) - correctionFactor;
1580 smoothPosition =
mix(smoothPosition, pointPosition, h) - correctionFactor;
1587 octave.
color = smoothColor;
1595 float3 localPosition = coord - cellPosition;
1599 float3 offsetF1 = {0.0f, 0.0f, 0.0f};
1600 float3 positionF1 = {0.0f, 0.0f, 0.0f};
1601 float3 offsetF2 = {0.0f, 0.0f, 0.0f};
1602 float3 positionF2 = {0.0f, 0.0f, 0.0f};
1603 for (
int k = -1; k <= 1; k++) {
1604 for (
int j = -1; j <= 1; j++) {
1605 for (
int i = -1;
i <= 1;
i++) {
1607 float3 pointPosition = cellOffset +
1610 if (distanceToPoint < distanceF1) {
1611 distanceF2 = distanceF1;
1612 distanceF1 = distanceToPoint;
1613 offsetF2 = offsetF1;
1614 offsetF1 = cellOffset;
1615 positionF2 = positionF1;
1616 positionF1 = pointPosition;
1618 else if (distanceToPoint < distanceF2) {
1619 distanceF2 = distanceToPoint;
1620 offsetF2 = cellOffset;
1621 positionF2 = pointPosition;
1637 float3 localPosition = coord - cellPosition;
1639 float3 vectorToClosest = {0.0f, 0.0f, 0.0f};
1641 for (
int k = -1; k <= 1; k++) {
1642 for (
int j = -1; j <= 1; j++) {
1643 for (
int i = -1;
i <= 1;
i++) {
1645 float3 vectorToPoint = cellOffset +
1649 float distanceToPoint =
math::dot(vectorToPoint, vectorToPoint);
1650 if (distanceToPoint < minDistance) {
1651 minDistance = distanceToPoint;
1652 vectorToClosest = vectorToPoint;
1659 for (
int k = -1; k <= 1; k++) {
1660 for (
int j = -1; j <= 1; j++) {
1661 for (
int i = -1;
i <= 1;
i++) {
1663 float3 vectorToPoint = cellOffset +
1667 float3 perpendicularToEdge = vectorToPoint - vectorToClosest;
1668 if (
math::dot(perpendicularToEdge, perpendicularToEdge) > 0.0001f) {
1669 float distanceToEdge =
math::dot((vectorToClosest + vectorToPoint) / 2.0f,
1671 minDistance =
math::min(minDistance, distanceToEdge);
1683 float3 localPosition = coord - cellPosition;
1685 float3 closestPoint = {0.0f, 0.0f, 0.0f};
1686 float3 closestPointOffset = {0.0f, 0.0f, 0.0f};
1687 float minDistanceSq =
FLT_MAX;
1688 for (
int k = -1; k <= 1; k++) {
1689 for (
int j = -1; j <= 1; j++) {
1690 for (
int i = -1;
i <= 1;
i++) {
1692 float3 pointPosition = cellOffset +
1695 if (distanceToPointSq < minDistanceSq) {
1696 minDistanceSq = distanceToPointSq;
1697 closestPoint = pointPosition;
1698 closestPointOffset = cellOffset;
1705 float3 closestPointToClosestPoint = {0.0f, 0.0f, 0.0f};
1706 for (
int k = -1; k <= 1; k++) {
1707 for (
int j = -1; j <= 1; j++) {
1708 for (
int i = -1;
i <= 1;
i++) {
1709 if (
i == 0 && j == 0 && k == 0) {
1713 float3 pointPosition = cellOffset +
1716 if (distanceToPointSq < minDistanceSq) {
1717 minDistanceSq = distanceToPointSq;
1718 closestPointToClosestPoint = pointPosition;
1724 return math::distance(closestPointToClosestPoint, closestPoint) / 2.0f;
1737 float4 localPosition = coord - cellPosition;
1740 float4 targetOffset = {0.0f, 0.0f, 0.0f, 0.0f};
1741 float4 targetPosition = {0.0f, 0.0f, 0.0f, 0.0f};
1742 for (
int u = -1; u <= 1; u++) {
1743 for (
int k = -1; k <= 1; k++) {
1744 for (
int j = -1; j <= 1; j++) {
1745 for (
int i = -1;
i <= 1;
i++) {
1746 float4 cellOffset(
i, j, k, u);
1750 if (distanceToPoint < minDistance) {
1751 targetOffset = cellOffset;
1752 minDistance = distanceToPoint;
1753 targetPosition = pointPosition;
1769 const bool calc_color)
1772 float4 localPosition = coord - cellPosition;
1774 float smoothDistance = 0.0f;
1775 float3 smoothColor = {0.0f, 0.0f, 0.0f};
1776 float4 smoothPosition = {0.0f, 0.0f, 0.0f, 0.0f};
1778 for (
int u = -2; u <= 2; u++) {
1779 for (
int k = -2; k <= 2; k++) {
1780 for (
int j = -2; j <= 2; j++) {
1781 for (
int i = -2;
i <= 2;
i++) {
1782 float4 cellOffset(
i, j, k, u);
1790 0.5f + 0.5f * (smoothDistance - distanceToPoint) /
params.smoothness);
1791 float correctionFactor =
params.smoothness * h * (1.0f - h);
1792 smoothDistance =
mix(smoothDistance, distanceToPoint, h) - correctionFactor;
1793 correctionFactor /= 1.0f + 3.0f *
params.smoothness;
1797 smoothColor =
mix(smoothColor, cellColor, h) - correctionFactor;
1799 smoothPosition =
mix(smoothPosition, pointPosition, h) - correctionFactor;
1807 octave.
color = smoothColor;
1815 float4 localPosition = coord - cellPosition;
1819 float4 offsetF1 = {0.0f, 0.0f, 0.0f, 0.0f};
1820 float4 positionF1 = {0.0f, 0.0f, 0.0f, 0.0f};
1821 float4 offsetF2 = {0.0f, 0.0f, 0.0f, 0.0f};
1822 float4 positionF2 = {0.0f, 0.0f, 0.0f, 0.0f};
1823 for (
int u = -1; u <= 1; u++) {
1824 for (
int k = -1; k <= 1; k++) {
1825 for (
int j = -1; j <= 1; j++) {
1826 for (
int i = -1;
i <= 1;
i++) {
1827 float4 cellOffset(
i, j, k, u);
1831 if (distanceToPoint < distanceF1) {
1832 distanceF2 = distanceF1;
1833 distanceF1 = distanceToPoint;
1834 offsetF2 = offsetF1;
1835 offsetF1 = cellOffset;
1836 positionF2 = positionF1;
1837 positionF1 = pointPosition;
1839 else if (distanceToPoint < distanceF2) {
1840 distanceF2 = distanceToPoint;
1841 offsetF2 = cellOffset;
1842 positionF2 = pointPosition;
1859 float4 localPosition = coord - cellPosition;
1861 float4 vectorToClosest = {0.0f, 0.0f, 0.0f, 0.0f};
1863 for (
int u = -1; u <= 1; u++) {
1864 for (
int k = -1; k <= 1; k++) {
1865 for (
int j = -1; j <= 1; j++) {
1866 for (
int i = -1;
i <= 1;
i++) {
1867 float4 cellOffset(
i, j, k, u);
1868 float4 vectorToPoint = cellOffset +
1872 float distanceToPoint =
math::dot(vectorToPoint, vectorToPoint);
1873 if (distanceToPoint < minDistance) {
1874 minDistance = distanceToPoint;
1875 vectorToClosest = vectorToPoint;
1883 for (
int u = -1; u <= 1; u++) {
1884 for (
int k = -1; k <= 1; k++) {
1885 for (
int j = -1; j <= 1; j++) {
1886 for (
int i = -1;
i <= 1;
i++) {
1887 float4 cellOffset(
i, j, k, u);
1888 float4 vectorToPoint = cellOffset +
1892 float4 perpendicularToEdge = vectorToPoint - vectorToClosest;
1893 if (
math::dot(perpendicularToEdge, perpendicularToEdge) > 0.0001f) {
1894 float distanceToEdge =
math::dot((vectorToClosest + vectorToPoint) / 2.0f,
1896 minDistance =
math::min(minDistance, distanceToEdge);
1909 float4 localPosition = coord - cellPosition;
1911 float4 closestPoint = {0.0f, 0.0f, 0.0f, 0.0f};
1912 float4 closestPointOffset = {0.0f, 0.0f, 0.0f, 0.0f};
1913 float minDistanceSq =
FLT_MAX;
1914 for (
int u = -1; u <= 1; u++) {
1915 for (
int k = -1; k <= 1; k++) {
1916 for (
int j = -1; j <= 1; j++) {
1917 for (
int i = -1;
i <= 1;
i++) {
1918 float4 cellOffset(
i, j, k, u);
1922 if (distanceToPointSq < minDistanceSq) {
1923 minDistanceSq = distanceToPointSq;
1924 closestPoint = pointPosition;
1925 closestPointOffset = cellOffset;
1933 float4 closestPointToClosestPoint = {0.0f, 0.0f, 0.0f, 0.0f};
1934 for (
int u = -1; u <= 1; u++) {
1935 for (
int k = -1; k <= 1; k++) {
1936 for (
int j = -1; j <= 1; j++) {
1937 for (
int i = -1;
i <= 1;
i++) {
1938 if (
i == 0 && j == 0 && k == 0 && u == 0) {
1941 float4 cellOffset =
float4(
i, j, k, u) + closestPointOffset;
1945 if (distanceToPointSq < minDistanceSq) {
1946 minDistanceSq = distanceToPointSq;
1947 closestPointToClosestPoint = pointPosition;
1954 return math::distance(closestPointToClosestPoint, closestPoint) / 2.0f;
1964 const bool calc_color )
1966 float amplitude = 1.0f;
1967 float max_amplitude = 0.0f;
1971 const bool zero_input =
params.detail == 0.0f ||
params.roughness == 0.0f;
1977 params.smoothness != 0.0f) ?
1982 max_amplitude = 1.0f;
1987 max_amplitude += amplitude;
1991 scale *=
params.lacunarity;
1992 amplitude *=
params.roughness;
1996 if (remainder != 0.0f) {
1997 max_amplitude =
mix(max_amplitude, max_amplitude + amplitude, remainder);
2008 output.distance /= max_amplitude *
params.max_distance;
2009 output.color /= max_amplitude;
2013 float4{0.0f, 0.0f, 0.0f, 0.0f};
2023 float amplitude = 1.0f;
2024 float max_amplitude =
params.max_distance;
2028 const bool zero_input =
params.detail == 0.0f ||
params.roughness == 0.0f;
2038 max_amplitude =
mix(max_amplitude,
params.max_distance / scale, amplitude);
2040 scale *=
params.lacunarity;
2041 amplitude *=
params.roughness;
2045 if (remainder != 0.0f) {
2046 float lerp_amplitude =
mix(max_amplitude,
params.max_distance / scale, amplitude);
2047 max_amplitude =
mix(max_amplitude, lerp_amplitude, remainder);
2048 float lerp_distance =
mix(
2066 const bool calc_color);
2069 const bool calc_color);
2072 const bool calc_color);
2075 const bool calc_color);
2141 const float frequency,
2142 const float orientation)
2147 const float windowed_gaussian_envelope = gaussian_envelop * hann_window;
2149 const float2 frequency_vector = frequency *
float2(
cos(orientation),
sin(orientation));
2153 return windowed_gaussian_envelope * phasor;
2193 const float integral_of_gabor_squared = 0.25f;
2194 const float second_moment = 0.5f;
2206 const float frequency,
2207 const float isotropy,
2208 const float base_orientation)
2214 const float3 seed_for_orientation(cell.x, cell.y,
i * 3);
2215 const float3 seed_for_kernel_center(cell.x, cell.y,
i * 3 + 1);
2216 const float3 seed_for_weight(cell.x, cell.y,
i * 3 + 2);
2224 const float orientation = base_orientation + random_orientation * isotropy;
2227 const float2 position_in_kernel_space = position - kernel_center;
2247 const float frequency,
2248 const float isotropy,
2249 const float base_orientation)
2252 const float2 local_position = coordinates - cell_position;
2255 for (
int j = -1; j <= 1; j++) {
2256 for (
int i = -1;
i <= 1;
i++) {
2258 const float2 current_cell_position = cell_position + cell_offset;
2259 const float2 position_in_cell_space = local_position - cell_offset;
2261 current_cell_position, position_in_cell_space, frequency, isotropy, base_orientation);
2273 const float frequency,
2274 const float3 orientation)
2279 const float windowed_gaussian_envelope = gaussian_envelop * hann_window;
2281 const float3 frequency_vector = frequency * orientation;
2285 return windowed_gaussian_envelope * phasor;
2294 const float second_moment = 0.5f;
2302 const float isotropy,
2306 if (isotropy == 0.0) {
2311 float inclination =
math::acos(orientation.z);
2320 inclination += random_angles.x * isotropy;
2321 azimuth += random_angles.y * isotropy;
2331 const float frequency,
2332 const float isotropy,
2333 const float3 base_orientation)
2339 const float4 seed_for_orientation(cell.x, cell.y, cell.z,
i * 3);
2340 const float4 seed_for_kernel_center(cell.x, cell.y, cell.z,
i * 3 + 1);
2341 const float4 seed_for_weight(cell.x, cell.y, cell.z,
i * 3 + 2);
2344 base_orientation, isotropy, seed_for_orientation);
2347 const float3 position_in_kernel_space = position - kernel_center;
2366 const float frequency,
2367 const float isotropy,
2368 const float3 base_orientation)
2371 const float3 local_position = coordinates - cell_position;
2374 for (
int k = -1; k <= 1; k++) {
2375 for (
int j = -1; j <= 1; j++) {
2376 for (
int i = -1;
i <= 1;
i++) {
2378 const float3 current_cell_position = cell_position + cell_offset;
2379 const float3 position_in_cell_space = local_position - cell_offset;
2381 current_cell_position, position_in_cell_space, frequency, isotropy, base_orientation);
2391 const float frequency,
2392 const float anisotropy,
2393 const float orientation,
2398 const float2 scaled_coordinates = coordinates * scale;
2399 const float isotropy = 1.0f -
math::clamp(anisotropy, 0.0f, 1.0f);
2400 const float sanitized_frequency =
math::max(0.001f, frequency);
2403 scaled_coordinates, sanitized_frequency, isotropy, orientation);
2408 const float normalization_factor = 6.0f * standard_deviation;
2413 *r_value = (phasor.y / normalization_factor) * 0.5f + 0.5f;
2424 *r_intensity =
math::length(phasor) / normalization_factor;
2430 const float frequency,
2431 const float anisotropy,
2432 const float3 orientation,
2437 const float3 scaled_coordinates = coordinates * scale;
2438 const float isotropy = 1.0f -
math::clamp(anisotropy, 0.0f, 1.0f);
2439 const float sanitized_frequency =
math::max(0.001f, frequency);
2443 scaled_coordinates, sanitized_frequency, isotropy, normalized_orientation);
2448 const float normalization_factor = 6.0f * standard_deviation;
2453 *r_value = (phasor.y / normalization_factor) * 0.5f + 0.5f;
2464 *r_intensity =
math::length(phasor) / normalization_factor;
#define BLI_assert_unreachable()
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
static T sum(const btAlignedObjectArray< T > &items)
static unsigned long seed
VecBase< float, D > normalize(VecOp< float, D >) RET
float distance(VecOp< float, D >, VecOp< float, D >) RET
MINLINE float smoothstep(float edge0, float edge1, float x)
T length_squared(const VecBase< T, Size > &a)
T cos(const AngleRadianBase< T > &a)
T clamp(const T &a, const T &min, const T &max)
T distance(const T &a, const T &b)
T length(const VecBase< T, Size > &a)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
T min(const T &a, const T &b)
T atan2(const T &y, const T &x)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
T sin(const AngleRadianBase< T > &a)
T max(const T &a, const T &b)
T mod(const T &a, const T &b)
template VoronoiOutput fractal_voronoi_x_fx< float4 >(const VoronoiParams ¶ms, const float4 coord, const bool calc_color)
template float fractal_voronoi_distance_to_edge< float >(const VoronoiParams ¶ms, const float coord)
float3 perlin_float3_fractal_distorted(float position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
BLI_INLINE float negate_if(float value, uint32_t condition)
BLI_INLINE float uint_to_float_01(uint32_t k)
float perlin_ridged_multi_fractal(T p, const float detail, const float roughness, const float lacunarity, const float offset, const float gain)
static float2 compute_3d_gabor_noise(const float3 coordinates, const float frequency, const float isotropy, const float3 base_orientation)
@ NOISE_SHD_VORONOI_N_SPHERE_RADIUS
@ NOISE_SHD_VORONOI_SMOOTH_F1
@ NOISE_SHD_VORONOI_DISTANCE_TO_EDGE
uint32_t hash_float(float kx)
static float compute_3d_gabor_standard_deviation()
template float perlin_fbm< float3 >(float3 p, const float detail, const float roughness, const float lacunarity, const bool normalize)
static float2 compute_2d_gabor_noise_cell(const float2 cell, const float2 position, const float frequency, const float isotropy, const float base_orientation)
BLI_INLINE float perlin_distortion(float position, float strength)
float hash_float_to_float(float k)
float perlin_signed(float position)
void gabor(const float2 coordinates, const float scale, const float frequency, const float anisotropy, const float orientation, float *r_value, float *r_phase, float *r_intensity)
template float perlin_fractal_distorted< float >(float position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
BLI_INLINE void hash_bit_mix(uint32_t &a, uint32_t &b, uint32_t &c)
float4 voronoi_position(const float coord)
BLI_INLINE float fade(float t)
VoronoiOutput voronoi_smooth_f1(const VoronoiParams ¶ms, const float coord, const bool calc_color)
float voronoi_n_sphere_radius(const VoronoiParams ¶ms, const float coord)
static float2 compute_2d_gabor_noise(const float2 coordinates, const float frequency, const float isotropy, const float base_orientation)
float perlin(float position)
BLI_INLINE float random_float_offset(float seed)
static float voronoi_distance_bound(const T a, const T b, const VoronoiParams ¶ms)
BLI_INLINE float floor_fraction(float x, int &i)
float voronoi_distance_to_edge(const VoronoiParams ¶ms, const float coord)
BLI_INLINE uint32_t float_as_uint(float f)
template VoronoiOutput fractal_voronoi_x_fx< float3 >(const VoronoiParams ¶ms, const float3 coord, const bool calc_color)
template float perlin_fractal_distorted< float2 >(float2 position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
BLI_INLINE float3 random_float3_offset(float seed)
static float2 compute_3d_gabor_noise_cell(const float3 cell, const float3 position, const float frequency, const float isotropy, const float3 base_orientation)
static float2 compute_2d_gabor_kernel(const float2 position, const float frequency, const float orientation)
VoronoiOutput fractal_voronoi_x_fx(const VoronoiParams ¶ms, const T coord, const bool calc_color)
float voronoi_distance(const float a, const float b)
static float2 compute_3d_gabor_kernel(const float3 position, const float frequency, const float3 orientation)
template float perlin_fractal_distorted< float4 >(float4 position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
@ NOISE_SHD_PERLIN_MULTIFRACTAL
@ NOISE_SHD_PERLIN_RIDGED_MULTIFRACTAL
@ NOISE_SHD_PERLIN_HYBRID_MULTIFRACTAL
@ NOISE_SHD_PERLIN_HETERO_TERRAIN
BLI_INLINE float2 random_float2_offset(float seed)
float perlin_fbm(T p, float detail, float roughness, float lacunarity, bool normalize)
VoronoiOutput voronoi_f2(const VoronoiParams ¶ms, const float coord)
float3 hash_float_to_float3(float k)
uint32_t hash(uint32_t kx)
template VoronoiOutput fractal_voronoi_x_fx< float >(const VoronoiParams ¶ms, const float coord, const bool calc_color)
template float perlin_fbm< float2 >(float2 p, const float detail, const float roughness, const float lacunarity, const bool normalize)
BLI_INLINE float4 random_float4_offset(float seed)
BLI_INLINE float perlin_noise(float position)
float fractal_voronoi_distance_to_edge(const VoronoiParams ¶ms, const T coord)
BLI_INLINE void hash_bit_final(uint32_t &a, uint32_t &b, uint32_t &c)
float4 hash_float_to_float4(float4 k)
float perlin_hybrid_multi_fractal(T p, const float detail, const float roughness, const float lacunarity, const float offset, const float gain)
static float compute_2d_gabor_standard_deviation()
@ NOISE_SHD_VORONOI_MANHATTAN
@ NOISE_SHD_VORONOI_MINKOWSKI
@ NOISE_SHD_VORONOI_EUCLIDEAN
@ NOISE_SHD_VORONOI_CHEBYCHEV
float perlin_select(T p, float detail, float roughness, float lacunarity, float offset, float gain, int type, bool normalize)
BLI_INLINE float noise_grad(uint32_t hash, float x)
VoronoiOutput voronoi_f1(const VoronoiParams ¶ms, const float coord)
float perlin_multi_fractal(T p, const float detail, const float roughness, const float lacunarity)
template float fractal_voronoi_distance_to_edge< float3 >(const VoronoiParams ¶ms, const float3 coord)
static constexpr int gabor_impulses_count
static T mix(T v0, T v1, float x)
float perlin_fractal_distorted(T position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
template float perlin_fractal_distorted< float3 >(float3 position, float detail, float roughness, float lacunarity, float offset, float gain, float distortion, int type, bool normalize)
template VoronoiOutput fractal_voronoi_x_fx< float2 >(const VoronoiParams ¶ms, const float2 coord, const bool calc_color)
template float fractal_voronoi_distance_to_edge< float4 >(const VoronoiParams ¶ms, const float4 coord)
BLI_INLINE uint32_t hash_bit_rotate(uint32_t x, uint32_t k)
float perlin_hetero_terrain(T p, const float detail, const float roughness, const float lacunarity, const float offset)
float2 hash_float_to_float2(float2 k)
static float3 compute_3d_orientation(const float3 orientation, const float isotropy, const float4 seed)
float hash_to_float(uint32_t kx)
template float fractal_voronoi_distance_to_edge< float2 >(const VoronoiParams ¶ms, const float2 coord)
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< float, 2 > float2
VecBase< float, 3 > float3