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

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:
    227
    You can generate your own shadow map and sample it in your transparent shader.
     
  3. Alesk

    Alesk

    Joined:
    Jul 15, 2010
    Posts:
    339
    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:
    666
    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:
    339
    Many thanks ! :)
     
  6. RDeluxe

    RDeluxe

    Joined:
    Sep 29, 2013
    Posts:
    117
    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

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    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:
    227
    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:
    646
    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:
    392
    What are your sources for this? I hope it's true!
     
  11. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    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:
    117
    Small bump. Still no deadline on this @Aras ?
     
  13. Potaski

    Potaski

    Joined:
    Aug 21, 2013
    Posts:
    52
    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:
    666
    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:
    48
    so it's still not possible for transparent objects to receive shadows?
     
    Last edited: Sep 27, 2016
  16. TacticalDan

    TacticalDan

    Joined:
    Jan 1, 2013
    Posts:
    35
    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. o1o101

    o1o101

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

    cgeye

    Joined:
    Mar 5, 2014
    Posts:
    76
    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:
    203
    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. }
     
    CDUnityDev likes this.
  20. HonoraryBob

    HonoraryBob

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

    HonoraryBob

    Joined:
    May 26, 2011
    Posts:
    1,214
    "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. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    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:
    12,329
    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. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    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:
    69
    In my own case, using decal:blend instead of alpha:auto(fade,blend,etc) in surface shader sloved my problem.
     
    SunnySunshine likes this.
  27. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    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:
    864
    final version:
     

    Attached Files:

  29. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    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:
    864
    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:
    12,329
    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:
    864
    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:
    5
    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. John1515

    John1515

    Joined:
    Nov 29, 2012
    Posts:
    248
    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

    Joined:
    Nov 15, 2016
    Posts:
    793
    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!
     
    FusRoDahh likes this.
  36. Wattosan

    Wattosan

    Joined:
    Mar 22, 2013
    Posts:
    456
    Aye, this works but only with Directional lights. The shadows are cast on the transparent plane ONLY when directional light is used. Using point or spotlights does not work.
    This is a picture when using a directional light:
    https://drive.google.com/open?id=0B0gogWMq7zHXaGIzX2ZIeHJEM0U
    And this is using the same light but changing the mode to Point:
    https://drive.google.com/open?id=0B0gogWMq7zHXQWZOMGdSS000dTQ

    As you can see, shadows are cast in both cases (on the furniture). But with the point light, the shadows are cast just on the furniture and not on the transparent plane.
     
    rob_ice likes this.
  37. St000

    St000

    Joined:
    Oct 31, 2017
    Posts:
    2
    Last edited: Jan 19, 2018
    rob_ice and sanmn19 like this.
  38. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Basically all of this is being solved by the new Scriptable Render Pipelines rolling out with 2018 rather than trying to solve it for the existing render. i.e.:Actually let transparent objects receive shadows.
     
  39. jimmya

    jimmya

    Joined:
    Nov 15, 2016
    Posts:
    793
    For using other than directional lights, see the comment in the shader:
    // 1.) This will be the base forward rendering pass in which ambient, vertex, and
    + // main directional light will be applied. Additional lights will need additional passes
    + // using the "ForwardAdd" lightmode.
    + // see: http://docs.unity3d.com/Manual/SL-PassTags.html
     
  40. FusRoDahh

    FusRoDahh

    Joined:
    Jan 20, 2015
    Posts:
    21
    I confirm this works for ARCore. For anyone who also want to have Alpha Texture as input option into this shader, I had to modify the shader as follows. @jimmya Kindly correct me if wrong somewhere :

    First add Properties section :
    Code (CSharp):
    1. Properties
    2. {
    3.     _MainTex("Base (RGBA)", 2D) = "white" {}
    4. }
    Make sure blend mode is chaned to :
    Code (CSharp):
    1. Blend SrcAlpha OneMinusSrcAlpha
    Add uv coods info into vertex structure:
    Code (CSharp):
    1. struct v2f
    2. {
    3.        float4 pos : SV_POSITION;
    4.        float2 uv  : TEXCOORD1;
    5.                
    6.        LIGHTING_COORDS(0,1)
    7. };
    Modify fragment shader to read texture data :
    Code (CSharp):
    1. fixed4 frag(v2f i) : COLOR
    2. {
    3.         fixed4 tex = tex2D(_MainTex, i.uv);
    4.  
    5.         float attenuation = LIGHT_ATTENUATION(i);
    6.         fixed4 color = tex * attenuation;
    7.         color.a = tex.a;
    8.         return color;
    9. }
    Honestly, I am not sure performance impact of this on mobile platform. Perhaps people here can add to it.
     
    Last edited: Feb 17, 2018
  41. unity_e37J3FSssmROgA

    unity_e37J3FSssmROgA

    Joined:
    Feb 28, 2018
    Posts:
    4
    Hello.
    About Keijiro ShadowDrawer, is there any way to change the shader queue to Transparent and still cast the shadows? I have some sprites and meshes with transparency below the transparent plane that only works properly with queue transparent (3000). So I wonder if its possible to make ShadowDrawer work with queue set to 3000 (Im very new with shaders). Thanks.
     
  42. lpiljek

    lpiljek

    Joined:
    Nov 11, 2015
    Posts:
    12
    So... calling from 2018, is there still no way to make the shader in the transparent queue receive shadows?
    My problem is that I need objects to be strictly sorted back to front which as I understand ONLY happens in Transparent queue. Is there any other way to get this sorting behaviour?
    And all I want is for those objects to be affected by the same shadow-map that is used for opaque objects.
    I'm developing a mobile game so I'm using forward rendering and just one hard shadow coming from a directional light. I have no need for soft shadows, shadow cascades and I certainly don't want my shadows to be a screen space effect.
    Why is this so hard??? Is there ANY way I can have my objects sorted (as transparent) AND get the shadow-map in the shader?
     
  43. alexander11

    alexander11

    Joined:
    Aug 11, 2014
    Posts:
    94
    I'm currently in the process of trying to achieve transparent objects to receive shadows. I'll keep you posted if I succeed in doing so.
     
  44. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,539
    They already receive and cast shadows in Unity 2018 with the HD Pipeline.
     
  45. alexander11

    alexander11

    Joined:
    Aug 11, 2014
    Posts:
    94
    @Invertex I know that, I just want to know how to create my own.
     
  46. jariwake

    jariwake

    Joined:
    Jun 2, 2017
    Posts:
    100
    I just bumped into this issue of not receiving shadows on surfaces that use standard shader with transparent (or fade) rendering mode. The only way to get shadows is to use a cutout rendering mode, but this does not give the desired look.

    I browsed through this 10 year old thread and understood that this is not a trivial issue, but is there now a way to receive shadows on transparent surfaces? Im using 2018.1.
     
    rob_ice and S_Darkwell like this.
  47. rob_ice

    rob_ice

    Joined:
    Nov 11, 2016
    Posts:
    112
    Looking around for a point light shadow catching shader!
     
  48. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,539
    When HD render pipeline was in beta it did casting and receiving shadows on semi-transparent surfaces, but then they disabled that while revamping the shadow system I believe. That was many months ago though, I haven't tried it recently, perhaps it's been reimplemented now.
     
  49. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    If you guys still trying to get shadow receiver on transparent object, you can modified the builtin rendering pipeline. The best example is on 3D GameKit the lake water in 3D gamekit are transparent and it receive shadow.
     
  50. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,539
    The water doesn't need to cast shadow because of the depth darkening, thus you can render it at a higher geometry queue to get shadows on the surface. If you made a ball of water it likely wouldn't be casting shadows.

    Technically you could do significant changes to the unity cginc files to support casting and receiving but I doubt the 3D Gamekit did that...