Search Unity

Resolved 2d Sprites - 3d World & Shadows and Shaders

Discussion in 'Shaders' started by PsaroLearthy, Aug 17, 2022.

  1. PsaroLearthy

    PsaroLearthy

    Joined:
    Jan 3, 2017
    Posts:
    3
    Really wasn't sure how to label this thread because this one is hard to summarize in one line.

    I'm prototyping a farming sim using 2d sprites in a 3d world. The character is at a 45 degree slant with the camera angled in the same manner. I've managed to get shadows working on both my tilemaps and my sprites, and it is looking great so far.

    upload_2022-8-17_12-33-39.png

    Where I run into trouble however is any animations that extend below where his feet are fall under the world.





    Essentially i'd like for my tilemap to render almost as a background, that no matter what all animations, shadows and effects play on top but I've been struggling to accomplish that.

    I've tried rendering the character on top of everything but then I run into issues having him stand behind objects.

    I've been able to get him to render in the right order with transparent shaders and using sorting order/queues but it seems shadows don't play well (if at all) with transparent shaders.

    Is something like this achievable, or will I have to make some other adjustment? Any help would be appreciated!
     
  2. PsaroLearthy

    PsaroLearthy

    Joined:
    Jan 3, 2017
    Posts:
    3
    Some further thoughts and things I've tried.

    One solution I found that partially worked was using a shadow offset. Essentially I moved the sprite so that it gave the illusion it was direct on the tilemap, but was actually floating higher in the air, then offset the shadow to be the right spot it all worked, but sadly only for that light position. As I moved the light, such as changing the time of day, things were out of sync. So in theory I could just shift the offset as the day changes but that seems like more of a hack than I am hoping for.

    The current thing I am searching for is if there is anyway to fake the ztest calculations so that my tilemap always loses but still renders where it is, and shadows correctly. I found the offset keyword which seemed to cause some strange behavior. I also saw a lot of warnings about using that incorrectly so I am thinking its not the solution I want.

    If anyone has any ideas I am eager to hear them.
     
  3. PsaroLearthy

    PsaroLearthy

    Joined:
    Jan 3, 2017
    Posts:
    3
    I just managed to solve my problem, though it was not with any of the concepts I attempted or theorized earlier.

    My issue was essentially that I was using the same shader for my Objects & my Character. I simply made a unique shader for both, rendered the tilemap first, the character second with ztest off, then the new object shader with ztest on. Everything now works as intended.

    Talk about over thinking things.