{"id":3088,"date":"2014-07-15T16:55:16","date_gmt":"2014-07-15T13:55:16","guid":{"rendered":"http:\/\/unitycoder.com\/blog\/?p=3088"},"modified":"2014-07-24T04:23:25","modified_gmt":"2014-07-24T01:23:25","slug":"unity-indie-soft-shadows-directional-light","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2014\/07\/15\/unity-indie-soft-shadows-directional-light\/","title":{"rendered":"Unity indie: Soft Shadows (Directional Light)"},"content":{"rendered":"<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3089\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2014\/07\/15\/unity-indie-soft-shadows-directional-light\/fake_soft_shadows_unity_indie_1\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/07\/fake_soft_shadows_unity_indie_1.jpg?fit=680%2C480&amp;ssl=1\" data-orig-size=\"680,480\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"fake_soft_shadows_unity_indie_1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/07\/fake_soft_shadows_unity_indie_1.jpg?fit=680%2C480&amp;ssl=1\" class=\"alignnone size-full wp-image-3089\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/07\/fake_soft_shadows_unity_indie_1.jpg?resize=680%2C480\" alt=\"fake_soft_shadows_unity_indie_1\" width=\"680\" height=\"480\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/07\/fake_soft_shadows_unity_indie_1.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/07\/fake_soft_shadows_unity_indie_1.jpg?resize=300%2C211&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n<p>Using Unity Indie, modified directional hard light shadows.<\/p>\n<p><strong>Forum thread:<\/strong><br \/>\n&#8211; <a title=\"http:\/\/forum.unity3d.com\/threads\/free-directional-light-soft-shadow-unity-indie.257432\/\" href=\"http:\/\/forum.unity3d.com\/threads\/free-directional-light-soft-shadow-unity-indie.257432\/\" target=\"_blank\">http:\/\/forum.unity3d.com\/threads\/free-directional-light-soft-shadow-unity-indie.257432\/<\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>How to:<\/strong><br \/>\n&#8211; Download builtin shader: <a title=\"http:\/\/unity3d.com\/unity\/download\/archive\" href=\"http:\/\/unity3d.com\/unity\/download\/archive\" target=\"_blank\">http:\/\/unity3d.com\/unity\/download\/archive<\/a><br \/>\n&#8211; copied UnityCG, UnityShaderVariables, HLSLSupport, AutoLight to assets folder<br \/>\n&#8211; renamed these as: UnityCG2, \u200b\u200bUnityShaderVariables2, \u200b\u200bHLSLSupport2\u200b\u200b<br \/>\n&#8211; created new shader file (that default diffuse)<br \/>\n&#8211; add this line to shader: #include &#8220;UnityCG2.cginc&#8221;<br \/>\n\u200b\u200b- modified it to use: #include &#8220;UnityShaderVariables2.cginc&#8221;\u200b\u200b<br \/>\n&#8211; modified that to use: #include &#8220;HLSLSupport2.cginc&#8221;<br \/>\n&#8211; then modified \u200b\u200bAutoLight for the soft shadow\u200b\u200b (basically changed all returns to 1, until founded which one it is, then added shadow &#8220;blur&#8221; there)<br \/>\n&#8211; *** Seems that you only need the AutoLight.cginc (in the same folder as the shader, others were not needed)<\/p>\n<p><strong>Sources:<\/strong><br \/>\n<a title=\"https:\/\/github.com\/unitycoder\/IndieSoftShadow\" href=\"https:\/\/github.com\/unitycoder\/IndieSoftShadow\" target=\"_blank\">https:\/\/github.com\/unitycoder\/IndieSoftShadow<\/a> **there are no comments or tutorial yet, check AutoLight.cginc for the modifications..<\/p>\n<p><strong>Webplayer demo:<\/strong><br \/>\n<a title=\"http:\/\/unitycoder.com\/upload\/demos\/HardShadowSoftener\/\" href=\"http:\/\/unitycoder.com\/upload\/demos\/HardShadowSoftener\/\" target=\"_blank\">http:\/\/unitycoder.com\/upload\/demos\/HardShadowSoftener\/<\/a><\/p>\n<p>&#8212;<\/p>\n<p><strong>v2:\u00a0<\/strong> Some progress on getting custom shadows, without any cginc modifications, but something is still broken..<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\r\nShader &quot;Custom\/IndieShadow1&quot; {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Properties {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 _Color (&quot;Main Color&quot;, Color) = (1,1,1,0.5)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 _MainTex (&quot;Texture&quot;, 2D) = &quot;white&quot; { }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 SubShader {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Pass {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 CGPROGRAM\r\n\/\/ Upgrade NOTE: excluded shader from DX11 and Xbox360; has structs without semantics (struct v2f members shadowCoord)\r\n#pragma exclude_renderers d3d11 xbox360\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #pragma vertex vert\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #pragma fragment frag\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #include &quot;UnityCG.cginc&quot;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 float4 _Color;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sampler2D _MainTex;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sampler2D _ShadowMapTexture;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 struct v2f {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 float4 pos : SV_POSITION;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 float2 uv : TEXCOORD0;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 float4 shadowCoord;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 };\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 float4 _MainTex_ST;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 v2f vert (appdata_base v)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 v2f o;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 o.pos = mul (UNITY_MATRIX_MVP, v.vertex);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ FIXME: problem could be here?\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 o.shadowCoord =\u00a0 mul( unity_World2Shadow&#x5B;0], mul( _Object2World, v.vertex ) );\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return o;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 half4 frag (v2f i) : COLOR\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 half4 texcol = tex2D (_MainTex, i.uv);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Hard Shadow\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0fixed shadow = tex2D(_ShadowMapTexture, i.shadowCoord.xyz).r;\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0shadow = _LightShadowData.r + shadow * (1-_LightShadowData.r);\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return texcol * _Color * shadow;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ENDCG\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Fallback &quot;VertexLit&quot;\r\n\u00a0\u00a0\u00a0 }\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&#8212;<\/p>\n<p><strong>Image#2:<\/strong> closeup<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3090\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2014\/07\/15\/unity-indie-soft-shadows-directional-light\/fake_soft_shadows_unity_indie_2\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/07\/fake_soft_shadows_unity_indie_2.jpg?fit=680%2C501&amp;ssl=1\" data-orig-size=\"680,501\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"fake_soft_shadows_unity_indie_2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/07\/fake_soft_shadows_unity_indie_2.jpg?fit=680%2C501&amp;ssl=1\" class=\"alignnone size-full wp-image-3090\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/07\/fake_soft_shadows_unity_indie_2.jpg?resize=680%2C501\" alt=\"fake_soft_shadows_unity_indie_2\" width=\"680\" height=\"501\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/07\/fake_soft_shadows_unity_indie_2.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/07\/fake_soft_shadows_unity_indie_2.jpg?resize=300%2C221&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n<p>&#8212;<\/p>\n<p><strong>Image#3:<\/strong> Inverted shadow (shadow is light), could be useful for some effects?<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3093\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2014\/07\/15\/unity-indie-soft-shadows-directional-light\/inverted_shadow_cast_light_unity_3\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/07\/inverted_shadow_cast_light_unity_3.jpg?fit=680%2C517&amp;ssl=1\" data-orig-size=\"680,517\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"inverted_shadow_cast_light_unity_3\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/07\/inverted_shadow_cast_light_unity_3.jpg?fit=680%2C517&amp;ssl=1\" class=\"alignnone size-full wp-image-3093\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/07\/inverted_shadow_cast_light_unity_3.jpg?resize=680%2C517\" alt=\"inverted_shadow_cast_light_unity_3\" width=\"680\" height=\"517\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/07\/inverted_shadow_cast_light_unity_3.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/07\/inverted_shadow_cast_light_unity_3.jpg?resize=300%2C228&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n<p>&#8212;<\/p>\n<p>Image#4: Custom shader with inline unitySampleShadow(), without using autolight.inc..currently only works from certain angles..<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"3121\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2014\/07\/15\/unity-indie-soft-shadows-directional-light\/custom_shadow_shader_unity1\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/07\/custom_shadow_shader_unity1.png?fit=680%2C372&amp;ssl=1\" data-orig-size=\"680,372\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"custom_shadow_shader_unity1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/07\/custom_shadow_shader_unity1.png?fit=680%2C372&amp;ssl=1\" class=\"alignnone size-full wp-image-3121\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/07\/custom_shadow_shader_unity1.png?resize=680%2C372\" alt=\"custom_shadow_shader_unity1\" width=\"680\" height=\"372\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/07\/custom_shadow_shader_unity1.png?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/07\/custom_shadow_shader_unity1.png?resize=300%2C164&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using Unity Indie, modified directional hard light shadows. Forum thread: &#8211; http:\/\/forum.unity3d.com\/threads\/free-directional-light-soft-shadow-unity-indie.257432\/ &nbsp; How to: &#8211; Download builtin shader: http:\/\/unity3d.com\/unity\/download\/archive &#8211; copied UnityCG, UnityShaderVariables, HLSLSupport, AutoLight to assets folder &#8211; renamed these as: UnityCG2, \u200b\u200bUnityShaderVariables2, \u200b\u200bHLSLSupport2\u200b\u200b &#8211; created new shader file (that default diffuse) &#8211; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3089,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[13,3],"tags":[160,644,7,645,14,40,385],"class_list":["post-3088","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-shaders","category-unity3d","tag-blur","tag-directional","tag-fake","tag-hard","tag-shader","tag-shadow","tag-soft"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/07\/fake_soft_shadows_unity_indie_1.jpg?fit=680%2C480&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-NO","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/3088","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/comments?post=3088"}],"version-history":[{"count":14,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/3088\/revisions"}],"predecessor-version":[{"id":3124,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/3088\/revisions\/3124"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/3089"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=3088"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=3088"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=3088"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}