From dorn@virginia.edu Tue Apr 11 11:53:50 2017 Date: Tue, 11 Apr 2017 11:45:19 -0400 From: Jonathan Dorn To: Westley Weimer Subject: Re: Graphics shader programs request I have attached a tarball containing shader sources and a renderer that uses them to generate images. The original shaders are in the bandlimiting/src/ directory and the renderer is in the bandlimiting/tools/ directory. You will need CIL (and ocaml) and CUDA (technically, you might be able to use an AMD card instead of NVIDIA, but I've never actually tested that, so YMMV) installed to build the renderer. You can edit bandlimiting/tools/Makefile or set the CIL and CUDA environment variables to point to the correct locations on your system. Once those are defined correctly, you should be able to just run make in the bandlimiting/tools/ directory. The original shaders are written in C so that I could process them with CIL, but the renderer actually uses programs written in OpenCL. The easiest way to get the OpenCL programs (and to generate variants) is, from the bandlimiting/ directory, to run tools/search.py configuration \ --keep-opencl \ --search ga \ --generations 0 \ --popsize \ --prog src/.c where is the number of variants to generate and is the program to modify. This may take a while depending on the shader you select. It will create several ppm files in the bandlimiting/golden/ directory and several files named 000000.cl (and similar) in the bandlimiting directory. The 000000.cl file will be the original program and the rest will be variants. It will also measure how close the shader's output is to the target output (lower numbers are better), but you can just ignore that if it's not useful to you. You can modify the *.cl files however you want; Wes hinted that you might want to add printf statements or to save intermediate state in the image instead of the final output. The shader function is always the same as the filename you chose and will usually be about 90% through the *.cl file. It is called once for each pixel in the image; whatever color it returns (type float4, though only the x, y, and z fields are saved) will be the color of the pixel. So to save an intermediate value, just have it return that value in the x, y, and/or z field of the float4. To run a shader yourself, you can use this command: tools/renderer 000000.cl \ --perspective \ --zoom 0 \ --size 256x256 \ -o filename.ppm The renderer always generates ppm P6 images, which are easy to process programmatically. If you want something more common like png and have ImageMagick installed, use "convert -set colorspace RGB name.ppm name.png" to convert it. Finally, here is a list of the available shaders and the number of nodes we can replace in each. Since each node can be either replaced or not, there are 2^N total variants for a shader with N replaceable nodes. For shaders with small numbers of nodes, you can use --search brute instead of --search ga to efficiently and exhaustively generate all possible variants. src/bars.c : 3 src/checker2.c : 4 src/checker.c : 4 src/circles.c : 5 src/cosine.c : 1 src/crazymaze.c : 22 src/depthillusion.c : 4 src/gabor_brick.c : 26 src/gabor_harlequin.c : 74 src/gabor_marble.c : 28 src/gabor_rust.c : 3 src/gabor_wood.c : 18 src/hardstep.c : 1 src/lights.c : 20 src/lightweave.c : 40 src/oilgrid.c : 15 src/perlin.c : 244 src/pulse.c : 2 src/ridges.c : 1 Please let me know if you run into any problems building or running the system. Jonathan