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

Applying Shadows to a transparent surface

Discussion in 'Shaders' started by crash664, Jul 18, 2016.

  1. crash664

    crash664

    Joined:
    Nov 22, 2012
    Posts:
    91
    Hi all,

    Once again, I will open this can of worms..there are a few other threads (quite old) discussing this problem yet nobody is able to give a solution. Additionally, I do believe I had this working a few years ago (~4.6.2), but Unity seems to have changed something in their rendering pipeline which prevents this from being achieved.

    To be clear, the desire is to have a transparent plane that will still receive shadows. I went back in the shader source to find out how I achieved it previously, and found that the old vertex-lit shader has two passes called "Shadow Caster" and "Shadow Collector". The new shaders still have Shadow Caster, but not Collector. When I tried to copy the Collector pass from the old shader to the new one, it just won't work.

    I did some more searching and found this custom shader.

    Perfect for my needs, however, it does not work. Can anybody provide some insight as to why these are no longer supported in Unity, or even a possible solution?

    Thanks!
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    In 5.0 they merged the shadow collector and shadow caster into a single shader. They still have equivalents of shadow caster and shadow receiver rendering passes, they just both use the shadow caster shader.

    The problem is they simply do not send shadow data to anything in the "transparent" rendering queues. I've written several posts about the issue before and plausible (but very, very involved) solutions, but I'm not going to iterate them here.

    Right now this thread has basically the only working option, as well as some discussion on how to get some different version working.
    http://forum.unity3d.com/threads/transparent-shader-that-recieves-shadow-kinda-works-already.398674/

    A future version of Unity (after 5.4) should have the ability to enable shadows on transparency again relatively trivially.
     
    Frencich likes this.
  3. crash664

    crash664

    Joined:
    Nov 22, 2012
    Posts:
    91
    Thanks for your prompt answer.

    That makes a lot of sense for now. I hope this functionality is added sooner as it is quite a common requirement of AR type projects which Unity is quite convenient for.

    I'll attempt the solution outlined in your referenced post.

    Thanks!
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    The second to last shader I posted in that thread should work for you. Since with AR you probably won't be using a skybox you shouldn't be running into the issues that thread mentions.
     
  5. crash664

    crash664

    Joined:
    Nov 22, 2012
    Posts:
    91
    Yes you're right. I first implemented the last one, but as you noted in that thread the shadow intensity is somewhat fixed. I just tried the second to last one and it works like a charm! Also, I'm not exactly doing real AR, I just have a 360 spherical panorama and wish to integrate virtual content. But it's the same thing I suppose as there is a sphere all the way around the user, hence no skybox.

    Thanks a lot for your help :)