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

Rendering of Screen Space Shadows Only

Discussion in 'Shaders' started by Narkata55, Jul 30, 2021.

  1. Narkata55

    Narkata55

    Joined:
    Feb 25, 2017
    Posts:
    63
    Hey all, was hoping to have some discussion to figure out what the best approach would be for my issue.

    I'm creating a 3D representation of my 2D tile based world (in order to use Unity's built in realtime lighting with a directional light, for a day night cycle), and so I'm trying to figure out the best way to get just Shadows in a camera (which I would then layer over the 2D scene)
    --> Basically, I have a 2D tilemap, have modeled a 3D scene that is analogous to it, render the 3D scene far away (on a different camera with some tweaked perspective + distance settings to get everything lining up), and now just want to "translate" the 3D shadows that are shown over to the 2D map (ignoring/removing the 3D models except for their effects on the shadows)

    My 2 approach ideas are:

    1) Somehow create a shader/find a combination of settings that allows for MeshRenderers to cast/receive shadows while being transparent themselves. Then I could set the default clear color of the camera to red or something and use a screen space shader to remove all red pixels from the render texture. I don't know if this is feasible/possible (transparent objects casting + receiving shadows doesn't really... work in real life), but was the first idea that came to mind

    2) Somehow incorporate screen space shadows into a shader and render them only. I read that Unity has a function that allows me to grab just the screen space shadows, so I could take that only, and that would be perfect. However, I'm kind of confused on what that function is, what it's idiosyncrasies are, etc (I only saw 1 forum post briefly mentioning the concept, but it seemed perfect for what I'm looking for)

    Would love to hear from anyone if they have any better ideas than the 2 above, or have any insight that could help me solve this issue! Thanks a bunch!

    Note: I don't know if this matters, but I'm using the default render setup that comes with Unity 2019.1.0f2