# Cycles' Pathtracing and Ray Numbering

These days I’ve read in the book “Cycles Encyclopedia” written by Steinmetz and Hofmann about the pathtracing calculations und counting of the redirected rays.
To examine the behaviour of Cycles, I’ve created two scenes that are attached below to this post.
Additionally I’ve watched the presentation “Cycles Light Path Magic” by Frederik Steinmetz at the “Blender Conference 2015” (https://www.youtube.com/watch?v=NGqzbGAT6wQ)
In this video I especially want to point at the explanations about “Shadow Rays” (4:50 to 7:07) and the comments about the extensive tests by Steinmetz and Hofman concerning the “Light Path Node” (22:46 to 23:54) in the context of their research fort the “Cycles Encyclopedia”.

Following the “Cycles Encyclopedia”, the counting oft the rays begins with “0”. That’s why setting all bounces to „0“ under “Light Paths” still causes one bounce to be calculated. Prior to each bounce, one “Shadow Ray” is sent into the direction of a randomly selected light source and afterwards – in case of a mix of several shaders – one shader is randomly selected
(with respect to the probability defined by the mixing ratio of the shaders). This selected shaders serves for the “Evaluation of the Shader”, that is for determining, whether the “Shadow Ray” inside the scope of the ray directions allowed by the shader or not. If the “Shadow Ray” is outside this scope, it is ignored, otherwise the brightness of the „Shadow ray“ is multiplied with the probability of its direction and the resulting value is saved as the contribution of this ray sample to the brightness of the whole pixel that is sampled.
If a ray after its last bounce hit another surface, no “Shadow Ray” is sent, which makes sense, because no shader is used, that could serve for the „Evaluation of the Shadow Ray" Anwendung finden könnte (see “Cycles Encyclopedia”, p. 36, fig. 1.24).
If you want to know, how many “Diffuse Bounces” are maximally calculated, you need to add „1“ to the value set in the field labeled “Diffuse”.

I have some questions concerning the behaviour of Cycles in the test scenes mentioned in the introduction of this post. I couldn’t find answers despite intensive research.

>>>>>>>
>>>>>>>
SCENE 1: File „2GlossyPlanes_1DiffuseGround.blend“ [please set the left window to „Rendered Viewport Shading“]

SCENE DISCRIPTION: Two orange mirrors directed frontally to each other are standing on a diffuse white ground plane. A point lamp is located in the middle. The world background is set to a dark gray.
The values for all Bounces-in the panel “Light Paths” are set to “0”, except “Bounces Max” has the value “1”.
The light source is reflected In the mirror visible in the left viewport-window („Rendered Shading“). You can prove that this a “Glossy Bounce” by deselecting “Glossy” in the “Ray Visibility” of the point lamp.

TEST DISCRIPTION: Augmenting “Bounces Glossy” to “1” makes the reflection of the light source in the second mirror (located outside the left viewport window) and the diffuse ground visible.

The first result meets my expectations, since the setting of “Bounces Glossy” to “1” allows two “Glossy Bounces” ("Glossy

Bounce #0" and “Glossy Bounce #1” according to the „Cycles Encyclopedia“ by Steinmetz and Hofman.
In contrast to this, it astonishes me that the diffuse ground plane becomes visible after augmenting the value of "Bounces Glossy“: The ray starting from the camera is first submitted to a “Glossy Bounce” on the surface of the mirror that can be directly seen and afterwards to a “Diffuse Bounce” on the ground plane before it reaches the point lamp.

Since Steinmetz and Hofman mention in their „Cycles Encyclopedia“ that the ray numbering starts with “0”, there should be already with
“Bounces Diffuse” set to “0” und “Bounces Glossy” set to “0” one “Diffuse Bounce” and one “Glossy Bounce” at disposal and therefore the diffuse ground plane should be already visible in the first mirror.

An additional question: Why does “Multiple Importance” fort the point lamp make the reflection of the lamp invisible in the mirror but not on the diffuse ground?

ATTEMPT TO EXPLAIN: Perhaps, it’s always the shader first used in a light path that is relevant for the shader type fields under “Bounces”, even if other shader types follow in the light path.

At least it seems to be necessary the value “1” for the shader selected at the beginning for the following shader in the light path to have an effect.

>>>>>>>

>>>>>>>
SCENE 2: File 3TransparentPlanes_2GlossyPlanes_1DiffuseGround.blend [left ground window set to „Rendered Viewport Shading“.]

SCENE DISCRIPTION: Two mutually mirroring glossy planes are visible through three transparent planes with a slight grey shading
A point lamp is in the middle. The word background is set
to a bright green. “Transparency Max” and “Bounces Max” in the panel “Light Paths” are set to three, “Bounces Glossy” to “2”, all other bounce to “0”.

TEST DISCRIPTION:
If you set the value “Transparency Max” to “2”, the render setting of “Bounces Max” set to “3“ is overwritten in the area of the transparent planes in the viewing axis so that the view through the 3 transparent planes only allows the bright green background to shine through, whereas the diffuse ground plane and the two mirrors are displayed in black. Despite “Bounces Max” set to „3“ und „Bounces Glossy“ set to „2“, there is no „Glossy Bounce“
at the glossy plane behind the 3 transparent planes, so that no “Shadow Ray”
is sent out, too. Despite this, the background (with „Transparency Max“ set to „2“) shines through the overlapping areas of the 3 transparent planes, because it counts as light source.
With „Transparency Max“ set to „1“, the bright green world background is (among others) blocked at the rearmost transparent plane in the area of the overlapping oft he 3 transparent planes, because the maximum number of 2 bounces has been reached with the “Transparency Bounces” number „0” and „1" so that there can’t be any bounce (that means: no transmission) and in consequence also no “Light Sampling” through a “Shadow Ray”.

ATTEMPT TO EXPLAIN: For scenes without transparent planes you use the setting “Bounces Max”, for scenes with transparent planes, the setting “Transparency Max” determines the maximum for all ray types in the image areas covered by these last mentioned planes.

REMARKS:

1. Concerning “Transparency Bounces” also see „Cycles-Encyclopedia, p. 199, fig. 14.8).

According to the Blender online manual (https://docs.blender.org/manual/en/dev/render/cycles/settings/scene/render/light_paths.html?highlight=light%20path), the ray type doesn’t change when passing a transparent surface.

1. The more I’m researching the more confusing things appear to me. The terms “Direct/Indirect LightSampling”, “Multiple Importance Sampling” und “Shadow Ray” seem to be defined differently by blender users in different internet-forums. Is there anybody here familiar with the programming of Blender? Maybe Brecht van Lommel could give some insight to effects caused by the bounces settings in Cycles under “Light Paths”.

Although I’ve already searched the source code of Blender 2.77 with Notepad++, I haven’t yet found any source code comments answering my questions, particularly as the comments of the source code parts I’ve looked at, were very short. But maybe, I’ve only searched the wrong terms. Where should I look at? Is it possible to completely turn off the calculation of “Shadow Rays”? I mean with that the calculation itself, not making individual objects invisible by deactivating the according option under “Ray Visibility”.

1. I think it could also help to review the Blender online manual in order to help Blender users to better understand what’s happening „under the hood“ of Cycles‘ pathtracing. The explanations there are still a little bit to general.