Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Cast real time shadow only from a separate light source (avoiding Directiona Light)?

Discussion in 'High Definition Render Pipeline' started by johannesQb, Aug 20, 2022.

  1. johannesQb

    johannesQb

    Joined:
    Jan 18, 2022
    Posts:
    10
    Hi, in HDRP I'd like to recreate a shadows settings like mario odyssey, where every objects in the environment casts shadows from the directional light, but Mario not; he casts the shadow from another separate source, and ONLY from it (avoiding directional light).
    Here a screenshot, blue arrows = directional light, red arrow = the other source of light, from top. In this case is perfect becaouse you have the player's shadow always under the player while he jumps.
    Thanks

    upload_2022-8-20_16-1-56.png
     
    Last edited: Aug 20, 2022
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,456
    The lights have a culling mask. Exclude mario from the mask and have a seperate spotlight which just casts shadows on mario and culls the rest
     
  3. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    399
    You can use light layers for that. Just put Mario on a separate Light Layer and assign it to the dedicated light (you might need to toggle advanced settings in the first foldout of the light inspector)
     
    DevDunk likes this.
  4. johannesQb

    johannesQb

    Joined:
    Jan 18, 2022
    Posts:
    10
    It works but the shadow is almost invisible even if i increase the intensity fo the spotlight to max. Probably something messy with my global volume settings.

    Thanks
     
    DevDunk likes this.
  5. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Layers won't work really since it'll be physically correct, and mario's is not. Mario just has a blob shadow technique but instead of it being a blob its using a render texture. The render texture is a black and white render of just mario. You do not use a camera for that or anything. You can draw the model directly to the rendertexture.

    The things you need to know for this to work:
    • rendering meshes to a render texture without using a camera
    • rendering a blob shadow under player's feet on the floor
    • making a shader for blob shadow so that it uses a different texture
    The reason it's important to not use a second camera is because it will kill HDRP performance and this technique never does use a second camera anyway.

    Blob shadow is a widely understood concept.
     
  6. johannesQb

    johannesQb

    Joined:
    Jan 18, 2022
    Posts:
    10
    Thanks! I understand the concepts, but i really can't figure out how to do this. I'm new on Unity and never use render texture before. According to the docs rendertexture work with camera, i tried and understand how it works for simple purpose like show on a texture (a screen in game) what a camera is looking.