PageRenderTime 36ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/noise.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 85 lines | 41 code | 18 blank | 26 comment | 1 complexity | 65c0331cc013d5fa6aa527ca44dec811 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file noise.cpp
  3. * @brief Perlin noise routines for procedural textures, etc
  4. *
  5. * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "noise.h"
  28. #include "llrand.h"
  29. // static
  30. #define B 0x100
  31. S32 p[B + B + 2];
  32. F32 g3[B + B + 2][3];
  33. F32 g2[B + B + 2][2];
  34. F32 g1[B + B + 2];
  35. S32 gNoiseStart = 1;
  36. F32 noise2(F32 *vec)
  37. {
  38. U8 bx0, bx1, by0, by1;
  39. U32 b00, b10, b01, b11;
  40. F32 rx0, rx1, ry0, ry1, *q, sx, sy, a, b, u, v;
  41. S32 i, j;
  42. if (gNoiseStart) {
  43. gNoiseStart = 0;
  44. init();
  45. }
  46. fast_setup(*vec, bx0, bx1, rx0, rx1);
  47. fast_setup(*(vec + 1), by0, by1, ry0, ry1);
  48. i = *(p + bx0);
  49. j = *(p + bx1);
  50. b00 = *(p + i + by0);
  51. b10 = *(p + j + by0);
  52. b01 = *(p + i + by1);
  53. b11 = *(p + j + by1);
  54. sx = s_curve(rx0);
  55. sy = s_curve(ry0);
  56. q = *(g2 + b00);
  57. u = fast_at2(rx0, ry0, q);
  58. q = *(g2 + b10);
  59. v = fast_at2(rx1, ry0, q);
  60. a = lerp_m(sx, u, v);
  61. q = *(g2 + b01);
  62. u = fast_at2(rx0,ry1,q);
  63. q = *(g2 + b11);
  64. v = fast_at2(rx1,ry1,q);
  65. b = lerp_m(sx, u, v);
  66. return lerp_m(sy, a, b);
  67. }