51
$\begingroup$

In most of my models, I usually end up setting a world background using an HDRI image of some kind or another. This has always been really useful for lighting in general or as a background for my final render.

But what if I want my model to look like it is interacting or touching part of the background? For example, in the image below that I found, the modeled objects look like they're part of the scene, and even appear to cast shadows on the ground. How can I do this?

...

$\endgroup$
1
  • $\begingroup$ Can you accept the cycles answer instead of my BI one so it gets seen first, thanks. $\endgroup$
    – iKlsR
    Commented Jan 6, 2019 at 17:21

3 Answers 3

39
$\begingroup$

One quick way to achieve this using Blender Internal is to select the plane and add a new material, in the material settings under shadow, enable Shadows Only.

enter image description here

Next, you can optionally enable transparency, use Z Transparency and use the alpha slider to control the strength/darkness of the shadow.

enter image description here

To further enhance this and add to the realism, you can enable Ambient Occlusion and use a blend sky (for simple renders). It is also worth noting that the shadow you get is dependent on the type of lamp and world settings you use in some cases, in the image below I am using a sun lamp with ray shadow enabled and I also have Environment lighting turned on, this softens the shadow and its harder to control but gives a nicer subtle effect.

enter image description here

Here I am using a sun lamp and a point lamp with Environment lighting off, with this setup, I can easier adjust the opacity of the shadow with the transparency setting.

enter image description here

Finally, in a case like you describe above, just render the scene without the sky (untick sky under the scene tab), align the camera as best as you can to the angle of the background, render and use an Alpha Over node to join the render and the background together. Here is a quick example I did in a few minutes.

enter image description here

With HDR lighting and some tweaking, this can look really good. It's a bit tricky depending on how you want to use it and at times it will take a good amount of tweaking to get it to look 'right' but this is a sure way to go about it, the ground plane still catches the shadow but it is invisible.

$\endgroup$
5
  • $\begingroup$ iKlsR is right. Shadow-only textures will do the trick. Adding a floor will do wonders. If you want shadows to have additional play with other things in the scene -- e.g. people and buildings -- then camera mapping will go a long way. Andrew Price explains it flawlessly in his Camera Mapping tutorial and again in Part 2 (an updated one). $\endgroup$ Commented May 31, 2013 at 8:48
  • $\begingroup$ And shadow only textures simply can't be done (as of 2.77) in cycles. That means cycles is... Better, right..? $\endgroup$
    – yPhil
    Commented Jul 21, 2016 at 16:46
  • $\begingroup$ @philipyassin huh? $\endgroup$
    – iKlsR
    Commented Jul 21, 2016 at 16:47
  • $\begingroup$ @iKlsR blender.stackexchange.com/questions/58342/… $\endgroup$
    – yPhil
    Commented Jul 21, 2016 at 16:54
  • $\begingroup$ Updated link to version 2 of the camera mapping tutorial: blenderguru.com/tutorials/camera-mapping-tutorial-v2 $\endgroup$
    – Jacob
    Commented Jun 7, 2020 at 18:17
56
$\begingroup$

CYCLES ENGINE

Shadow Catcher

Starting from version 2.79 any mesh object can be set as Shadow Catcher.
Select object (like a Plane) and check this option.

  • 2.79 located in Properties Editor > Object > Cycles Settings
  • 2.8+ located in Properties Editor > Object > Visibility

enter image description here


Issue of current Shadow Catcher

Shadow Catcher can receive only shadows (limits are nicely summarised in this DevTalk) So I will keep Shader method, that can be used to "catch" also emission, indirect light or reflection that gives more sense in term of merging CG into image. Comparison ...

Example of Shadow Catcher issues -/- comparison with Shader solution ... see ground that doesnt catch emmisive rays and metal sphere reflects white plane ...

enter image description here

enter image description here

Edit 2021-05-05 Finaly movement :) Emmisive rays are calculated, but reflections and other mentioned above is still missing. So here is the shader solution for now ...


Shader for HDRi Environment

  • This material for ground plane object can also receive lights, indirect light or reflection.

  • This material gives you precise feedback if the HDR image lights correctly. If not, ground plane will be brighter or darker (or will tend to be a different colour tone) depending on image color deformation.

Material for ground (plane) is Diffuse shader with assigned Environmetal (Equirectangular) HDRi texture. The same texture used for World. The trick here is to use "Reflection" texture coordinates with negative Z value (-1). For smaller color differences between found and environment use RGB node.

enter image description here As enhancement you can sync HDRi rotation. Just right-click on Z Rotation of World's Mapping node, choose Copy as New Driver and Paste Driver here in object ground material's Z Rotation (value becomes violet). Now when you change orientation in World material it will be copied to ground material too.

Showcase https://vimeo.com/159234378
For more examples and tests check out this Blenderartists thread.


Lighting by HDRi

is another topic, so just a quick tips. Use this World node-tree ...

enter image description here Update for 2.9x (increased Divide node to move Mix node slider smoother).

Basic Color Correction

  • adjust Factor of the first Mix node (should be enough)

Shadows
If lighting seems to be ok, but shadows are still too sharp/soft the best way is to fix the HDRi image manually in some image editor supporting 32-bit images, select pixels in place of sun and decrease/increase exposure.

To affect shadows directly in blender you can try to add Multiply (Math) node before Divide (Math) node and adjust node-tree in this order:

  • first adjust value of Multiply (Math) node to affect shadows
  • change color of second Mix node to merge environment exposure
  • under Render properties > Color Management increase Exposure to bring general light appearance back
  • in case ground tint color doesn't match - add RGB Curve node to correct tint manually

Extreme example enter image description here

Rendering – Be sure "Multiple Importance" is enabled in World Properties panel (value like 840), it should be checked by default.


Shader for Backplate (2D image)

In case you want to merge your CG with the backplate, simply use "Window" texture coordinates for shadow / light receiver. This material doesn't have a geometry limitation. In this example, a plane is used also, but it can be any shape. Scene is lit only by a sun with strength that brings ground image to background colours. Both previously mentioned benefits (shadow/light receiver and in this case general feedback of correct lighting) works here too. Disadvantage of backplate (compared to equirectangular HDRi image) is lighting inaccuracy and missing reflections.

Note: the same node tree is used for the world.

enter image description here


Note: There exists OSL shader QUIP and QUIPCam for this purpose that gives you the ability to have a bit of movement in the environment too. But OSL isn't supported for GPU calculation and takes quite a lot of time to get a clean render.

$\endgroup$
7
  • $\begingroup$ Thank you for this answer. Your example was very userful for me :) $\endgroup$
    – Ant4res
    Commented Aug 14, 2015 at 20:55
  • $\begingroup$ When it comes to envmaps - do you have any method control how hard/soft env light is? $\endgroup$
    – user92
    Commented May 24, 2016 at 13:45
  • $\begingroup$ I'm gonna sound very stupid, I'm afraid. I read the whole BE thread, watched the videos several times, and I can't, for the life of me, figure out where this "HDRI" image texture file comes from. $\endgroup$
    – yPhil
    Commented Jul 21, 2016 at 13:28
  • $\begingroup$ OK, so no one is going to tell me where is this HDRi image file, or why do I need it just to hide the shadow receiving plane in my video? Come on, tell me, this unreproducible answer is a joke, right? $\endgroup$
    – yPhil
    Commented Jul 21, 2016 at 16:56
  • 1
    $\begingroup$ @yPhil The "HDRi" in question is the same as the world's environment texture. If you don't have an environment texture you will have to use a different method to hide the plane. $\endgroup$
    – Fax
    Commented Jun 30, 2018 at 21:26
8
$\begingroup$

I'll probably get myself defrocked for this because what I'm offering is more an alternative to shadowing because it's so easy to achieve and is completely independent of Blender's lighting restrictions, quirks etc.

The method is kindergarten level, crude even, but it works!

enter image description here enter image description here enter image description here enter image description here

It's entirely flexible and has the added advantage of being able to assume any shape a storyline demands. It can even move independently of its 'master', take on a life of its own!

Shadows -

The system uses a 2D alpha layered plane textured with the shadow movie or a still frame when no animation is involved. This is laid at the actor's or object's 'feet' and parented to the same empty that's propelling it forward. (for stability)

It can just as easily be placed on a wall, or bent half between!

Shadow movies can be blurred in the VSE when a sharply defined version isn't desirable, the plane textured with that instead.

They are also rendered using OpenGL and with no lighting. (Black on transparent)

A shadow is photographed/filmed as with any movie, capturing the actor's movements, but holding it (the actor) stationary. I find it easier to either duplicate the Blend file and do the shadow in that, or create a new scene and copy paste (append) the actor into it, animation and all. In the shadow Blend file all lighting is removed so you end up with a black figure doing its thing on an alpha layered background.

The examples above were rendered using OpenGL as png files, one for each frame and with the "RGBA" button pressed for the alpha layer.

I'd recommend setting up a fixed camera for this. It will give you somewhere stable to come back to, should the need arise.

The cam is usually placed at a position that gives the best results for the job. This isn't necessarily from where the scenario's lighting originates.

More often it can be at its 'compass' direction only, and at a height and angle to suit. In the Plant example, the shadow sequence was taken from about mid plant height and perpendicular to them.

The walking sequence was taken from directly behind and with the forward motion disabled. i.e. animated but stationary. Whatever 'stretching' is needed for the shadow's projection, is achieved by scaling the plane in that axis. Keyframes can rescale as necessary.

The craft taking off was just a still alpha layered 'photograph' to get its basic shape from the sun's angle. (It was not intended for this particular background photo)

The shadow plane was parented to the craft.

When the craft takes off and rotates, so too does the plane, so its Z height has to be held at its original setting. To add realism the width of the plane was scaled down with a keyframe or two to more accurately reflect the sun's projection angle.

Where more complex distortions might be required, shape keys can be called upon. (See the EDIT below)

-=================-

EDIT 10th Aug 2022

EDIT 10th Aug 2022 -

Added a fourth clip above...

The last video shrink-wraps the shadow plane so it follows 'terrain'. (the hump in the floor)

It also encounters a wall and behaves accordingly. For that, a duplicate of the plane was added and placed vertically under the floor. It's ascent is tweaked to match 1st.

$\endgroup$

You must log in to answer this question.

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