Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Shadow Caster/Dark rim light or similar effect

Discussion in 'Shaders' started by Prefab, Apr 6, 2020.

  1. Prefab

    Prefab

    Joined:
    May 14, 2013
    Posts:
    68
    I would like a simple (black and white) way of showing the player when their charatcer is hidden or not from AI. To achieve this I would like to create a darker shadow like affect on the character mesh to visualise that they are hidden. I quite like the darkness that a projector (aimed down) creates however this is quite expensive since it doubles the set pass calls. Another effect I was thinking is using a rim light like effect but making it black. At the moment I am using the below shader code to create my rim lighting which works well, except when trying to make it black it of course mutes the effect i.e. the darker the selected color is the the less rim light is visible, similar to if you try to make the color of a light darker. I suppose what I am asking is if there is a way to create a "negative" rim light or black light like effect in a shader.

    Any suggestions on how this could be achieved?

    Code (CSharp):
    1.         half4 rim = 1.0 - saturate(dot (IN.viewDir, o.Normal));
    2.         o.Emission = _RimColor.rgb * pow (rim, _RimPower);    
     
    Last edited: Apr 6, 2020
  2. Prefab

    Prefab

    Joined:
    May 14, 2013
    Posts:
    68
    I have been looking online and experimenting with a few different solutions when I realized that using an invisible shadow caster might be all that I need.

    So what I have done is create a standard Unity cube (capsule will also work), changed the dimensions and position so the character approximately fits inside it, and then created a transparent material and set Cast Shadows in the renderer to Shadow Only. This works visually exactly like I want, and adjusting the material transparency adjusts the darkness of the shadow which is great.

    However the issue is that this invisible cube casts a shadow on everything, whereas I would like it to only cast onto the character mesh. Is there a way to be able to do this? Since otherwise a box shadow follows the character around.

    upload_2020-4-10_15-12-57.png
     

    Attached Files: