{"id":2700,"date":"2014-02-10T22:23:07","date_gmt":"2014-02-10T19:23:07","guid":{"rendered":"http:\/\/unitycoder.com\/blog\/?p=2700"},"modified":"2014-10-13T20:53:08","modified_gmt":"2014-10-13T17:53:08","slug":"shadow-casting-2d","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2014\/02\/10\/shadow-casting-2d\/","title":{"rendered":"Shadow Casting 2D"},"content":{"rendered":"<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"2701\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2014\/02\/10\/shadow-casting-2d\/dynamic_shadow_casting_1\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/02\/dynamic_shadow_casting_1.jpg?fit=680%2C497&amp;ssl=1\" data-orig-size=\"680,497\" 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=\"dynamic_shadow_casting_1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/02\/dynamic_shadow_casting_1.jpg?fit=680%2C497&amp;ssl=1\" class=\"alignnone size-full wp-image-2701\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/02\/dynamic_shadow_casting_1.jpg?resize=680%2C497\" alt=\"dynamic_shadow_casting_1\" width=\"680\" height=\"497\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/02\/dynamic_shadow_casting_1.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/02\/dynamic_shadow_casting_1.jpg?resize=300%2C219&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n<p>Another fake shadow test.. (similar to the old <a title=\"http:\/\/unitycoder.com\/blog\/2012\/02\/15\/raycast-realtime-visibility-2-0\/\" href=\"http:\/\/unitycoder.com\/blog\/2012\/02\/15\/raycast-realtime-visibility-2-0\/\" target=\"_blank\">raycast version<\/a>, but should work with Physics2D).<br \/>\n<em>*This is currently abandoned..<\/em><\/p>\n<p><strong>See also:<\/strong><br \/>\n<a title=\"http:\/\/unitycoder.com\/blog\/2014\/10\/12\/2d-visibility-shadow-for-unity-indie\/\" href=\"http:\/\/unitycoder.com\/blog\/2014\/10\/12\/2d-visibility-shadow-for-unity-indie\/\" target=\"_blank\">http:\/\/unitycoder.com\/blog\/2014\/10\/12\/2d-visibility-shadow-for-unity-indie\/<\/a><\/p>\n<p><strong>Info:<\/strong><br \/>\n&#8211; Testing <a title=\"http:\/\/stackoverflow.com\/questions\/16542042\/fastest-way-to-sort-vectors-by-angle-without-actually-computing-that-angle\" href=\"http:\/\/stackoverflow.com\/questions\/16542042\/fastest-way-to-sort-vectors-by-angle-without-actually-computing-that-angle\" target=\"_blank\">PseudoAngle <\/a>to sort object positions<\/p>\n<p><strong>Todo:<\/strong><br \/>\n&#8211; Take shadow caster PolygonCollider2D vertices, check which one are visible to play<br \/>\n&#8211; ..<\/p>\n<p><strong>Webplayer:<\/strong><br \/>\n<a title=\"http:\/\/unitycoder.com\/upload\/demos\/Dynamic2DShadows1\/\" href=\"http:\/\/unitycoder.com\/upload\/demos\/Dynamic2DShadows1\/\" target=\"_blank\">http:\/\/unitycoder.com\/upload\/demos\/Dynamic2DShadows1\/<\/a> (v1, update speed is 0.1f)<\/p>\n<p><strong>Related forum topic:<\/strong><br \/>\n<a title=\"http:\/\/forum.unity3d.com\/threads\/165283-2D-Dynamic-Shadows\" href=\"http:\/\/forum.unity3d.com\/threads\/165283-2D-Dynamic-Shadows\" target=\"_blank\">http:\/\/forum.unity3d.com\/threads\/165283-2D-Dynamic-Shadows<\/a><\/p>\n<p>&#8212;<\/p>\n<p><strong>Snippets:<\/strong><\/p>\n<p>PseudoAngle (c#)<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nfloat pseudoAngle(float dx,float dy)\r\n{\r\nfloat ax = Mathf.Abs(dx);\r\nfloat ay = Mathf.Abs(dy);\r\nfloat p = dy\/(ax+ay);\r\nif (dx &lt; 0) p = 2 - p;\r\n\/\/# elif dy &lt; 0: p = 4 + p\r\nreturn p;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Another fake shadow test.. (similar to the old raycast version, but should work with Physics2D). *This is currently abandoned.. See also: http:\/\/unitycoder.com\/blog\/2014\/10\/12\/2d-visibility-shadow-for-unity-indie\/ Info: &#8211; Testing PseudoAngle to sort object positions Todo: &#8211; Take shadow caster PolygonCollider2D vertices, check which one are visible to play &#8211; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2701,"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_feature_clip_id":0,"_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":[4,1,3],"tags":[65,7,594,40,593],"class_list":["post-2700","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-demos","category-uncategorized","category-unity3d","tag-2d","tag-fake","tag-pseudoangle","tag-shadow","tag-shadow-casting"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2014\/02\/dynamic_shadow_casting_1.jpg?fit=680%2C497&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-Hy","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/2700","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=2700"}],"version-history":[{"count":9,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/2700\/revisions"}],"predecessor-version":[{"id":3317,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/2700\/revisions\/3317"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/2701"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=2700"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=2700"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=2700"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}