Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Shadow cast - transparent visual, masked/clipped/alphatest shadow

Discussion in 'Shaders' started by jistyles, Aug 14, 2015.

  1. jistyles

    jistyles

    Joined:
    Nov 6, 2013
    Posts:
    34
    So I've got some nice fast cloud volumes, all lovely and fluffy with some dipole scatter approximation for getting some dynamic lighting:
    upload_2015-8-14_12-46-52.png

    upload_2015-8-14_12-53-5.png

    So far so good.

    A technique I would now normally use to cast dynamic shadows is to use a clip()/alphatest shadow casting pass to blat the Z into the shadow depth map.
    However, trying that in unity, I seem to hit a brick wall. There appears to be some artificial hard-coded clause if there's any potential that it's transparent, then disable ALL shadow path's. This is the case when using both a surface shader with addshadow and alpha pragma, and also a cg shader when explicitly using another pass:
    Name "ShadowCaster"
    Tags { "Queue"="Geometry" "RenderType"="Opaque" "LightMode" = "ShadowCaster" }

    Can somebody please confirm/deny if this is the case? @Aras - I'm looking at you buddy!

    Hopefully artificial limitations like this haven't been introduced on purpose :D
     
  2. jistyles

    jistyles

    Joined:
    Nov 6, 2013
    Posts:
    34
    So all I'm turning up online is a solid "no" for this -- admittedly all the questions seem to be the usual naive "can I make my transparent thing cast transparent shadows".

    It seems that unity is hard coded to disallow a shadow pass if the primary shader pass is transparent in any way.

    Soooo that leaves me with three options I can think of:
    1) using a proxy geometry pass which renders nothing visual, and is only used for its masked shadow pass.
    This should of course work fine, however the overhead is pretty wasteful and very non-generic.
    2) do a full custom transparent shadowing pass ala starcraft2:
    http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2013/01/Chapter05-Filion-StarCraftII.pdf
    3) do a cheap transparent shadowing pass which only applies to terrain as a light cookie; update it dynamically based off the clouds periodically.