Mandelbrot Set with SIMD Intrinsics
nullprogram.com
nullprogram.com
http://hamsterworks.co.nz/mediawiki/index.php/Mandelbrot_NG_...
vec3 srgb_from_rgb(vec3 rgb) {
vec3 a = vec3(0.055, 0.055, 0.055);
vec3 ap1 = vec3(1.0, 1.0, 1.0) + a;
vec3 g = vec3(2.4, 2.4, 2.4);
vec3 ginv = 1.0 / g;
vec3 select = step(vec3(0.0031308, 0.0031308, 0.0031308), rgb);
vec3 lo = rgb * 12.92;
vec3 hi = ap1 * pow(rgb, ginv) - a;
return mix(lo, hi, select);
}
vec3 rgb_from_srgb(vec3 srgb) {
vec3 a = vec3(0.055, 0.055, 0.055);
vec3 ap1 = vec3(1.0, 1.0, 1.0) + a;
vec3 g = vec3(2.4, 2.4, 2.4);
vec3 select = step(vec3(0.04045, 0.04045, 0.04045), srgb);
vec3 lo = srgb / 12.92;
vec3 hi = pow((srgb + a) / ap1, g);
return mix(lo, hi, select);
}
They don't have any measurable performance impact, as far as I can tell.Edit: comparison between non-colourspace-corrected and colourspace-corrected versions of the shadertoy link http://www.screenshotcomparison.com/comparison/134695
// do some soft coloring based on distance
d = clamp( 8.0*d/zoo, 0.0, 1.0 );
d = pow( d, 0.25 );
vec3 col = vec3( d );The bottom line is that sRGB is hideously hard to work in. You really want to only use it for storage and only if you really must. It's an optimisation to allow you better range on the low end, at the expense of the high intensity end, to match human colour vision. However, that means using 48bit RGB and that's not a price everyone wants to pay. People who do professional graphics work simply use 32bit floats per colour channel - 128bit RGBA, or even 192bit RGBRaGaBa (separate alpha for each channel) and have workstations with 32 or 64GB of RAM. However, your normal everyday GUI application needs to run on a phone with about 1GB of RAM. Or going back farther, it has to run on an Intel 486 with 16MB of RAM. That kind of explains where the culture of "just treat it as linear, it's not that wrong" came from :) .
How's that going? Seems like progress has slowed.
If you want to see how alive is Hand Made Hero just follow Casey on Twitter and check the Forums from handmadehero.org.
Which makes me wonder - do GCC and/or Clang compile complex arithmetic so SIMD instructions?
A couple of years back, I rewrote a mandelbrot renderer from C89 to C99 and used complex numbers, and I noticed that it ran faster afterwards (not dramatically so, but I noticed the difference). I never checked, though, if the compiler emitted SIMD instructions, and sometime since I lost the source code to a faulty hard disk and was too lazy to write another one.