Search Unity

Experimental Realtime Decal Shadows

Discussion in 'Shaders' started by Dantus, Sep 5, 2013.

  1. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I have create some shaders for my Decal System (Pro) which support realtime shadows. I have tested them in many different scenarios and haven't found issues so far. As I don't consider myself a shader expert, I am making this pre-release before the shaders will be shipped with my Decal System (Pro).
    Another addition is a parallax shader and certainly a variant with realtime shadows.

    Feedback is highly welcome! I am curious to hear your opinion and certainly if you know ways to improve them!

    Known Limitation
    • Those shaders only work if the decal projector is placed on top of a mesh/skinned mesh/terrain which uses an opaque shader.
    • As with any other shader, dynamic shadows in combination with baked lightmaps only work if Dual Lightmaps are used.
    Download Link
    Experimental Shaders


    Edit: Got the idea from this post. Thanks cician!
     
    Last edited: Sep 5, 2013
  2. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    Nice! Hows the performance when compared to Unity's shadows? Can they be filtered / blurred?
     
  3. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Check it out! It is not too funky...
    I just used the default shaders, added some tags, such that the decals receive Unity's shadows. As such you don't have additional settings.
     
  4. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    Ooh wait a minute. I think I got you wrong. I thought this is a replacement for Unity's shadows, but it seems that you just added shadow support for your decals.
     
  5. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Yes, that's it. As I said, it is not too funky. But it is also not that easy to get shadows on transparent shaders. I am not 100% sure if they work reliable under all circumstances. That's why I have posted them here to get feedback.
     
  6. Rico21745

    Rico21745

    Joined:
    Apr 25, 2012
    Posts:
    409
    $Shot 206.5013.png

    Looks like there may be some issues with it. I changed the material of my atlas to use one of the shadowed colored transparent experimental shaders.

    The weirdness is the fact that the shaders never seem to light up when hit by a light source. They always appear the same as they are no matter the light condition. Those are realtime shadows you see in the scene by the way.
     
  7. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    @Rico21745, are the gray rectangles the decals? I hope you don't mind if I ask a few questions. This will help me a lot to identify and hopefully to resolve the issue.
    Do you have any lightmaps in the scene? Did you try if it works in a clean scene? E.g. by just have a directional light and two cubes where one is in the shadow and then placing a decal half in the shadow and half lit.
     
  8. Rico21745

    Rico21745

    Joined:
    Apr 25, 2012
    Posts:
    409
    Yeah the dark rectangles are paper decals that are being blackened by the shader (they should appear white like paper). I'll try to run a test when I get home on a clean scene. There's no lightmapping in that scene, all real time and ambient lights.
     
  9. Rico21745

    Rico21745

    Joined:
    Apr 25, 2012
    Posts:
    409
    Ok I had a chance to test it in a clean scene and it still appears to be happening. It's almost like the decals are always in the shadowed state, no matter how much light hits them.

    If it helps, I'm using deferred rendering on my camera.
     
  10. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I tried to reproduce the issue. The shadows work on my side, even with the deferred pipeline. Could you send me a reproduction?
     
  11. Rico21745

    Rico21745

    Joined:
    Apr 25, 2012
    Posts:
    409
    Aha! I finally figured out what's causing it.

    Looks like it's DX11 mode in Unity. If you switch platforms to PC Mac and then enable DX11, then restart the Unity editor, you should be able to reproduce the issue. Let me know if you still need me to send in a reproduction, but that should do it, I just got it to happen in a brand new project.
     
  12. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Thanks a lot, I'll see what I can do about it.