Shadow rays, the Light Path node and how sampling works

For quite some time I would like to fill some gaps in my understanding of the tracing/sampling method of Cycles. I believe I have some misconceptions, as when playing around with the Light Path node, the results do not match my expectations.

I try to explain in brief my understanding of the sampler. Please correct me, when you find something wrong with it.

When hitting a surface the material is evaluated and a new ray is created. There is always importance sampling used to determine the direction of the new ray. There are two different flavors of importance sampling, each of which is used for some rays.

  1. Rays are created depending on the shader (BSDF), preferring directions which the most light is scattered to, according to the BSDF.
  2. Rays are created in the direction of a light source. These are called shadow rays.

The intensities resulting from these 2 methods are combined with MIS. Shadow rays are only created toward light sources with the MIS flag enabled.

Now to the tricky questions:

  • What happens when a shadow ray does not reach the light source, but is blocked by a surface? Is it discarded? Or the path continued by creating a new ray with one of the methods above? Backtracked to the last surface and creating a new ray from there?
  • When does the Light Path node set the Shadow Ray flag? When a shadow ray hits a surface? Or already one bounce before, implying that the sampler decidey to create a shadow ray before evaluating the material? Can it only be found set when evaluating a lamp material (or a surface with an emission shader)?
  • Do Shadow rays still get one of ‘Reflection Ray’ or ‘Transmission Ray’ set?
  • What happens when a shadow rays hits a transparent material? Is the Shadow Ray flag still set after the transmission?
  • What happens when a shadow ray hits a semi-transparent material (transparent shader mixed with something else)? Normal path continuation? Always picking transparent passthrough with intensity weighted with the transparency mix factor?

I could go on with a few more questions along these lines, but I guess you got what I’m interested in. Any insights into the matter are welcome.

I might post a blend file with results I find counterintuitive in a few days (I’m on travel).

What happens when a shadow ray does not reach the light source, but is blocked by a surface? Is it discarded? Or the path continued by creating a new ray with one of the methods above? Backtracked to the last surface and creating a new ray from there?

Assuming the object is not transparent, the shadow ray is discarded and the shading point that spawned it is considered to be in shadow from the light that shadow ray was cast towards.

When does the Light Path node set the Shadow Ray flag? When a shadow ray hits a surface? Or already one bounce before, implying that the sampler decidey to create a shadow ray before evaluating the material? Can it only be found set when evaluating a lamp material (or a surface with an emission shader)?

It’s only for objects that block a shadow ray. Shader branches under “is shadow ray” only get evaluated when their object blocks a shadow ray.

Do Shadow rays still get one of ‘Reflection Ray’ or ‘Transmission Ray’ set?

AFAIK, no. Not completely sure on this one, but I believe glossy or transmission hits do not start shadow rays the way diffuse hits do.

What happens when a shadow rays hits a transparent material? Is the Shadow Ray flag still set after the transmission?

A new shadow ray(still has the flag) is started from the transparent object to continue the path. This continues until the chain either reaches the light, or is blocked by an object that does not have transparent shadows enabled.

What happens when a shadow ray hits a semi-transparent material (transparent shader mixed with something else)? Normal path continuation? Always picking transparent passthrough with intensity weighted with the transparency mix factor?

This one I’m fuzzy on. For a single transparent BSDF with a non-white color, I want to say it’s continued like it would be for a fully transparent surface, but the result is then attenuated by the color of the transparent BSDF. For a transparent/non-transparent mix with a mix factor other than 0 or 1, I forget what happens, tbh. I want to say it picks one at random, but I think that would result in noise in the transparency which I don’t recall seeing.