art with code

2010-07-27

Berlin!



Hanging out in Berlin this week, with a shiny new sketchbook to boot.

Went to the Pergamonmuseum on Sunday to be all Ozymandias. The things they have there are huge (indoor display of 15m high pillars, etc.) and pretty old (2-3 thousand years) and beautiful. And messed up in that ancient style of messed-upness. The objects in the Islamic museum side were nicee, superior metalcraft and calligraphy (also a millennium or two younger than the rest of the stuff but who's counting). The Assyrian reliefs had writing going across them, like a textured strip of cuneiform. They had a special display on the coloring of the Greek statues, with brightly colored reproductions of much RGB might.

2010-07-20

Silly C hacks

Macros! To do safe mallocs and fopens! Brittle like the glass you tread upon!

/* A small cat that prints out the files given to it */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <sys/stat.h>

#define BLOCK(pre, post, ok, error, block) \
{ \
pre; \
if (ok) { \
block; \
post; \
} else { \
error; \
} \
}

#define with_malloc(t, var, sz, block) \
BLOCK(t var = (t)malloc(sz), free(var), var, \
fprintf(stderr, "Malloc failed, out of memory\n"); exit(1), block)

#define with_file(var, fn, mode, error, block) \
BLOCK(FILE* var = fopen(fn, mode), fclose(var), var, error, block)

#define with_file_contents(var, len, fn, error, block) \
with_file(var##__f, fn, "r", error, \
off_t len = file_size(fn); \
with_malloc(char*, var, len+1, \
len = fread(var, 1, len, var##__f); \
var[len] = 0; \
block))

off_t file_size(char *path)
{
struct stat st;
stat(path, &st);
return st.st_size;
}

int main(int argc, char *argv[]) {
int i;
for (i=1; i<argc; i++) {
with_file_contents(s, slen, argv[i], fprintf(stderr, "Couldn't open %s.\n", argv[i]),
fwrite(s, 1, slen, stdout);
);
}
}



It would be kinda fun to port the whole functional array-munging part of prelude.ml to C. Fun in a very painful fashion.

Small C++ SSE3 vector lib

If you want to do some simple and somewhat fast vector math in C++, sse.h might be fun.

It has float4, double2 and double4 structs, constructors of different kinds, operator overloading and methods for horizontal add, dot product and swizzling.

Code examples:

4x4 matrix multiply with floats and doubles:

// dst = a x b, ~44 cycles with -O3 -funroll-loops
void mmul4x4 (const float *a, const float *b, float *dst)
{
for (int i=0; i<16; i+=4) {
float4 row = float4(a) * float4(b[i]); // float4(a) is {a[0], a[1], a[2], a[3]}
// float4(b[i]) is {b[i], b[i], b[i], b[i]}
for (int j=1; j<4; j++)
row += float4(a+j*4) * float4(b[i+j]);
*(float4*)(&dst[i]) = row;
}
}

void mmul4x4d (const double *a, const double *b, double *dst)
{
for (int i=0; i<16; i+=4) {
double4 row = double4(a) * double4(b[i]);
for (int j=1; j<4; j++)
row += double4(a+j*4) * double4(b[i+j]);
*(double4*)(&dst[i]) = row;
}
}


Dot product of two arrays of vectors:

double dotArrays (const double2 *a, const double2 *b, int len)
{
double2 sum;
for (int i=0; i<len; i++) {
sum += a[i] * b[i];
}
return sum.sum();
}

2010-07-12

AC the planet

+7C equals ow. (Check out the map in that: yellow areas would be deadly.)

Guess humans wouldn't have survived too well in the Cretaceous period (when the avg. temp was 15-20C higher than today. Tropical sea surface temperatures at around +37C. Here a fun lecture on that.) If you'd time-travel back to ride on brontosaurs or whatever, you'd probably end up with a heat stroke.

2010-07-09

Future display tech

Graphics, where is the limit? The display resolution of the day is 1920x1080, or Full HD, as it is called, with high-end displays operating at 2560x1600. Modern graphics cards are quite capable of running games at those resolutions. Adding stereo-3D on top of that doubles the amount of pixels, but that isn't much of a problem either. Pushing up the resolution from 100 ppi to 300 ppi would need an extra 9x the resolution, which would probably start pushing today's limits.

To do no-glasses viewing-angle independent 3D requires a pixel for every direction (or something like a pixel, e.g. plop a lens in front of a flat pixel array). That would easily multiply the resolution by 16 or 256 or such. Not to mention requiring new display tech and the cameras to produce content for them.

You probably want to push the dynamic range of the display as well, in order to reproduce bright noonday sun and a pitch-black night. According to this page the contrast from the sun to the limits of human night vision is around 300 trillion to one. To do that range with fixed step would take 48 bits. The display would have to be able to emit from a couple photons at a time all the way up to a billion candela per square meter, which is a good million times brighter than today's bright LCD displays.

Using 16 bits per RGB channel for encoding the hue and saturation, and then 48 bits divided among them to do the luminosity would result in 96 bits per pixel. With 32-bit alpha channel, 128 bits per pixel, or four times today's display bit depth.

The display would be nice if it covered your field of vision from a comfortable viewing distance. A wall-sized display might be the ticket to that. Let's say 5 meters by 3 meters.

Summing up all the above, a future wall-sized 256x integral hologram display with 300 ppi resolution and natural dynamic range would have 550 gigapixels at 128-bit color, and would need a 8.8 TB frame buffer from the graphics processor. A more modest 30" display at those specs would have only 9.4 gigapixels and a 150 GB frame buffer. If we assume that 1 GFLOPS is enough to run a 32-bit two megapixel display, a 128-bit 550 gigapixel display would require around 1,100,000 GFLOPS of processing power. Today's graphics cards are at around 2 GFLOPS, so if they keep doubling in performance every year it'd take 20 years for them to get to the required 1.1 PFLOPS.

What would such a display look like in person? I suppose the experience would be like looking out of a window. A window to a place that doesn't exist. Where the searing hot twin suns rise above the desert, windswept dialog boxes of long-forgotten programs casting long shadows into your living room. Or the view out into a starlit forest: a ghastly green shape here, another there, the darkness registering as a noisy shimmer as the rods in your eyes struggle to resolve the scant errant photons reflected from your surroundings.

I don't really know if 256x holography would be enough, though. Maybe you want to boost that to 4096x or more. And make the display wrap around you for that VR cave experience. And add one extra color channel for tetrachromats. Or heck, just use photon energy histograms as your colors instead of the limited RGB. The people with those new-fangled omni-EM eyes will thank you for that. And a monitor just isn't a monitor unless you can do astronomical spectrography off it, take your X-ray with it, microwave an egg, make your radio play tunes and do a realistic documentary of the Chernobyl disaster, complete with the viewer receiving a half dozen gray of radiation.

Blog Archive