# Mixing two shaders based on raylength

I attempted to mix a Glass shader and an SSS shader based on ray length to simulate a material that has many particles in it, scattering light that travels farther through it.

Node setup:

However, I get this:

Manually setting the Factor of the mix shader anywhere in between 1 and 0 gives this (renders of 1, .5, and 0):

What is causing this darkening and how can I get the desired result?

Try increasing the bounces under light paths.

The direct light preset with caustices gives a very dark image

while full global preset gives a golden brown finish.

I also think the SSS being used on the backface may be stopping light passing through the object. The calculation for the mix appears to always give a zero value for the visible faces, by replacing the SSS with another glass shader you get a brighter finish.

• It's still pretty noisy.. Is there a way to use ray length without including the variations caused by scattering etc? E.g. get the ray length as it occurs with a transparent node then use that to mix other shaders? – gandalf3 Nov 21 '13 at 22:32
• @gandalf3 the noise would be from the glass or more specifically the caustics - the biggest cause of noise in cycles. Usual noise reduction tricks apply. The material used won't alter the ray length, it is a measurement based off surface locations. I'm not sure that you get much variation in your mix calculations, I only see zero value facing camera. – sambler Nov 22 '13 at 12:27
• I thought the ray length referred to the path-traced ray, which bounces/scatters/transmits through an object based on the properties of the material? Anyway I was attempting to make a orange juice shader (again), and I can't figure out how to make it scatter light more based on the distance light has to travel through the juice. E.g like this, where the OJ is "thin", it looks like a glass shader, but there it is thicker, it looks like it needs SSS. – gandalf3 Nov 22 '13 at 21:59

I think that what you want to do is not to use the Ray Length directly, because that can includes many different ray types, but instead multiply the Ray Length with Is Transmission Ray, in order to get the length of the Transmission ray, instead of one which also includes the Camera ray type and others.

• I don't want the length between the camera and the object, I want the length between one surface of the object to the other (inside the object the rays are all transmission or reflection, there should be no camera rays in there).. This is easily gotten by multiplying the ray length by the backfacing, but using that to mix shaders is not working as expected.. – gandalf3 Oct 13 '14 at 20:24
• There; All fixed – someonewithpc Oct 13 '14 at 20:27