6
$\begingroup$

I have a Blender project that I am trying to make replicate how old video games worked.
What I am working on has an artificial shadow for an object. The shadow is a plane that is supposed to snap to the surface of the ground.

The red circle indicates the shadow object and the yellow circle indicates the object the shadow is supposed to follow. How can I make the shadow move to the surface of the checkered object while following the X and Y location of Suzanne?

What I am trying to do

$\endgroup$

2 Answers 2

12
$\begingroup$

Sorry, this will be a long one. But I will give you two methods to choose from. So if I understand you correctly you want something like this:

following shadow

Starting with a mesh object as shadow as this is what it seems you want to do. For a (in my eyes simpler and more reliable) method to do this in the floor shader, look further below.

Mesh object shadow

First of all, the plane that acts as the shadow has to be bound to Suzanne with a Copy Location constraint just like @Chris said, with X and Y enabled and Z disabled.

copy location

Then, to have the shadow stick to the ground and taking the geometry below into account, it cannot be a simple plane with a single face and four vertices, so I subdivided it a few times and gave it a Subdivision Surface modifier as well.

Next, I added a Shrinkwrap modifier to it. I used Wrap Method > Project and Snap Method > Above Surface (although I guess On Surface or Outside Surface should work here as well), chose Axis > Z and the floor object as Target.

shrinkwrap modifier

Now to make the shadow not intersect with the floor, you could enter some value > 0 in the Offset field. However, the problem is - and no offset can change that, only an infinitely high resolution - at vertical (or very steep) walls that there is one part of the shadow mesh projected onto the higher surface and the other part onto the lower surface. But the edge between high and low vertices crosses the wall and you would have to give a very high offset to avoid that:

projection vs vertical walls

The only solutions to this problem are either accepting that the floor can sometimes peek through the shadow or reducing (but not completely eliminating) the amount of cutting through by giving the shadow an even higher resolution. If this is still not acceptable, you could - instead of having a totally flat shadow - give the shadow plane a Solidify modifier. Not the best solution for a shadow, but with the correct settings you can get rid of the floor showing through.

highres + solidify solidify modifier

Floor shader method

Another relatively easy way to do this would be to get the location of Suzanne into the shader of the floor material, and then either (for a circular shadow) set Z to 0 and use X and Y to calculate the length of the vector or (for a rectangular shadow like the plane) take the maximum of X and Y, then for both versions take a Math node set to Greater Than to define the size of the shadow.

To do this, put a Texture Coordinate node into the shader to use the Object output, referencing Suzanne as Object.

Plug the coordinates into a Vector Math node set to Absolute (actually only necessary for the rectangular shadow), then Separate XYZ and then

  1. for the circular shadow, use a Combine XYZ node with the original X and Y values and Z = 0 and plug it into a Vector Math node set to Length,

  2. for the rectangular shadow, plug X and Y into a Math node set to Maximum.

Afterwards get a Math node set to Greater Than and the Threshold defines the size of the shadow.

The result is a black and white output with black for the shadow and white everything else. This can be used as a mix factor, for example in a Mix Shader where you leave the first Shader input empty to get a pitch black shadow and in the second input you plug the original material of the floor.

Nodetree:

shadow shader following object

And these are the shadows:

circular vs rectangular shadow

Of course, other than with a mesh object as shadow, you do not have to make a shadow with a hard edge - if you plug a Color Ramp in there instead of a Greater Than node, you can get a shadow where you can control the softness of the border. But the size of the shadow is limited to a maximum of 1, because the Color Ramp is limited to the 0 to 1 range. So additionally you can plug a Map Range node before that to map any range from 0 to some positive value to the 0 to 1 range. In this case the From Max value can be used to change the size of the shadow.

Nodetree with Map Range for a circular shadow:

color ramp nodetree

small vs large shadow

But that is just the beginning, you can do much more with this mix factor. Here are just a few examples, in this case with a hard edge shadow but of course this works with a soft edge as well:

  1. No need for a pitch black shadow. Use a Mix Color node to multiply the original color with the shadow. The Factor determines how dark the shadow will be.

    darkening nodetree

  2. Or you could have a colorized shadow by multiplying the floor material with a color and using the shadow as Factor. In this case I set the Math node to Less Than to make the shadow white, otherwise the floor will be colorized except for the shadow area.

    colorizing nodetree

  3. Or do something completely different and give the floor a completely different material by using the shadow as mix factor between those two. In this example im just mixing colors, but with a Mix Shader you could switch between two completely different materials.

    mixing nodetree

And here are examples for the nodetrees shown above:

shadow mixing examples

$\endgroup$
1
  • 1
    $\begingroup$ An excellent example of answering not only the question the OP has, but their real issue. Well done. $\endgroup$
    – David
    Apr 12 at 13:32
2
$\begingroup$

just add an object constraint to the plane -> copy location and choose suzanne as target. Uncheck the z component.

Note: this only follows xy as you asked for. It won't be the "right" shadow on your box though....

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .