62 lines
1.6 KiB

  1. //
  2. // Simplex Noise Test Program
  3. //
  4. // Copyright (c) 2010-2014 Sam Hocevar <sam@hocevar.net>
  5. // (c) 2013-2014 Guillaume Bittoun <guillaume.bittoun@gmail.com>
  6. // This program is free software; you can redistribute it and/or
  7. // modify it under the terms of the Do What The Fuck You Want To
  8. // Public License, Version 2, as published by Sam Hocevar. See
  9. // http://www.wtfpl.net/ for more details.
  10. //
  11. #if HAVE_CONFIG_H
  12. # include "config.h"
  13. #endif
  14. #include <lol/engine.h>
  15. using namespace lol;
  16. int main(int argc, char **argv)
  17. {
  18. UNUSED(argc, argv);
  19. float const zoom = 0.03f;
  20. int const octaves = 10;
  21. /* Create an image */
  22. ivec2 const size(1280, 720);
  23. Image img(size);
  24. array2d<vec4> &data = img.Lock2D<PixelFormat::RGBA_F32>();
  25. /* Fill image with simplex noise */
  26. simplex_interpolator<2> s2;
  27. simplex_interpolator<3> s3;
  28. simplex_interpolator<4> s4;
  29. for (int j = 0; j < size.y; ++j)
  30. for (int i = 0; i < size.x; ++i)
  31. {
  32. float sum = 0.f;
  33. int maxoctave = (j < size.y / 2) ? 1 : (1 << octaves);
  34. for (int k = 1; k <= maxoctave; k *= 2)
  35. {
  36. if (i < size.x / 3)
  37. sum += 0.5f / k * s2.Interp(zoom * k * vec2(i, j));
  38. else if (i < size.x * 2 / 3)
  39. sum += 0.5f / k * s3.Interp(zoom * k * vec3(i, j, 0.0f));
  40. else
  41. sum += 0.5f / k * s4.Interp(zoom * k * vec4(i, j, 0.0f, 0.0f));
  42. }
  43. float c = saturate(0.5f + sum);
  44. data[i][j] = vec4(c, c, c, 1.f);
  45. }
  46. /* Save image */
  47. img.Unlock2D(data);
  48. img.Save("simplex.png");
  49. }