Artisticrender is supported by its audience. When you purchase through links on our site, we may earn an affiliate commission.  Learn more

Erik Selin
Erik Selin

3D artist & all that other stuff

Share on facebook
Facebook
Share on twitter
Twitter
Share on pinterest
Pinterest
Share on reddit
Reddit

How the light path node works in Blender

The light path node in Blender has always been mysterious to me. While I have found it useful, many times I have not fully understood what it does or how it does it. To finally demystify it, I studied it a bit to learn how it works.

Hopefully, this article can help you learn what I learned about the light path node quicker. 

What is the light path node in Blender? As we render, rays are cast into our 3D scene from the camera. As these rays bounce around in our scene, they get tagged as different types of rays. The light path node allow us to access this data and manipulate our material based on these ray types.

I have limited this article to only discuss the different ray types and corresponding outputs on the light path node. This is the seven first inputs in the node.

What is the light path node?

The light path node is a node that we can use when creating materials for Cycles or Eevee in Blender. It is more feature rich when used in Cycles, but some outputs from this node is also usable in Eevee.

We will explain the node from a Cycles perspective since it is easier to understand the underlying concepts that we need to know about using the light path node effectively.

The light path node can seem mysterious at first. But what it enables us to do is to break the physics of how materials behave based on how we see the material.

That is mysterious indeed.

For example, we can say that when a material is viewed through a mirror, it will look different from when we view it directly.

We can also use the node for performance optimizations or to change the color of shadows and improve our glass materials by combining glass with transparency. 

To understand how it works, we have to understand something about render engines. Therefore, we will start with a somewhat simplified explanation of a render engine itself, and we will use Cycles as the example.

How does a ray tracer work?

Cycles is a ray-traced engine. This means that to figure out what color each pixel should have in the final image we shoot rays from the position of each pixel into our 3D scene and let them bounce around and gather data about geometry, materials and lighting conditions. 

We shoot many rays for each pixel since they often bounce in random directions, and we need a large enough sample count to approximate the color each pixel should have.

As a ray bounce around in the scene, it will hit different things. We call each hit a bounce. On each bounce, a few things are tested. 

One of those things that are tested is what we hit. Geometry? A light? Maybe the background.

In most cases we will probably hit geometry. If we hit geometry, the material for that surface will be analyzed. Depending on the components of that material, the ray will behave in different ways.

If it is mainly a diffuse material, it may bounce in a random direction. But there may be some glossy component making a certain number of the rays shot bounce in a more predictable outgoing angle.

As a ray bounce around, the ray itself also carries some information. The information we care about is what kind of ray it is. But also the ray travel distance or how many bounces it made so far.

Depending on where the ray is coming from it has one or more tags attached to it telling us what kind of ray it is. A ray can be one, or multiple types of rays at the same time.

We know that we send many rays for each pixel that bounce around in our scene. What this means is that we send light rays from the position of the camera rather than the lamp. This is a key element to understand.

As we continue to explore ray types and what we can do with them, we will also explore how we gather information with a ray and what information comes from where. In short, we gather information for each bounce. 

But only rays that are shot from a certain pixels’ perspective can contribute to that pixels color. That is another key piece of information.

If a ray hits geometry, the material is analyzed, and the ray behaves according to the material node tree.

Rays get tagged differently depending on the last surface they hit.

We will now explore each ray type in more detail in the order they are listed on the light path node.

Camera ray

When we shoot a ray from the camera, we consider it a camera ray. That means that all rays start out as camera rays.

We can also say that a ray is tagged as a camera ray when we can see something directly.

When the ray hit something, producing the first bounce, it drops the camera tag and picks up a new tag depending on what it hits. 

Let’s look at an example:

Here, the camera sees the blue object directly. The rays coming from the camera uses the lower socket of the mix shader since “is camera ray” is true, translating to the value 1. 

When we analyze the floor though, we can see that the bounce light from the cube is green. Something to be aware of here, is that the pixels on the floor don’t get a green tint because a camera ray first hit the cube and then carries information with it to the floor.

Instead, it is the rays we cast directly onto the floor that then bounce to the cube that gives the green tint. As the rays come from the camera and bounce on the floor, they drop the camera ray and become diffuse rays since the floor is a white diffuse material.

As some rays then hit the cube, the material is analyzed and since the incoming ray is not a camera ray the “is camera ray” is false and the green diffuse shader gets returned instead of the blue one.

A key takeaway here is that a ray does not hit and take material information with it to its next destination. Instead, it bounces and sends information back to previous points it hit.

If the rays was cast from the light, the flow of information would be reversed from the rays perspective, and we would bring information to the next bounce until we reached the camera and could display the correct color for the given pixel.

This can be a bit confusing since we often talk about the bounce light as coming from the light hitting the cube and bouncing off the floor and into the camera, like it does in the real world. But in cycles, it is the opposite. We bounce on the floor, land on the cube, and send information back to the spot on the floor to get the correct color for the pixel showing this area.

Make sure you understand why the indirect light on this cube is green and in what direction the rays are traveling before you continue reading. It can get very tricky to understand other ray types if we are not clear about this.

We are just about to enter the next piece of complexity, the shadow ray. You see, each bounce splits the ray into an additional ray called a shadow ray.

Shadow ray

When a ray bounces, a shadow ray is split off from the original ray. The shadow ray is a simpler ray that always bounce toward a random light source instead of taking the material into account.

If the ray can hit the light directly, we know that the spot we bounce from is directly lit by this light source. However, if we can’t connect directly to the light, we are in shadow from this light. 

With enough shadow rays and the information about each light, we can learn how much light hit each spot in our scene.

So how can we use a shadow ray and what can we do with it in our material? Well, we can color our shadows.

To change the color of a shadow using the shadow rays, we use the transparent BSDF shader to tint or completely change the color of a shadow.

We can also use a texture with our transparent shader.

So how does this work? We can say that the light path node changes how an object look to its surrounding.

In our camera ray example, the cube looks blue to the camera ray. But to the floor, the cube looks green.

For our shadow ray the cube looks transparent and therefore contributes to the color of the shadow. If we set the transparent BSDF to white, the cube will be fully transparent to the shadow ray and therefore won’t cast a shadow.

You can also try to use a glass shader to see how the shadow change if the cube is viewed as glass by the shadow.

Let’s now continue to the diffuse and glossy ray even if we kind of covered diffuse already.

Diffuse and glossy ray

So, we just expanded our view on rays by saying that an object with a light path node in its material can look different to it’s surrounding based on the incoming ray. This means that a diffuse material may view this object in one way while viewed directly by the camera it may look very different.

Same for the shadows rays even if we need to introduce some kind of transparency to see a real effect here.

We earlier also explored the diffuse ray, and it is pretty easy to understand as long as we know the direction of the ray and how information travels back from one bounce to another.

The materials we have here are sharp and glossy. Meaning roughness set to 0 on the left side, a rough glass surface on the right side and a glass material in the middle.

It may come as no surprise that both glossy surfaces become green. But what about the glass shader? The glass shader actually contains a glossy component. Remember how we said that light rays may carry more than one “ray type”. The glass shader is such an example. It carries both a “glossy ray” tag and a “transmission ray” tag.

We covered the diffuse ray as we looked at the camera ray. But we never tested the diffuse ray output from the light path node. Therefore, I just changed from the glossy ray in the example above to the diffuse ray to show you what it looks like.

You can see that the only place we have diffuse rays is when a ray bounce on the floor up on the cube, sampling data and use that information to determine the indirect color of the floor.

Singular reflection and transmission rays

The ray types we have left to learn about are singular reflection and transmission.

Before we continue here, keep in mind that these ray types are only available in Cycles and not in Eevee.

We will start with the singular ray. This is a ray that does not have any randomness in its output angle. This means it correspond to a mirror reflection. A diffuse ray can bounce in any random direction and a glossy ray with roughness will have some randomness to it, giving it the roughness effect. 

But a singular only has one possible bounce angle, making the surface a perfectly sharp reflection.

Here I adjusted the glass material and gave it some roughness. If a glass material has zero roughness, it will also be considered a singular ray and see our cube as green.

The glass shader can be tricky here. In this example it has the default IOR of 1.45 and a roughness of 0.1. But if we put the IOR to 1.0 it does not matter what the roughness is. The ray will still be considered singular.

With any other IOR and 0 roughness the ray will still be singular. But as we move the roughness slider it will once again become rough and not singular ray.

The only material with a completely sharp reflection in this case. In the right mirror though, we can see a reflection of a green cube. This is because the reflection in the right mirror is a reflection from the left sharp mirror. 

The lesson to be learned here is that even if something continues to reflect in further bounces, the data gathered in further bounces still stick.

Let’s now look at the reflection ray.

Here we see that the glass material is still red and therefore not considered a reflection. But both mirrors reflect a green cube and the bounce light on the floor is also green.

This means that both diffuse rays and glossy rays are also considered reflection rays. But only for opaque surfaces. In case of the glass material, it is not a reflective material. Instead, it is transmissive. Either reflection or transmission is not affected by the sharpness of a glossy component.

And that leads us to the transmission example.

Here we have the opposite effect. The glass now views the cube as green while the rest of the scene view the cube as red. 

We can also use some math nodes further select what kind of rays we want to be affected by the light path node. Here is an example.

Here we take all glossy rays and subtract the rays that are also transmission rays. This leaves us with opaque glossy surfaces. Then we subtract the singular rays leaving only glossy surfaces with some amount of roughness on them.

Final thoughts

The light path node can seem complex at first but once you dig deeper into how it works you can start to demystify it. We did not cover everything about it here but this will server as an introduction not only to the light path node but also to some basics of ray-tracing.

If you find this kind of content useful you can subscribe to the newsletter below and if you think others may benefit from this please consider sharing.

Thanks for your time.

Get our free workflow cheatsheet!

Join our newsletter and get updates of our news and content as well as our 3D modelling workflow cheat sheet.

More to explore

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.