You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

63 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<7> s7;
  29. for (int j = 0; j < size.y; ++j)
  30. for (int i = 0; i < size.x; ++i)
  31. {
  32. float x = (float)i, y = (float)j;
  33. float sum = 0.f;
  34. int maxoctave = (j < size.y / 2) ? 1 : (1 << octaves);
  35. for (int k = 1; k <= maxoctave; k *= 2)
  36. {
  37. if (i < size.x / 3)
  38. sum += 0.5f / k * s2.Interp(zoom * k * vec2(x, y));
  39. else if (i < size.x * 2 / 3)
  40. sum += 0.5f / k * s3.Interp(zoom * k * vec3(x, y, 0.f));
  41. else
  42. sum += 0.5f / k * s7.Interp(zoom * k * vec7(x, 0.f, 0.f, 0.f, y, 0.f, 0.f));
  43. }
  44. float c = saturate(0.5f + sum);
  45. data[i][j] = vec4(c, c, c, 1.f);
  46. }
  47. /* Save image */
  48. img.Unlock2D(data);
  49. img.Save("simplex.png");
  50. }