1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. We want to know how you learned Unity! Help us by taking this quick survey and have a chance at a $25 gift card
    Dismiss Notice
  5. Are you an artist or level designer going to Unite Europe? Join our roundtables there to discuss artist features.
    Dismiss Notice
  6. Unity 5.6 is now released.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice

No shadows visible on Transparency Shaders?!!

Discussion in 'Shaders' started by seon, Apr 3, 2008.

  1. maruska

    maruska

    Joined:
    Jun 1, 2013
    Posts:
    9
    Heh - yeah, there's 5 or six threads and a bunch of stuff on the various wikis. Most of them don't work in Unity 5 and all of them are Forward render, single directional light source only.

    I'm pretty inexperienced programming shaders, but conceptually, it seems like it'd be easy to just not render the albedo and specular passes and keep the shadow pass in the standard shader, but I haven't been able to make that work...
     
  2. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    198
    You can generate your own shadow map and sample it in your transparent shader.
     
  3. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    260
    Ok, how to generate our own shadow map in Unity ? Any link to share on this topic ;)
     
  4. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    658
    Well you basically do it the same way as you would with anything, create a camera and render with a depth pass with replacement shaders, this should get you started:

    http://www.software7.com/blog/unity-shadows-on-windows-phone-8/
     
    Alesk likes this.
  5. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    260
    Many thanks ! :)
     
  6. RDeluxe

    RDeluxe

    Joined:
    Sep 29, 2013
    Posts:
    56
    Hey @Aras , any update on this ? I did not see anything on the roadmap, and that's kind of a big problem for us right now, so we would like to know the probability of this happening in the next months.

    Thanks
     
    Alesk and S_Darkwell like this.
  7. Aras

    Aras

    Graphics Plumber Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,522
    Most likely not in the next 1-2 months. Right now no one is doing it (majority of graphics people are on bugfixes, GI, baking, Vulkan, multithreading etc.). Someday, but not "soon soon" :/
     
  8. varfare

    varfare

    Joined:
    Feb 12, 2013
    Posts:
    198
    I think that if docs would be more specific about what Unity is doing with its shadowmap pipeline we could pull this off by ourselves. For example - when does Unity renderer creates shadowmaps, how do you sample it, does Unity broadcast multiple resolutions of the shadowmap etc., etc.. At least I would create my own shaders which support that. There is simply too much digging through the code that needs to be done for doing this. There are a lot of shadowmap related macros, functions, samplers but docs not very good on this subject. Do you think that getting better shadowmapping docs is doable? If we could get this it would be really helpful (at least I would be very happy :)).
     
    antislash likes this.
  9. antislash

    antislash

    Joined:
    Apr 23, 2015
    Posts:
    627
    sounds like unity have been into this reflexion .. i v'e heard the in the next releases, the renderer will be fully scriptable with c#, allowing us to customize each element of the render path, interesting
     
    varfare likes this.
  10. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    241
    What are your sources for this? I hope it's true!
     
  11. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    2,804
    It was something being talked about by some of the Unity devs on Twitter and implemented to some degree during Unity's recent hack week.

    Here's an example of something they got working using it:
    https://mobile.twitter.com/aras_p/status/730795869533032448/video/1

    There's no official word on when or if it'll get a public release. The scriptable rendering pipeline or the OIT transparency.
     
  12. RDeluxe

    RDeluxe

    Joined:
    Sep 29, 2013
    Posts:
    56
    Small bump. Still no deadline on this @Aras ?
     
  13. Potaski

    Potaski

    Joined:
    Aug 21, 2013
    Posts:
    47
    I think the Unity team considered too much on this issue. Generally we don't need very precise and scientific projection of shadows on transparent objects. I just need it to HAPPEN. If it confuse some new users, how about make it a switch that could only be triggered in debug mode or by script? (A switch that make transparent object receive shadows, if there's code in shader, just like any opaque object.) I don't care it's technically wrong. The visual can always be fixed by clever artistic treatment.
     
  14. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    658
    There is not 1 game in the world currently that uses transparent shadows, your asking them to solve a problem that GPU manufacturers are yet to solve.
     
  15. Yeowza

    Yeowza

    Joined:
    May 9, 2014
    Posts:
    14
    so it's still not possible for transparent objects to receive shadows?
     
    Last edited: Sep 27, 2016
  16. Font8

    Font8

    Joined:
    Jan 1, 2013
    Posts:
    29
    If the Unity team needs any inspiration on getting this working, just look at the Sunshine asset on the asset store: It supports transparent shaders recieving shadows. The only problem with it is it's not fully integrated in the Unity pipeline, so it has to do a seperate camera render which can add some unnecessary overhead, like generating terrain meshes, calculating LODGroups and doing OnMeshRender callbacks, which can also create some unwanted side effects.

    It would help me out so much to get transparent shaders able to recieve shadows, even if they weren't blurred or blended. Trying to make a AAA looking product without it feels like a major kneecap.
     
  17. deverolirc

    deverolirc

    Joined:
    Jan 19, 2014
    Posts:
    184
    Wow, is this still not possible? its been almost 10 years!
     
  18. cgeye

    cgeye

    Joined:
    Mar 5, 2014
    Posts:
    27
    Guys,

    I've been using this shader to cast shadows of gameobjects onto real surfaces for AR. So it basically allows a transparent plane to recieve shadows. I didn't write it, and can't remember where it came from but happy to share. Just add it to your shaders folder, create a new material and select FX/ShadowCatcher from the shader dropdown. Make sure the alpha cutoff is set to 0. put a plane object on the floor of your scene, add the ShadowCatcher material in the inspector, make sure 'Receive shadows' is checked and you're done! Hope this helps!
     

    Attached Files:

    Last edited: Nov 22, 2016
  19. Zer0Cool

    Zer0Cool

    Joined:
    Oct 24, 2014
    Posts:
    1
    If someone is searching for an actual transparent (decal) shader that receives shadows (unity version 5.4.0f3). Thanks for the hints from antislash:

    Code (CSharp):
    1. Shader "FX/TransparentDiffuseWithShadows" {
    2. Properties{
    3.   _Color("Main Color", Color) = (1,1,1,1)
    4.   _MainTex("Base (RGB) Trans (A)", 2D) = "white" {}
    5. }
    6. SubShader{
    7. Tags{ "Queue" = "AlphaTest+50" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" }
    8. LOD 200
    9. CGPROGRAM
    10. #pragma surface surf Lambert alpha:fade
    11. sampler2D _MainTex;
    12.  
    13. fixed4 _Color;
    14. struct Input {
    15.    float2 uv_MainTex;
    16. };
    17. void surf(Input IN, inout SurfaceOutput o) {
    18.   fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    19.   o.Albedo = c.rgb;
    20.   o.Alpha = c.a;
    21. }
    22. ENDCG
    23. }
    24.   Fallback "Legacy Shaders/Transparent/VertexLit"
    25. }
     
  20. HonoraryBob

    HonoraryBob

    Joined:
    May 26, 2011
    Posts:
    763
    Does it still allow objects behind the transparent object to receive shadows?
     
  21. HonoraryBob

    HonoraryBob

    Joined:
    May 26, 2011
    Posts:
    763
    "Inside" was developed with Unity and it seems to allow transparent particles (dust) to receive shadows from spotlights, so why do people say this is impossible with Unity? Unless "Inside" is using some sort of fakery, but at fullscreen it looks like particle-effect dust is slowly drifting and being lit or shadowed in realtime by the lamps. Here's a Youtube video of someone playing it, although Youtube's clarity obviously isn't very good; but you can see the effect by going to 10 minutes 38 seconds and looking underneath those lights hanging from the ceiling:




    I could take a screenshot if the video isn't clear enough,
     
  22. rea

    rea

    Joined:
    Oct 10, 2009
    Posts:
    1,816
    Lit particles can be achieved via simple forward scattering right now afaik, but not shadowing .
    But shadowing still can be achieved via static shadow volume or light cookies for example is Resident Evil Umbrella Corps, they using some kind of static volume shadow for particle
     
  23. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    2,804
    Inside fakes a ton of stuff, but they also had engine source access so they could make the changes they needed to make it work if they wanted. Really though you'll never see shadows on particles, only the light cookie projections which is fairly easy to do, but they do volumetric lighting which hides the fact the transparencies usually don't have shadows. The water surface does receive shadows though.
    http://twvideo01.ubm-us.net/o1/vault/gdc2016/Presentations/Gjoel_Svendsen_Rendering_of_Inside.pdf

    It is possible using the scripting tools we have to copy the shadowmap from a light, and then pass that on to a custom transparent shader with the appropriate data so it can render with a shadow. The issue is it takes quite a bit of work and know how to get that, well, working. It's actually easier in some ways to just render your own custom shadowmaps.
     
  24. rea

    rea

    Joined:
    Oct 10, 2009
    Posts:
    1,816
    it certainly is possible
    upload_2017-1-25_21-27-34.png
     
  25. zboyet

    zboyet

    Joined:
    May 27, 2013
    Posts:
    3
    Add me to the list of people that really need this. I made a really slick tiled ground system but it depends on transparency to work properly. Now it looks like I will have to go with another solution just so my ground can show shadows :(
     
  26. G1NurX

    G1NurX

    Joined:
    Dec 25, 2012
    Posts:
    59
    In my own case, using decal:blend instead of alpha:auto(fade,blend,etc) in surface shader sloved my problem.
     
  27. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    337
    Hi.

    Love threads started in 2008 and are still alive.
    I was in the need for my particles to cast shadows and to "simulate" volume so they could affect the god rays.

    Unlike many of u I still develop in 4.7 cause of the no way to lightmap big scenes. So even unity 5 seems to support alpha blend shadows I could not take advantage of it.

    Still the approach I used might be mor optimal than shadowcasting your full particle cloud.

    This smoke cloud is formed by about 3 systems so I will makek only ethe big one cast shadows.
    upload_2017-3-28_19-37-20.png

    I duplicate the big particle system shader and change it to Cutout-->Onside-->Back shader (see below 4 the shader).

    I duplicate the big particle system and aply previous shader, now is casting shadows and blocking godrays, yay!
    Still you can reduce the emision rate and consider making particles bigger for greater coverage, also playing with the cutout value you can simulatevariation in the thickness of the cloud.

    note:yes I should now move the partycle system closer to origin so that there is no shadow gap XD.

    Some tests : ( yes god ray caster is too low, only for testing):
    upload_2017-3-28_19-40-53.png

    upload_2017-3-28_19-41-15.png

    upload_2017-3-28_19-41-41.png

    Shadows are not prefect but this approach gives you much more than having none for I belive little cost.

    Nor sure if I should duplicate the sprite and create a low res or being the other particle system already using the sprite will make no performance difference.

    Cutout shader is named:
    Transparent/Cutout/DiffuseBack

    And is part of an old oculus sdk. not sure if I can share it so if you need it find it yourself in the asset package that is available for oculus devs.

    Hope you liked it!!
     
    Last edited: Mar 28, 2017
  28. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    337
    final version:
     

    Attached Files:

  29. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    2,804
    Note, the problem this thread is discussing is transparent objects receiving shadows cast by other objects (or itself). Transparent objects casting shadows onto other objects is fairly straightforward.
     
  30. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    337
    Is it?! I mean, is there other way than using cutout shader? Cause when I use cutout shader it looks crap. I posted because there was other person in the need to cast shadows with particles #16.
     
  31. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    2,804
    The "best" answer beyond basic cutouts is to use stippled / dithered cutout shadows (which is what Unity 5 does with the standard shader) and rely on shadow filtering to blur it. Dithering is easy to implement, but the shadow filtering in Unity 4.0 isn't good enough to hide the dithering, and is only really good enough on directional lights in Unity 5.0. This is a fundamental limitation of tranditional shadow maps, not just something Unity is avoiding because they're "lazy".

    I said it was straightforward, but I didn't say it looked good. :)

    AAA games often do soft semi-transparent shadows from particles by rendering particles from a second camera and projecting that back into the scene using something like a light cookie or Unity's projector, or using much fancier (and much slower!) volumetric shadow maps. Infamous Second Son as an example did soft particle shadows by using a fairly traditional "blob shadow" for every particle that they wanted to cast a shadow.

    People can, and have implemented several of these techniques in Unity already, and you can find them on the asset store, probably using Unity 5.0, but the techniques should all be possible in Unity 4.0 Pro.
     
  32. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    337
    Tx for the info!

    I wanted to run away for anything complex like volumetric stuff. A global projector could also do the trick as with such big cloud the distances are big and if you've (I've) the shadow distances "short" they shadows... show progresively witch feels cheapo.
     
  33. JorgeRC

    JorgeRC

    Joined:
    Nov 22, 2013
    Posts:
    3
    Let me bring this back to the table. I have tested around 20 different shaders and nothing works. I remember to achieve this in Unity 4.6 but in Unity 5 I can´t. Is there any solution? This behavior is very important for the augmented reality applications and I can´t believe that after 9 years of this thread there is no a solution.
     
  34. jopi404

    jopi404

    Joined:
    Nov 29, 2012
    Posts:
    27
    I also would like a transparent material that is able to receive shadows. With the release of AR Kit, this will be very relevant for many projects. Because you do want your game objects to project shadow on the actual ground!
     
  35. jimmya

    jimmya

    Unity Technologies

    Joined:
    Nov 15, 2016
    Posts:
    117
    Hi folks,
    Come and join us over at the ARKit thread where we have just submitted a possible solution. Please check it out and let us know how it works for you.

    If you just want to see the shader, its here.
    Cheers!