Search Unity

Implementing custom shadow map filtering...

Discussion in 'Shaders' started by FuzzyQuills, Jul 15, 2014.

  1. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Hi guys.

    I am after some knowledge of how to do some sort of custom shadow filtering for my game project. being that Unity Free doesn't have soft shadows, I need to find a way to do my own shadow sampling in free. only problem is, Google brings up nothing on this!

    If anyone can point me in the right direction, that would be great! :)
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,445
    some keywords for searching:
    unitySampleShadow
    _ShadowMapTexture

    i've tried replacing AutoLight.cginc and modifying it, but only managed to invert the shadow so far..(or duplicate, but it starts to float around..)
     
  3. Cyrien5100

    Cyrien5100

    Joined:
    Oct 17, 2012
    Posts:
    145
    Yes search on AutoLight.cginc and try to find the shadowmap part, and modify it to have some pcf filtering.
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,445
  5. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    OOH! mgear, you are a legend! could you give me this. perrrlease! :D

    @Cyrien5100: i did give the autolight.cginc a go, but i didn't know what to change... o_O

    EDIT: Also, do you know where to put a modified AutoLight? i kinda forgot... :(
     
    Last edited: Jul 16, 2014
  6. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,445
    i'm posting the sources soon'ish (later this week hopefully)
     
  7. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    COOL! Also know how to replace a new AutoLight.cginc?
     
  8. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,445
    i did this:
    - copied UnityCG, UnityShaderVariables, HLSLSupport, AutoLight to assets folder
    - renamed these as: UnityCG2, UnityShaderVariables2, HLSLSupport2
    - created new shader file (that default diffuse)
    - add this line to shader: #include "UnityCG2.cginc"
    - modified it to use: #include "UnityShaderVariables2.cginc"
    - modified that to use: #include "HLSLSupport2.cginc"
    - then modified AutoLight for the soft shadow (basically changed all returns to 1, until founded which one it is)
     
  9. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Question: when adding autolight, do you have to include it? I did everything else... but changing all returns to 1 does nothing!
     
  10. metaleap

    metaleap

    Joined:
    Oct 3, 2012
    Posts:
    589
    Good stuff folks. Just a quick note, ShadowSoftener.com somehow does this without modifying autolight or any other built-in cginc. So it's definitely doable without such hackiness --- the built-in cgincs get often (ok rarely but still) changed during Unity updates, but will your project keep up forever? ;) ;)

    There's some built-in named pass tags you can use or hook into or some such. Don't have the full details on me but just in case you were wondering whether there is a way that doesn't require modifying the built-in cgincs. There is :D
     
  11. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,445
    That would be pretty nice, also founded out that the other cgincs were not needed, just put the AutoLight in the same folder as the shader..

    sources are in the github now, need help to improve it :)
    http://unitycoder.com/blog/2014/07/15/unity-indie-soft-shadows-directional-light/

    ** posted the "release" as new thread here:
    http://forum.unity3d.com/threads/free-directional-light-soft-shadow-unity-indie.257432/
     
    Last edited: Jul 17, 2014