1
$\begingroup$

I was trying to fade shadows out and found animated shadow fade on Blender StackExchange.

In the setup described above, shadow rays are multiplied by a factor, and that's applied to the factor on a Mix Shader that uses 0 for a Diffuse shader and 1 for a Transparent shader. You can animate the amount of shadow casting by animating the multiplication: 0 means cast shadows, and it fades up to 1, where it doesn't cast shadows. I duplicated that in a material that's normally blue, as in the screenshot below.

Nodes to not cast shadows

I found that counterintuitive, and wanted to switch the multiplication value so that 0 meant no shadows, and 1 meant regular full shadows. "No problem! Just swap the Mix Shader inputs so the Transparent is on top, and Diffuse is on bottom! Like the red material in the screenshot below.

Nodes to reverse shadow factor

That does eliminate the shadow at 0 and show it at 1, but the object is completely transparent. The screenshot below shows a scene with two cubes that would normally cast shadows to their LEFT. The left, blue cube is not casting shadows, with multiply of 1, as expected. The right, red cube casts faded shadows on an inverted factor, as desired, but is unexpectedly completely transparent.

Unexpected results

Obviously my understanding is flawed. Can someone explain this effect to me?

$\endgroup$
5
$\begingroup$

Before giving you the solution, you need to understand somethings from Cycles..

When a ray from the camera is thrown to the scene, this ray will be tagged with 'is_camera_ray'! As soon as the ray hits some object in the scene, a bunch of other rays are created, depending on the type of shader that object has (glossy rays, diffuse rays, etc).

enter image description here

Cycles first tries to check if the sample point on the hit object is illuminated by some light, so it throws a shadow ray directly to each light.

If this shadow ray hits another object before hitting the light, then you get a shadow of the second object in the first object.

The exception to this result is if the second object has a Transparent shader in it.

This will let the ray to continue its path to the light, and in return, the amount of light is multiplied by the transparent shader color.

This means that a transparent shader with a full white color will let all the incoming light to pass through the second object and the sample point in the first object will be fully illuminated.

Having a (0.5, 0.5, 0.5) color in the shader, will block half of the incoming light, and a transparent color of black, will block all the light in that path, which is the same behaviour of all other shaders.

Now, having a Transparent shader in the node_tree will also make it transparent to all other rays, inclusive the camera rays. To avoid this we make a switch from original material to a transparent shader only when the ray is shadow ray.

That's why we don't multiply the is a shadow ray by anything, as we want the transparent behaviour for shadows (1) and normal behaviour for everything else (0).

If you multiply the is shadow ray by 0.5, it just means that shadows rays will see 50% the top shader, and 50% the bottom shader, while all other rays will only see the top shader. enter image description here In this situation, any shadow ray will put a 1 in the is shadow ray output, which will make the Mix Shader node to output the Transparent shader instead of the Diffuse shader (which is the one visible to any other types of rays).

Since the Transparent shader has a color of white, the light will simply pass through and no shadow will be produced. Changing the transparent color will change the amount of light (and coloring it).

Solution: Just animate the color of the Transparent shader.

read more in docs.blender.org

$\endgroup$
  • $\begingroup$ Certainly cleaner than multiplying a boolean, when that's not strictly necessary for brevity. $\endgroup$ – Robin Betts May 8 at 13:36
  • $\begingroup$ Thanks for the clear explanation. It's gonna be pretty easy to animate the color, too. $\endgroup$ – Judebert May 8 at 22:52
  • $\begingroup$ It also makes it clear that inverting the multiplier on the isShadowRay just causes ALL rays to be not shadows at 0, and then applies the Transparent shader to them. $\endgroup$ – Judebert May 8 at 23:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.