Thursday, December 22, 2016

The Colour of 3D Fractals

An interesting feature of 3D fractals compared to other shapes is that they have a real colour. By this I mean that, if you 3D printed a 3D fractal to an ultrafine scale (below about 100nm), using a white substance, the fractal would never-the-less appear to have some amount of colour. This is due to structural coloration, meaning that the actual shape of an object (rather than its chemistry / pigments) gives it colour.

Examples in nature include butterfly wings, peacock's tail feathers, the iridescent colours when cutting through meat (due to muscle fibre ends), and opals. These iridescent effects occur when the object has a regular structure at scales similar to light's wavelength, much like a diffraction grating. But it isn't just iridescent colours that are produced structurally, for instance the bright blue colours of parrots are due to the fine scale shape of the feathers.

So what colour are 3D fractals? What colour is a 3D Menger sponge, or a Mandelbox or Mandelbulb? The answer is that it is pretty difficult to find out. The equations of light scattering are quite complicated, and also difficult to simulate as calculations and reflections happening at the nanoscale effect the result at the macroscopic scale (to colour a 1cm fractal for instance). One needs to get statistical approximations of the light dynamics, luckily A Yu Cherny and E M Anitas from the Moscow Institute of Physics have some very recent papers on this subject. In this paper they look at the spectrum of light reflected from a cluster fractal, in this case a Cantor cluster:
gives the spectrum:
The horizontal axis qL is proportional to the frequency of light, and the vertical axis gives relative intensity of reflected light. The downwards slope suggests that this fractal would be a blueish sort of colour, since it has a similar slope to classic Rayleigh scattering which gives the sky its blue colour. 
They also work out the spectral response of a Koch snowflake-like 2D fractal (from in-plane light rays), with a similar power-law downward slope, but less steep in this case. And also for 3D Viscek fractsls (void trees):
giving the spectrum:
which again has a gentler slope, so I would expect it to be a less saturated blue, if I'm interpreting it correctly. 

For more complex fractals statistical plots are no good as the colour could well change with location. A good example is the Mandelbox fractal (I'm using scale -1.5), where some areas are clearly more rough than others. To render the fractal, I use the program Fragmentarium as the algorithm can be modified. There are several effects that could be simulated but I have tried just two:
  1. These fractals are rendered as a very high detail but smooth surface, which is controlled by the minDist bailout threshold, so long as the other iteration counts are high. I model light of different wavelengths as reacting to this surface of different minDist values respectively, consequently high wavelength light will only react to smoothed features and low wavelength light will reflect off all the smaller features. So I simply render the fractal three times using a different minDist, for red green and blue light respectively. 
  2. The Bragg's Law effect shows how a coherent light, when bouncing off two surfaces of different depths, interferes on the return journey, either destructively (darker in that wavelength) or constructively (brighter in that wavelength). This is the principle effect happening in the iridescent natural examples. I simulate it by taking nearby points in screen-space, and performing this interference based on their relative depths. 
The result is shown on this 1cm dimension Mandelbox, there appears to be no coloration:
However this may be largely expected on this fractal as most of it is very low roughness surfaces (even the rough parts have a lot of these flat box faces, larger than the wavelengths of light). But if we look closer: 

 here we see a brown colour on the thinnest cracks, and come blue colours amoungst the rougher areas.
This 'lilly' shows a brown coloration at its edge, and blue amoung the tiny encrusted boxes.
For a smaller (4mm) Mandelbox, the effect is a bit stronger, but the actual colours haven't changed. 

Examining the effect of the two simulated effects above, it appears that they have a very similar effect, both causing the redder and the bluer areas in roughly the same places. Since the 2nd effect is slower and less obvious in its correctness, I have chosen to exclude it, and can just do the first effect, but exaggerating the wavelength difference between red,green,blue to compensate. This is done in real-time using this Fragmentarium script

It is important when using this script to turn the 'pigment' colour off (colourIterations=0), antialiasScale=0, dither=0, and set maxRaySteps and (Mandelbox) Iterations to high. 

Here is the result for the 1cm Mandelbox:

How about the 1cm Mandelbulb? Well, the same code gives this:
One problem with this method is that, while the large minDist lighting gives the expected smoothing, it also enlarges the fractal. consequently, edges could become coloured as they are only seen in the lower wavelengths. The images below removed this effect, and I have also rendered in higher detail, with more colour channels (5), and adjusted the specularity to see what effect it had:
The results are very similar, and suggest that the colours in the images are not unwanted effects. Here are two areas of the -1.5 mandelbox that show consistent colds and warm colours respectively:
 


These results are all very primitive however, so my conclusions are really just conjectures at this point, here they are:

1. For a surface of increasing roughness, the surface goes from a mirror towards a reducing sharpness specular component and increasing diffuse component, the specular component is a warmer colour and the diffuse a cooler colour. This is very similar to the Tyndall effect, but rather than scattering of light going through a 'dust' it is scattered reflections off surfaces. The colour gets stronger as roughness increases.
2. For much rougher surfaces, areas in the light and protrusions have a warmer colour as the higher frequencies are scattered away. and areas out of the light and in hollows and away from the specular reflection have a bluer colour as greater scattering is needed to get light from these areas.
3. For materials that absorb some of the incident light, I would expect the average colour to be warmer, as blues scatter more and so have more surface hits where absorption can happen.
4. For complex fractals the structural colour can be quite subtle, because:
    a. the coloration varies so much that it averages to a greyish colour
    b. many surfaces are low roughness, such as the -1.5 mandelbox, or the smooth mandelbulb areas
5. For complex (multifractal, varying scale) fractals the structural colour doesn't effectively change with the scale of the fractal. It just effects how noticeable it is. 

Regarding point 1, a good avenue here may be the Cook-Torrence model of specular reflection off rough surfaces, it includes a Fresnel term, which includes a term to the power of the wavelength, such that larger wavelengths give a stronger, sharper specular reflection, consistent with this point 1.

Update:
There is a nice article on 3D printing transmission gratings at the micrometre level. This may be a reasonable model for the 2.5D fractal here:
as it is somewhat similar in its shape. If this is the case, then unfortunately the low pillar height in this fractal places it off the graph in figure 2, but the extrapolation hints at a pale or aqua blue, when the pillar height is 1 micrometre. Perhaps a better paper is this, which has a very similar local shape. For pillar height 120nm the perceived colour was 530nm which is aqua. Moreover, they claim that this lower pillar height (the same as the pillar width) keeps its colour up to 45 degrees angle, which, given the shape of the fractal above, suggest that the whole thing would keep an aqua colour, rather than be too iridescent. However it should be noted that both papers use transparent material and the result probably depends on the relative refraction indices... so it doesn't necessarily hold that the same coloration would work with just a reflective material like metal.

Also a lab has in fact made a nanoscale 'sponge' fractal, which they call the fractal nanotruss:
As you can see, the smallest scale is around 500nm, so just about into the light wavelengths. The lead of this project has clarified that it does exhibit structural colour, she says it shows opalescence. So it is good to hear that the effect does happen in real examples... though it remains a question what effect the material properties has on the resulting colour. 

3 comments:

  1. Instead of using fixed color channels, wouldn't it be better to sample form a blackbody radiation source? Select a given ray's energy with Monte Carlo sampling. Should work just fine. The only problem is how to convert that over to three channels of color as seen by us. Gotta have a full conversion table for that.
    If you want to simulate a fractal as seen in sun light (in space / without the atmosphere/sky) you'll just have to set the temperature to 5777K.
    Presumably that'll not be so different from what you've got now but it should be closer to reality.

    ReplyDelete
  2. Thanks! I did try this, after your suggestion. It was quite a bit trickier than it sounds... you then have to go from power spectra back to rgb, which requires knowing the sensitivity of wavelengths in the eye. The results seemed slightly off, I actually think I had a bug somewhere, but roughly it seemed to work, and as you mentioned, it didn't seem to make a big difference, perhaps fortunately.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete