From 7b2f3bdcfb0c48ee353b716c97d25a08696ce10a Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 7 Feb 2017 09:41:06 +0100 Subject: [PATCH] samples: add blue noise generation demo. --- .gitignore | 1 + doc/samples/Makefile.am | 6 +++++- doc/samples/bluenoise.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 doc/samples/bluenoise.cpp diff --git a/.gitignore b/.gitignore index 37d715c0..7c07715f 100644 --- a/.gitignore +++ b/.gitignore @@ -79,6 +79,7 @@ _ReSharper.* # Our binaries demos/lol.js/lol.js doc/samples/benchsuite +doc/samples/bluenoise doc/samples/btphystest doc/samples/meshviewer/meshviewer doc/samples/nacl_phystest diff --git a/doc/samples/Makefile.am b/doc/samples/Makefile.am index 9eec13fc..9d6b9eb2 100644 --- a/doc/samples/Makefile.am +++ b/doc/samples/Makefile.am @@ -7,9 +7,13 @@ bench: benchsuite$(EXEEXT) ./benchsuite$(EXEEXT) if BUILD_SAMPLES -noinst_PROGRAMS = benchsuite btphystest nacl_phystest simplex +noinst_PROGRAMS = bluenoise benchsuite btphystest nacl_phystest simplex endif +bluenoise_SOURCES = bluenoise.cpp +bluenoise_CPPFLAGS = $(AM_CPPFLAGS) +bluenoise_DEPENDENCIES = @LOL_DEPS@ + benchsuite_SOURCES = benchsuite.cpp \ benchmark/vector.cpp benchmark/half.cpp benchmark/trig.cpp \ benchmark/real.cpp diff --git a/doc/samples/bluenoise.cpp b/doc/samples/bluenoise.cpp new file mode 100644 index 00000000..6d3d9eca --- /dev/null +++ b/doc/samples/bluenoise.cpp @@ -0,0 +1,39 @@ +// +// bluenoise — create a N×N blue noise kernel +// +// Copyright © 2016—2017 Sam Hocevar +// +// This program is free software. It comes without any warranty, to +// the extent permitted by applicable law. You can redistribute it +// and/or modify it under the terms of the Do What the Fuck You Want +// to Public License, Version 2, as published by the WTFPL Task Force. +// See http://www.wtfpl.net/ for more details. +// + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +using namespace lol; + +int main(int argc, char **argv) +{ + UNUSED(argc, argv); + + ivec2 const size(64); + auto const &kernel = image::BlueNoiseKernel(size, ivec2(8)); + + image im(size.xy); + array2d &data = im.Lock2D(); + + for (int j = 0; j < size.y; ++j) + for (int i = 0; i < size.x; ++i) + data[i][j] = vec4(vec3(kernel[i][j]), 1.0f); + im.Unlock2D(data); + im.Save("bluenoise.png"); + + return 0; +} +