{"id":5282,"date":"2023-10-29T12:36:24","date_gmt":"2023-10-29T04:36:24","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=5282"},"modified":"2023-10-29T12:36:24","modified_gmt":"2023-10-29T04:36:24","slug":"2d%e7%ba%b9%e7%90%86%e5%a4%96%e6%8f%8f%e8%be%b9%e6%95%88%e6%9e%9c%e6%b5%8b%e8%af%95","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=5282","title":{"rendered":"2D\u7eb9\u7406\u5916\u63cf\u8fb9\u6548\u679c\u6d4b\u8bd5"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"524\" height=\"511\" src=\"http:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2023\/10\/image-11.png\" alt=\"\" class=\"wp-image-5283\" srcset=\"https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2023\/10\/image-11.png 524w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2023\/10\/image-11-300x293.png 300w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2023\/10\/image-11-51x50.png 51w\" sizes=\"(max-width: 524px) 100vw, 524px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"482\" height=\"275\" src=\"http:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2023\/10\/image-12.png\" alt=\"\" class=\"wp-image-5284\" srcset=\"https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2023\/10\/image-12.png 482w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2023\/10\/image-12-300x171.png 300w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2023\/10\/image-12-70x40.png 70w\" sizes=\"(max-width: 482px) 100vw, 482px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>Shader \"ImageEffect\/Outline\"\n{\n    Properties\n    {\n        _MainTex (\"Sprite Texture\", 2D) = \"white\" {}\n        _OutlineWidth (\"Outline Width\", Range(0, 10)) = 1\n        _OutlineColor (\"Outline Color\", Color) = (1.0, 1.0, 1.0, 1.0)\n        _OutlineColorPow(\"OutlineColorPow\", float) = 1\n        _AlphaThreshold (\"_AlphaThreshold\", Range(0, 1)) = 0.1\n    }\n    \n    SubShader\n    {\n        Blend SrcAlpha OneMinusSrcAlpha\n\n        Pass \n        {\n            CGPROGRAM\n            #pragma vertex vert\n            #pragma fragment frag\n            #include \"UnityCG.cginc\"\n\n            sampler2D _MainTex;\n            float4 _MainTex_ST;\n            half4 _MainTex_TexelSize;\n            float _OutlineWidth;\n            float4 _OutlineColor;\n            float _AlphaThreshold;\n            float _OutlineColorPow;\n\n            struct appdata\n            {\n                float4 vertex   : POSITION;\n                float2 uv : TEXCOORD0;\n                float4 normal : NORMAL;\n            };\n\n            struct v2f\n            {\n                float4 vertex   : SV_POSITION;\n                half2 uv  : TEXCOORD0;\n                half2 left : TEXCOORD1;\n                half2 right : TEXCOORD2;\n                half2 up : TEXCOORD3;\n                half2 down : TEXCOORD5;\n            };\n\n            v2f vert(appdata i)\n            {\n                v2f o;\n                o.vertex = o.vertex + i.normal * _OutlineWidth;\n                o.vertex = UnityObjectToClipPos(i.vertex);\n                o.uv = TRANSFORM_TEX(i.uv, _MainTex);\n                o.left = o.uv + half2(-1, 0) * _MainTex_TexelSize.xy * _OutlineWidth;\n                o.right = o.uv + half2(1, 0) * _MainTex_TexelSize.xy * _OutlineWidth;\n                o.up = o.uv + half2(0, 1) * _MainTex_TexelSize.xy * _OutlineWidth;\n                o.down = o.uv + half2(0, -1) * _MainTex_TexelSize.xy * _OutlineWidth;\n                return o;\n            }\n\n            fixed4 frag(v2f i) : SV_Target\n            {\n                fixed4 col = tex2D(_MainTex, i.uv);\n                half colorStep = step(col.a, _AlphaThreshold);\n                half4 selfColor = col * (1-colorStep);\n\n                float outlineAlpha = tex2D(_MainTex, i.left).a + tex2D(_MainTex, i.right).a \n                    + tex2D(_MainTex, i.up).a + tex2D(_MainTex, i.down).a;\n                half4 outColor = _OutlineColor * pow(outlineAlpha, _OutlineColorPow) * colorStep;\n\n                return selfColor + outColor;\n            }\n            ENDCG\n        }\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/5282"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5282"}],"version-history":[{"count":1,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/5282\/revisions"}],"predecessor-version":[{"id":5285,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/5282\/revisions\/5285"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5282"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5282"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5282"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}