Forum rules - please read before posting.

2D camera and character shadow

It's been two days since I'm looking for information about the shadow of the character.
The environment is 2d, screen space and 3d character.
The problem is that the plane positioned in front of the 2d background does not become transparent (with 2D camera).
I've tried MatteShadow taken from the AC 2.5d tutorial but also FX_Matte Shadow, Custom_ShadowDrawer, InvisibleShadowCaster, Selfmade_TrasparentShadowReceiver (unity forum) and a combination of them in the Mesh Renderer and Shader of the Plane.
Whatever I do if the plane is visible there is the shadow of the character if the plane becomes invisible (thanks to scripts) there is no shadow.
What is a 2.5d game without the shadow? And how is it possible for an engine as unity to have these limitations when an old Wintermute has no problem in this regard and the engine was written by a single person and not by a team?
Does anyone have any idea how to make the plane transparent but allowing the shadow of the character? I can not use the AC 2.5D camera because of some limitations.


  • edited November 2017
    I tried to use a 3d camera but the problem remains, but if I use a 2.5d camera, the plane is not displayed as right.
    I finally tried to create a mesh with 3ds max by setting Pathfinding as Mesh Collider but the mesh remains visible when it shows the shadow.
    A question in this regard. I looked again at the Creating 3D game tutorial and there is a particular thing I do not understand.
    The New 3D scene section shows how to use the mesh.
    The NavMesh setting displays Disable mesh renderer as selected and the NavMesh shader as Unlit / Texture. Cast Shadows and Receive Shadows are selected.
    But if Disable mesh renderer is active why TinPot has the shadow?
    In the 2.5d tutorial it is said to uncheck Disable mesh renderer to have the shadow.
    So in the case of the 3d tutorial where does the shadow come from? Maybe from the mesh when it was built?

  • edited November 2017
    Shadows in the 3D tutorial come from the set mesh - it's nothing to do with the navigation mesh.  There's no special tricks there, it's just regular Unity shadows at work in the normal way.

    I agree that it should be more simple to have "overlay" shadows in Unity - the MatteShadow example script in the 2.5D tutorial works for me, but only when using Directional lights.  Point and Spot lights don't work.

    One technique that gives much better results is to create a separate "shadow" camera that then gets overlayed on top of the MainCamera - similar to how you might do it in Photoshop.

    I'll see about writing a tutorial for it, but here's the rough guide:

    1) Duplicate your character's mesh GameObject (the one with the Skinned Mesh Renderer) and place it on the BackgroundImage layer.

    2) Set this duplicate object's Cast Shadows value to Shadows Only

    3) Create a plane for the floor, and place it on the BackgroundImage layer.  The plane should have a standard default-white material.

    4) Create a new Camera in the scene named "Shadow Camera", and remove all components except for the standard Unity camera.  Then make it a child of the MainCamera, clearing its transform so that it shares the same point in space and field-of-view.

    5) Create a new Render Texture asset in your Project folder, and set the Size values to match your game's intended resolution.

    6) Set ShadowCamera's Culling Mask to BackgroundImage, Clear Flags to Solid Color (white) and assign the Render Texture as the asset you just created.

    7) Duplicate your scene's light, and set the Culling Mask to BackgroundImage only and enable shadows.

    8) If you are using a point light, you will need to ramp up the Intensity value so that the plane is completely white, save for the shaded area caused by your character

    9) Download the Legacy Image Effects asset here:!/content/83913

    10) Open ScreenOverlay.cs and replace line 22:
    public Texture2D texture = null;
    public Texture texture = null;

    11) Select the MainCamera and attach the modified Screen Overlay component to it

    12) Set the Blend Mode to Multiply, and the Texture as the Render Texture asset

    You should then have shadows projected onto the plane appearing on top of the rest of your scene.
  • edited November 2017
    I agree that it should be more simple to have "overlay" shadows in Unity - the MatteShadow example script in the 2.5D tutorial works for me, but only when using Directional lights.  Point and Spot lights don't work.

    Thank you Chris, I think you will do a great job writing a tutorial for the shadow, it will be useful to many of us.
    But I would not have explained myself badly.
    In 2.5d mode, even for me MatteShadow using Directional light works perfectly.


    Even in 2D environment the shadow operating normally but the difference with 2.5D is that the plane on which moves the character is not hidden. It is therefore not possible to use the shadow because it is not possible to leave the plane visible for obvious reasons.


    You should then have shadows projected onto the plane appearing on top of the rest of your scene.

    The shadow on the plane is not the problem, the real problem is the visibility of the plane. 
    Can I then follow your directions or have I explained badly?

  • edited November 2017
    Hi Chris, I followed your directions but I have some perplexity.
    The first is that the plane is still visible.
    The second is that the duplication of Directional light would seem to be unimpressive. If I set the original Directional Light with Shadows Disabled and Directional Light duplicated with Shadows enabled the shadow is not visible, inverting the setting instead the shadow is visible. 
    Finally, if I remove the Directional Light duplicated and I leave the original with Shadows enabled the shadow is still visible.
    In this image you see the visible plane and the visible shadow despite the duplicate Directional Light is disabled.


    But the plane for the floor of step 3) must be a duplicate of the first (which is set as NavMesh and baked)?

    Finally I managed to find a version of FX / Matte Shadow that seems to work in 2D - screenspace - 3D character.
    The plane is transparent and the shadow is projected onto the floor.


    The only negative note is that there is not much difference between Soft Shadows and Hard Shadows.
    This is the link where you can download the script

    However, it does not seem to work with Spot and Point.

    Obviously whoever finds better solutions than this shares it, this shadow is not really among the most beautiful.
    We wait for Chris's tutorial (I think I've made a mistake by following his directions).

  • edited November 2017
    The tutorial can be found here, but it's generally the same as my above steps.  As I explain at the start of it, it's just one approach that can be taken - and there could well be a better way.
  • edited November 2017
    I suspect the issue with the visible plane in the 2D camera is that the 2D mode requires your background to be an actual sprite in your scene, meaning it's displayed behind the floor in physical space.

    The MatteShadow shader is only designed to work with nothing behind it, hence the problem.

    You should still be able to make use of that shader by moving the background onto the BackgroundImage layer, and then creating the same "ShadowCamera" as the tutorial (which only renders that layer), and making sure the MainCamera doesn't render that layer.  That's essentially the principle behind 2.5D mode, only using a sprite instead of a GUI component.
  • Sorry Chris, I tried but no luck.
    When you find some time, could you give me some more detail?

  • Which part?  What does your attempt look like?

    The MainCamera's Clear Flags will also need to be set to Depth Only, and have a higher Depth value than your ShadowCamera.

    When the Scene window is open, and you select the ShadowCamera child, the "Camera preview" window should show just the background sprite image.  The MainCamera should show your Player on a black background.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.