1

Topic: Diamond textures

Intro

It was January 2015 when I saw this picture as an illustration on some business news.

http://www.kuukahvila.com/peteihis/AOI/projects/diamond/story/Kauppalehden_timantti.jpg

It has some resemblance to a brilliant cut diamond, but anyone can see, that the the forms are irregular and at a closer look some some defining forms are actually missing entirely. Not to mention the "radiating" light, which is down right ugly.

Around the same time there was another one that obviously was not supposed to be a brilliant but, what is known as the "Passion cut". Thisone is much better than the one above, but this artist too had taken a few short cuts.
http://www.kuukahvila.com/peteihis/AOI/projects/diamond/story/blue-gem.jpg



The Brilliant shape

So I started to look for information, how it really should be done. It turns out that there are several different standards, quality criteria and "schools" about brilliants and to my surprise all the details are not even fixed, but come with options. Eventually I chose, what is called the "Eulitz Brilliant" as my starting point. The Euliz Brilliant is said to have the main angles and dimensions mathematically calculated. I think I made a tiny mistake with the proportions but at least the angles should be as correct a possible.

I have already forgotten some details of how I eventually got the model done. Anyway, it's a PolyMesh. I'll try post something to the Modeling section some day.

http://www.kuukahvila.com/peteihis/AOI/projects/diamond/story/Brilliant_clay.png
(Click for a larger picture!)



The Diamond material

Making the diamond material was basically easy. Just set IoR to about 2.42 and there you go! Then I also gave the material a light cyan-blue transparent color. This is supposed to have the effect, that when a ray bounches a few times inside the diamond, it gets a little bit more colured every time and should produce some areas, that are more blueish than others on the render. Eventually, when I was working on the colur separation ("rainbow effect" if you like), I ended up using 2.418 for the average IoR of the material.

The high IoR alone does not make the diamond look very impressive. This one is with just a single layer texture with fixed reflectivity.

http://www.kuukahvila.com/peteihis/AOI/projects/diamond/story/Brilliant_simple_txtr.png

It could be a little bit improved by making a procedural texture that uses the ViewAngle to adjust the reflections but that is still not, what I was after. I knew I had to dig into physics books to get it right. At this point I put the project on docks for a couple of months.



Developing the textures

I knew that the diamond (or any transparent material) needs a different texture on the outside and the inside surfaces. Then is stumbled on a paper that had the reflectances drawn into curves in relation to the angle. (I did not ask permission to use it, but it was in a public source....).

Of course the ViewAngle in AoI is backwards compared to the angles used in the physics class. So I just drew custom curves, that somehow represent those. The first attempt to render was a bit of a disappointment. When I mapped the inside texture into the the model, it turned all black....

That was because the ViewAngles on the inside are negative. -- Once I got that corrected (set the ViewAngle to Abs), I knew I had something happening.

But I wanted to do it right.

I remembered this dicussion and there were some valuable tips in there, like that the ViewAngle actually puts out the cosine of the angle and not the angle of incidence (Theta_i) itself. That approach actually normalizes the value between -1 and 1, which is handier to use than ±pi/2 on the editor and also the cosine makes the colour slides on a sphere look much nicer.

Now I needed to turn the cosine into the angle. Unfortunately there is no arccos-function available. The available angle-function is basically an arctan-function where the tangent is expressed by two variables (a.k.a. atan2). Well' it' been over three decades since high school so... scratchchin

Somehow I managed to dig out from my memory a couple of formulas that seemed relevant to this case: tan = sin/cos and the Pythagorean theorem. So after the mathematical work-out, the angle has to be:

Theta_i = angle(sqrt(1-ViewAngle^2), ViewAngle)

Phwefff... And then to work.

Now, the changing the cosine back into the angle actually turns, what was backwards, forwards again. So now the reflectance physics formulas can be used without modification. On the outside texture there is nothing special to it. On the inside the critical angle (Theta_c) needs to be defined. Of course the formula for Theta_c is based on sine, so I had to do the same thing as above, but the other way around. -- On the wrong side of this limit the equations would not work (produces "NaN").

The content of the procedural wiring is simply "If Theta_i > Theta_c, reflectance is 100%. Else use the formula."  In Wikipedia the needed equations are scattered into several articles, so I went for my old physics books to be sure.

http://www.kuukahvila.com/peteihis/AOI/projects/diamond/story/Inside-texture.png
(Ckĺick to see it larger!)

And then to render:

http://www.kuukahvila.com/peteihis/AOI/projects/diamond/story/Brilliant_true_plain.png

Now you'll notice that the there is a a general grayness on it and that light is leaking through the diamond. The grayness happens because the diamond is reflecting the partially illuminated plane under it, but the light leakage should not be possible. So let's try it with the caustics on.

http://www.kuukahvila.com/peteihis/AOI/projects/diamond/story/Brilliant_true_caust.png

Now of course the diamond reflects all the direct light back up and the area under it is in complete darkness. The obvious solution would be to use and environment color other than black. The problem there is that it can not be used with caustics. The photon map may or may not be computed -- (often it somehow works two times in a row, but not the third time and in any case only with relatively low photon counts.)

What you can do is to render an image with the environment and another one with the light and then combine them in an image processor....



Separating colours

As we know AoI can not separate colours by diffraction on it's own. However, it can do it with a little help.

In the Tools library, there is a script that can be modified to change the Index of Refraction of a material 'on flight' and the sub-images system in the movie renderer offers a handy way of combining several renders in different colours. Now all it takes is to change the color of the light synchronized with the changing of the IoR. Then I began to think, how to change the colours of several lights and the environment simultaneously and decided, that it was easier to leave the light as they are and use a colour filter instead. The filter is a small transparent sphere in the camera location, with the transparent color changing.

So far so good, but how exactly should the IoR change in relation to the colour? After some research it turned out that there if quite a bit of variation how each source translates wavelengths to colors. I chose to follow the scale that was used in Wikipedia and go from slightly infrared to slightly ultraviolet in the spectrum.

http://www.kuukahvila.com/peteihis/AOI/projects/diamond/story/605px-Linear_visible_spectrum.svg.png

It also became obvious, that the as function of wavelength IoR behaves like a hyperbola (not on very long wavelengths but in the visible light area very much so).

http://www.kuukahvila.com/peteihis/AOI/projects/diamond/story/320px-Dispersion-curve.png

Then I found a series of IoR:s for different wavelengths in Crown Glass. I normalized the wavelengths from 700 nm to 350 nm into 0.0 - 1.0 (yes: turned the scale backwards just out of the habbit of having the red colour on the on the left end of the hue-bar) and divided the IoR:s by the IoR for green color, which is nicely in the middle of the scale. Now the equation for the IoR is of the form (b0/(2-x) + b1).

The 2 comes from the normalization of the scale: 700/(700-350). With a longer or shorter colour scale it would be something else. Then I wrote a script for least squares with the normalized data:

// BeanShell

import Jama.*;  // I don't think this is necessary

// The equation: y = b0/(2.0-x) + b1

Matrix y = new Matrix(
    new double[][]{
        {0.996068152},
        {0.997378768},
        {0.998034076},
        {1.0},
        {1.00327654},
        {1.007863696}});

Matrix X = new Matrix(
    new double[][]{
        {0.53030303, 1.0},
        {0.573770492, 1.0},
        {0.603448276, 1.0},
        {0.636363636, 1.0},
        {0.744680851, 1.0},
        {0.853658537, 1.0}});

Matrix b = (X.transpose().times(X)).inverse().times(X.transpose()).times(y);

for (i=0; i<b.getArray().length; i++)
    print (b.getArray()[i][0]);

This gave me b0 = 0.03655 and b1 = 0.9764 Then I only needed to multiply the equation by the average IoR of diamond. This should now work for any material just by changing the one number.

Now, where the IoR of a material can be directly controlled by a script, the parameters of a texture are controlled by the parameters track. There is one major annoyance with those: The track forgets which parameters should be controlled, every time you open a texture or a material of the object for editing. A part of this 'forgetfullness bug' was already fixed a few years back, but obviously it was a bit deeper than we thought at the time.

Now the IoR-Controller script controls the IoR-parameters of the textures as well. Unfortunately, effectwise, this seems to work against itself a bit, but that's, what the equations say.

Any way, then to rendering. A one second movie, with just one frame/second with 12 sub images. Now, as the colours from yellow to blue are actually compressed into the middle of the scale the outcome is very strongly tinted with red and blue.

Edit: I changed this picture into one where the colour separation worked. Despite the obvious problem with the general color you can actually see it.

http://www.kuukahvila.com/peteihis/AOI/projects/diamond/story/Brilliant_diff_white_4.png

For some reason the colour filtered sub images appear rather over exposed on the screen at render time, but the final picture is much dimmer. I compensated this in two ways: I made the filter amplify the light and then adjusted the light itself to find a nice level.

The compensation to the color should, of course, be done in the colour filter, but since at this point, I had given up the thought of using more than one light at the time, I took a shortcut and made the compensation to color of the light. The exact tone was calculated backwards from a supposedly gray area of the picture before.

Below I used a version of the material, where there is no blue color in it. There are two spot lights, one shadowless and one normal with 50/50 shares. The result is basically similar to having rendered the images separately and then blended.

And WHAT THE FOOOOK????

http://www.kuukahvila.com/peteihis/AOI/projects/diamond/story/Brilliant_diff_comp_two_FU_02.png

It is a perfectly beautiful gray scale picture of the darn diamond, but the colour separation that I programmed into it is missing entirely.

I need to get drunk. NOW!

EDIT: Added the texture picture.
EDIT: Note on the spotlight for the last picture.
EDIT: Added the reflectance link.

Last edited by peteihis (September 28, 2015, 11:22 am)

...there's more to the picture than meets the eye...

Re: Diamond textures

Now, Now... I hope we can get this figured out without relying on the balmer peak...

First, congrats on some very thorough research. The bit about the view angle and reflection will come in handy for some projects that I have been contemplating for a while. And perhaps we should consider adding arc-cosine to the procedural functions. Its available in the java.math core class, so just a matter of adding a function box for it... I'd estimate ~5 lines of code.

First glance, which I have not been able to test yet, I do not believe that this is due to the same issue that has been discussed on sourceforge recently.

May I suggest taking apart the problem into several small steps?

As a control, how does the grayscale (balanced) result compare to a pure white light, rendered right in the middle of the IOR, all other details the same?

First: do your testing without the fancy procedural texture. You should be able to get spectral diffraction effects with a simple transparent texture, and its one less set of variables to have to consider.

- Can you get any diffraction  effect with a simple triangular prism?
- Try rendering the prism as just two frames, one near blue, and the other near red part of the spectrum. Post those frames separately so that we can compare them.
- What kind of light are you using? Post the type and all variables.
- Also, what scale are you working on with your model? That is, how many AOI units across is the diamond?

I have done a (crude) diffracted spectrum experiment before, and got some results, so I do expect to be able to get this working eventually...

Thumbs up

3

Re: Diamond textures

eusa_doh A classic case of decimal-error...  lol

Some time in the summer I had a version of the file where the 0.03... had turned 0.003... I did not realize that I had one still lying around a of course I had to start working with that one...  icon_rolleyes

Here it's corrected.

http://www.kuukahvila.com/peteihis/AOI/projects/diamond/story/Brilliant_diff_comp_two.png

The colors are never very strong with this technique. Here's the same picture with higher saturation. -- Still not very strong.

http://www.kuukahvila.com/peteihis/AOI/projects/diamond/story/Brilliant_diff_comp_two_sat.png

...and yet another one. Rendered with dimmer lights, the blue color in and then post processed a bit. (Increased brightness by 50% and pulled saturation to +100%)

http://www.kuukahvila.com/peteihis/AOI/projects/diamond/story/Brilliant_diff_comp_two_blue_dim2_post.png

Last edited by peteihis (September 22, 2015, 4:27 am)

...there's more to the picture than meets the eye...

Re: Diamond textures

Glad you got that part figured out.

One thing that I have noticed about real-world photos that end up with the very dramatic lighting/saturated spectrum is that they have a very strong, highly directional light. Think of a very narrow spotlight.

I suspect that with broader light sources, the spectrum samples across various source points on the light will overlap, somewhat out of phase, and wash each other out.

Might also be fun, once the lighting is performing as desired, to lay the diamond on a cloth-type surface...

Thumbs up

5

Re: Diamond textures

Narrow light sources make usually sense with caustics. Actually in many cases it is the directional lights, that produce the best caustic effects. Here's one with just a directional light. (Intensity 0.8)

http://www.kuukahvila.com/peteihis/AOI/projects/diamond/story/Brilliant_diff_comp_blue_dir.png

And another with he light set to shadowless. (Intensity 0.75)

http://www.kuukahvila.com/peteihis/AOI/projects/diamond/story/Brilliant_diff_comp_blue_dir_shdl.png

Something unexpected happens, when I use a color in the environment: In this one there are no lights. The environment is only about 50% bright, but generally the diamond appears somewhat brighter than that. I don't think it should be possible. Caustics and Ambient Occlusion are on.

http://www.kuukahvila.com/peteihis/AOI/projects/diamond/story/Brilliant_diff_comp_blue_env_50.png

To my surprise with just the environment producing light or the environment and a directional light, caustics seems to be working. The combination of environment and a spotlight is what causes problems. (Seems that something is left in the memory and that gets in the way when you render the next picture or the next to that...)

Last edited by peteihis (September 28, 2015, 1:12 pm)

...there's more to the picture than meets the eye...

6

Re: Diamond textures

Hmm... been thinking about that a bit. and I recall having issues with re-rendering the same scene if I cancelled and changed settings. I'd thought that it was fixed in 3.0.2, but perhaps not... it was an intermittent issue, so no good consistent repro. in the first place.

There is also currently an issue with direct light primitives and refractive materials when the surface is shadowed, but I don't see that being relevant here...

Thumbs up

7

Re: Diamond textures

ljs wrote:

I'd thought that it was fixed in 3.0.2

Might be. I did most of the studying on an earlier version. With these I used the settings that I already had found working. -- I do remember some of the minor changes that made RR go haywire...

BTW, there is one thing with the diamond texture that makes it entirely wrong: The physics equations are made for light. Not for eye-spawn rays.

This becomes very obvious, when I place the camera inside the diamond (actually I used a cube to test this -- not so much the actual diamond) all of the cube is dark inside except for the round window, where the the ray can escape the surfaces.... (Monte Carlo the makes that round window to reflect inside the piece several times over, which is not natural either.

The thing with light is, that when the angle of incidence is low enough, the inside of the the piece should reflect 100% of it AND AT THE SAME TIME let an angle dependent percentage of light through from the outside. Now as the ray is traveling to the opposite direction, there is only the 100% reflectance, but no transmittance, though physically that is what should happen.

It is possible to wire the procedural materials with 100% reflectance and 15% transmittance, but unfortunately the reflectance overrides the transmittance and the programmed 15% has no effect.

This of course is a kind of a fail safe system preventing the user from producing a light amplifier without meaning to... Still in this case the 100% + 15% would never make over 100% when the (camera) ray escapes the piece. Even at right angle 100% of light will never penetrate the surface from the outside. So, inside the the diamond there is always considerably less light available than outside. --> No amplifying can take place.

Well of course the ray tree would probably explode if the surface was working right.... I have been thinking that I could try by limiting the 100% reflectance to, say 87%, and see what happens then. Maybe on the holidays then ... smile

One thing I was thinking about trying wad the scripted textures, but unfortunately that part of Peter's scripting the manual seems to have been removed (There used to be a piece about writing a striped texture). Though that probably wouldn't work any better as long as reflectance overrides transmittance.

scratchchin

Edit:

scripted textures

That is to say texture plugins...

Last edited by peteihis (December 19, 2015, 7:57 am)

...there's more to the picture than meets the eye...

8

Re: Diamond textures

And for the refraction angles I probably should have checked the usage of the "Abbe number" -- The colour split looks a bit exaggerated to me in some further tests.

...there's more to the picture than meets the eye...

9

Re: Diamond textures

I like the way the light makes a pattern on the floor from the diamonds in these renders.

May it be an evening star
Shines down upon you
May it be when darkness falls
Your heart will be true

Thumbs up