Nested Dielectrics

I was thinking about this today and whether Cycles may eventually get nested dielectrics at some point in the future.

For those who don’t know, nesting dielectrics would allow you to simulate things like ice cubes in a glass of water, orbeez in a vase etc. In these cases, because you have a transparent/refractive object submerged in a second transparent/refractive medium, the way light refracts depends on whether you are viewing the object above the liquid, or submerged below it.

For example, when you submerge saturated orbeez in water - it looks like they disappear (see video below).

Then it struck me - a solution already exists in Cycles using the light path node. No idea why I hadn’t thought of this before:

Basically - you give your object the shader group shown below. You set the IOR of the bottom glass node to the material you want it to be (e.g. ice in this case). Then you set the IOR of upper glass node to 1 + the difference between the object IOR and the IOR of the medium it is submerged in (in this case I have submerged ice in a cube with an IOR indicative of water - so the difference is -0.024).

Now when you submerge the ice ball, the IOR reacts correctly depending on whether you are viewing the ice above the water, or the ice submerged because the shader group knows whether you are viewing it through a refractive medium or not due to the light path node.

If the object had the same IOR as the medium (like in the case of an Orbee in water), the top glass node would have an IOR of 1 and the object would look like it has disappeared when submerged due to the lack of any discernible difference in IOR between the object and the medium.

This approach does have it’s limitations in as much that it can only handle one level of nesting - but it’s better than nothing I guess.

5 Likes

Nice trick.I guess cycles dont knows or makes a check, if the ray is in a object and has a different or same IOR.
If something like your transmission IOR “detection” would be implemented in the cycles IOR shader it would work out of the box.
The shader must just check what is the IOR outside of the material.In most cases Air with IOR 1.

If the material is in a Volume like water, then the IOR of the material changes to,because the basic IOR is based of Air 1 in the equation.
For the new IOR calc you have to use the IOR ray what are in the Volume (water)+ the material IOR.

Just one problem with the above node setup - it doesn’t work if you have say liquid in a glass, because when you view the object through the glass, it triggers the light path node.

This nodegroup works better because you can set the transparent depth to account for this.

1 Like

hm i see,maybe you can make a detection radius from the cube,to exclude the glass?

The ray depth does this.

By passing through the glass - ray depth = 1
By passing though the glass and liquid - ray depth = 2

Therefore if the ray passes into the ice cube below the liquid line - ray depth = 3 and the bottom glass node is invoked, whereas if it passes into the ice cube above the liquid, it has only passed through the glass previously, which makes the total ray depth = 2 and therefore uses the top glass node.

Obviously this is view dependent - so won’t work universally.

Have you tryed the new math graph shader with it?
you could measure the exact outputs with the number shader.

By “new math graph shader”, do you mean this?

Yes correct !!! with the number shader you can display all the values you can think of,eg the lightpath outputs.

I think nested dielectrics was a patch being worked on at some point. Looks like it was abandoned?

There is a post in the bugtracker,but its works as it was designed said brecht.
https://developer.blender.org/T98633

The thing is,you dont need to change the IOR of the glass eg.
The shader should just check what IOR is the volume outside from my material,and set the IOR from outside into the Fresnel calc inside the material shader.

The Fresnel calc needs to basic IOR settings.
The outside IOR mostly air at 1.or 1.33 for liquids ect.
And the material surface IOR itself,maybe water 1.33 or glass 1.5 etc.

Then you get the correct Reflection and refraction if you set both values in the fresnel equation.

Its pretty simple as that.

The standard Fresnel reflection/refraction is based on Air IOR = 1 calc in the shader.

Maybe using the ray depth as well in Light Path node, it’s possible to nest more than 2 refractive objects. I’ve tried this 1+ the difference of IOR and it didn’t look right, not sure what I did wrong. Thanks