[Free] Directional Light Soft Shadow (unity indie)

This is kind of softer shadow for unity indie(free), for directional light only.
(using modified AutoLight.cginc)

Still needs help to make it work without editing any .cginc files
(also no documentation yet, just check the included AutoLight.cginc to see what is happening…)

Original thread:

More info (+webplayer demo) :

Sources:
https://github.com/unitycoder/IndieSoftShadow

Image:

nice

Great ! Is it PCF or a simple shadow map blur ?

its just a simple blur right now, if anyone has ideas how to make it better please post info :slight_smile:

Hi guys, I am the one who started all this, and mgear was one of the ones who came to my aid. so here’s my result also, after working out some projection bugs (this is from my upcoming fighting game Knuckle Iron): 2017 edit: Such game has been in hiatus for a very long time.


If you look closely, you will notice there is absolutely no pixilation on the shadow whatsoever, and this is on medium resolution with no cascades! :stuck_out_tongue: (shadow distance is also 50, giving this a good deal of detail)

@mgear : if you wish, I can incorporate these changes as a secondary technique. (i found your technique had some weird graphics discontinuities, of which with mine, they are less obvious.)

everyone: also, like mgear said, if you have any ideas on improving filtering, please let us know! :slight_smile:

nice! yes please post them in :slight_smile:

did you yet find any way to do this without modifying autolight.cginc itself?

No, unfortunately… :frowning: to do it, we would need to find a way of accessing the shadow map in a custom shader. but unless mr. shadow softener figured out something not documented, we are stuck… :eyes:

BTW, here’s a modified .cginc from me. (attached to post)

I would recommend this for mine: make the resolution as low as you want to, and it will blur in the pixels. at least that’s how it went with me… :wink:

EDIT: Also, unless something in your game needs it to work right, try turning off cascades altogether. this will improve the blurring as the shadow map will switch to a lower resolution.

1708062–107489–AutoLight_SoftShadow.zip (2.1 KB)

2 Likes

Thanks, I’ll add that to the github later.

Some progress on sampling shadowtexture inside shader directly,
otherwise this works but some projection or direction is wrong… shadow is messed up.

Shader "Custom/IndieShadow1" {
        Properties {
            _Color ("Main Color", Color) = (1,1,1,0.5)
            _MainTex ("Texture", 2D) = "white" { }
        }
        SubShader {
            Pass {

        CGPROGRAM

        #pragma vertex vert
        #pragma fragment frag
        #include "UnityCG.cginc"

        float4 _Color;
        sampler2D _MainTex;
        sampler2D _ShadowMapTexture;

        struct v2f {
            float4 pos : SV_POSITION;
            float2 uv : TEXCOORD0;
            float4 shadowCoord;
        };

        float4 _MainTex_ST;

        v2f vert (appdata_base v)
        {
            v2f o;
            o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
            o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
         
            // FIXME: problem could be here?
            o.shadowCoord =  mul( unity_World2Shadow[0], mul( _Object2World, v.vertex ) );
            return o;
        }



        half4 frag (v2f i) : COLOR
        {
            half4 texcol = tex2D (_MainTex, i.uv);
         
            // Hard Shadow
              fixed shadow = tex2D(_ShadowMapTexture, i.shadowCoord.xyz).r;
            shadow = _LightShadowData.r + shadow * (1-_LightShadowData.r); 
         
            return texcol * _Color * shadow;
        }
        ENDCG

            }
        }
        Fallback "VertexLit"
    }

*image:
1709411--107592--shadow_problem1.jpg

what’s it look like?

image added.

this could be one solution, to get the shadow coordinate, but couldnt get it to work yet…

WTH? It looks like the shadow map is being tiled!

try turning off cascades if they are turned on.

huh, gave up and closed unity… now started it again and it works :slight_smile: works with your shadow code also.

(seems to do that even if duplicate same shader, use that, broken, restart, fixed…)

1709459--107598--softshadow_indie.jpg

How did you do that?

and BTW, check out my new avatar! I finally got around to finishing 2.0 of my FuzzyQuills model.

EDIT: Ok… it shows up on my profile, but on any thread my avatar is still the original… HUH?!

If you get good projection, try to do some poisson disk blur, it gives a good soft shadow, i tried myself to do it in screen space it looks good but there is haloing.

thanks!

tried with snippet from here but didnt work well yet… (shadow is too light and not getting more blurred even with large values)

I saw this : Poisson Disc shadow sampling – ridiculously easy (and good looking too) | Electronic Meteor
(Mine gives a good soft shadow but only in orthogonal view :eyes:)
His result is pretty good.
However, Poisson Disk Blur just adds some randomness to the blur, so it can reduce banding, but not very much.

Here you go. Where I went to find sampling techniques.

I actually got a pretty good result from both the one here and mgear’s code, but mgears only works in DX11. (for some reason, there is a EXTREME amount of ‘fragment noise’ when I switched to DX9. this doesn’t happen on the former from the URL, or on the other filtering type.)

EDIT: I fixed it, it turns out mgears were using floats, and trying to squeeze that into a half definitely won’t work… I will post a screen soon

EDIT2: another note: this sadly won’t work on mobile, all it does is mess up the projection. this only happens on the mobile device itself, it doesn’t show up on PC.

BTW, how to use the shadowmap shader mgear? not sure how to use it… :smile:

Nice work, thought that the hard shadows can’t be modified, turns out you did it! BTW since this is soft shadowing you should do some PCF filtering (Percentage - Close - Filtering).

http://www.gamerendering.com/2008/11/15/percentage-closer-filtering-for-shadow-mapping/ - i would recommend because they show code and make it easier to understand.
http://ogldev.atspace.co.uk/www/tutorial42/tutorial42.html

ill give that a shot and make a demo scenes with those shadows and indie effects to see how realistic i can get.