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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Getting shadows to appear from culled layers

Discussion in 'General Graphics' started by dgoyette, May 29, 2018.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,113
    My game is an FPS-style game, where the player's hand is visible on the screen. Because I didn't want the hand clipping through other geometry, the hand is being rendered by a dedicated camera whose culling mask only includes the layers that should be drawn on top of everything else. The rest of the screen is rendered by the main camera.

    upload_2018-5-28_18-35-21.png

    First of all, I assume this is a pretty standard approach to not getting the player's hand/gun to clip through nearby geometry. If there are other ways to accomplish this, I'd be interested in knowing.

    Anyway, a problem with this approach is shadows. If an object on a different layer casts a shadow, it's not getting included on the hands. For example, if I put a cube between the hand and a light source, the hand won't receive any shadows from the cube. If I include the default layer in the culling mask, now I get shadows.

    So, what's the solution here? Is there a way to get shadows from all layers to be drawn onto an object that is being rendered by a camera that doesn't include the shadow-casting layers? If not, is there a different approach I can take to drawing the Hand on top of everything else, but still getting shadows?
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,419
    Pretty much every recent FPS I played uses an animation to fix the "weapon clips through wall" issues.

    If the player gets near a wall, while aiming, the game forces an animation that stops aiming and moves the weapon near the players chest, thus not pointing through the wall anymore.
     
  3. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,113
    Thanks for the suggestion. I'll probably have to do something like that.

    I did experiment with writing a custom shader, with `ZTest Always` enabled, so that I could render the hand on the main camera, but on top of everything else. But I immediately realized this wasn't a viable approach. When hand clips through a wall. even though it's still drawn, the wall starts casting shadows on it, as you can see in this screenshot:

    upload_2018-5-29_13-3-44.png

    So, the shader approach doesn't seem to work. So now I have to decide whether proper shadows on the hand are worth the tradeoff of having to build the functionality to retract the hand to avoid clipping through walls.

    Thanks again.