{"id":2204,"date":"2020-08-21T23:29:48","date_gmt":"2020-08-21T15:29:48","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=2204"},"modified":"2020-08-21T23:30:28","modified_gmt":"2020-08-21T15:30:28","slug":"shader%e6%9c%80%e7%ae%80%e5%8d%95%e7%9a%84unity%e9%98%b4%e5%bd%b1%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=2204","title":{"rendered":"[Shader]\u6700\u7b80\u5355\u7684Unity\u6295\u5c04\u548c\u63a5\u6536\u9634\u5f71\u4ee3\u7801"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>Shader \"Custom\/FullShadowShader\"\n{\n    Properties\n    {\n        _MainTex (\"Texture\", 2D) = \"white\" {}\n    }\n    SubShader\n    {\n        Tags { \"RenderType\"=\"Opaque\" }\n        LOD 100\n\n        Pass\n        {\n            Tags \n            {\n                \"LightMode\"=\"ForwardBase\"\n            }\n\n            Cull Off\n\n            CGPROGRAM\n            #pragma vertex vert\n            #pragma fragment frag\n            #pragma multi_compile_fwdbase_fullshadows \n            #include \"UnityCG.cginc\"\n            #include \"AutoLight.cginc\"\n            struct appdata\n            {\n                float4 vertex : POSITION;\n                float2 uv : TEXCOORD0;\n            };\n            struct v2f\n            {\n                float4 vertex : SV_POSITION;\n                float2 uv : TEXCOORD0;\n                float3 wpos: TEXCOORD1;\n                SHADOW_COORDS(2)\n            };\n\n            sampler2D _MainTex;\n            \n            v2f vert (appdata v)\n            {\n                v2f o;\n                o.vertex = UnityObjectToClipPos(v.vertex);\n                o.wpos = mul(unity_ObjectToWorld, v.vertex);\n                o.uv = v.uv;\n                TRANSFER_SHADOW(o);\n                return o;\n            }\n\n            fixed4 frag (v2f i) : SV_Target\n            {\n                UNITY_LIGHT_ATTENUATION(atten, i, i.wpos);\n                atten = saturate( atten* 2 );\n                fixed4 col = tex2D(_MainTex, i.uv);\n                return fixed4( col.rgb * atten, col.a);\n            }\n            ENDCG\n        }\n\n        Pass \n        {\n            Tags \n            {\n                \"LightMode\"=\"ShadowCaster\"\n            }\n            Offset 1, 1\n            Cull Off\n            CGPROGRAM\n            #pragma vertex vert\n            #pragma fragment frag\n            #include \"UnityCG.cginc\"\n            struct app_data \n            {\n                float4 vertex : POSITION;\n            };\n            struct v2f \n            {\n                V2F_SHADOW_CASTER;\n            };\n            v2f vert (app_data v) \n            {\n                v2f o;\n                TRANSFER_SHADOW_CASTER(o)\n                return o;\n            }\n            float4 frag(v2f i) : COLOR \n            {\n                SHADOW_CASTER_FRAGMENT(i)\n            }\n            ENDCG\n        }\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/2204"}],"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=2204"}],"version-history":[{"count":2,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/2204\/revisions"}],"predecessor-version":[{"id":2206,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/2204\/revisions\/2206"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}