Search Unity

Shader that uses other shader's output?

Discussion in 'Shaders' started by CHOPJZL, Apr 4, 2021.

  1. CHOPJZL

    CHOPJZL

    Joined:
    Dec 5, 2016
    Posts:
    55
    Hello,
    I am still new to shaders. I am thinking about making 2d sprites to have 3d lighting and shadow.

    The current thought is collecting the ShadowCast result of a mesh out of the screen, then pass it to a sprite's ShadowCast pass, is this possible, and how to do it?

    Thanks in advance:)
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    Nope. Also because none of that really made any sense.

    However I'm assuming you're wanting to have shadows that are cast from a 3D object onto a presumably 3D scene, and have your sprite be lit like it's a 3D object. The answer to that is ... yes, but it's more complicated than you think. More likely you'll just want to use a 3D model that's set to be shadows only on it's mesh renderer component, and a 2D sprite that's using normal maps. Even if you go with an invisible 3D mesh casting shadows and a lit sprite with normal maps, you'll have to contend with the 3D mesh casting shadows onto the sprite ... and since the sprite is still a flat object and might be cutting through the middle of the 3D mesh causing the shadows that are cast onto the sprite to look very bizarre. Other options are to just use a 3D mesh that has the "sprite" artwork as it's texture, or a sprite setup that has a depth texture and using a custom sprite shader that uses that depth information when rendering. Or disable shadow receiving on the sprite.

    The biggest issue with mixing 2D and 3D objects is the lack of perspective on 2D objects. While there are ways you could copy the light from a 3D object and apply it to a 2D object in real time, they won't really line up unless you're using an orthographic camera and are very careful with the alignment of the two objects.
     
  3. CHOPJZL

    CHOPJZL

    Joined:
    Dec 5, 2016
    Posts:
    55
    I ended up using 3d directly:)