{"id":73,"date":"2020-10-08T15:17:11","date_gmt":"2020-10-08T07:17:11","guid":{"rendered":"https:\/\/meecarlo.wordpress.com\/?p=73"},"modified":"2020-12-28T18:21:12","modified_gmt":"2020-12-28T10:21:12","slug":"shader%e5%85%a5%e9%97%a8-2%e8%b4%b4%e5%9b%be%e6%9d%90%e8%b4%a8","status":"publish","type":"post","link":"https:\/\/meecarlo.com\/old\/2020\/10\/08\/shader%e5%85%a5%e9%97%a8-2%e8%b4%b4%e5%9b%be%e6%9d%90%e8%b4%a8\/","title":{"rendered":"Shader\u5165\u95e8\u2014\u20142\u8d34\u56fe\u6750\u8d28"},"content":{"rendered":"\n<p>        \u672c\u8282\u6211\u4eec\u8fdb\u884c\u6750\u8d28\u4e0a\u6700\u57fa\u672c\u7684\u8d34\u56fe\u3002\u4e5f\u5c31\u662f\u6700\u5e38\u7528\u7684\u8d34\u56fe\u6750\u8d28\u7f16\u5199\u3002\u9996\u5148\u662funity shader\u7684\u4ee3\u7801\u7f16\u5199\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Shader\"Custom\/BaseTextureMatShader\"\n{\n    Properties{\n        _Color(\"Color Tint\",Color)=(1.0,1.0,1.0,1.0)\n        _MainTex(\"Main Texture\",2D)=\"white\"\n    }\n    Subshader{\n        Pass{\n            CGPROGRAM\n            #pragma vertex vert\n            #pragma fragmengt frag\n            fixed4 _Color;\n            sampler2D _MainTex;\n            \n            float4 vert(float4 pos:POSITION):SV_POSITION{\n                return UnityObjectToClipPos(pos);\n            }\n\n            fixed4 frag(float2 uv:TEXCOORD0):SV_Target{\n                return tex2D(_MainTex,uv);\n             }\n            \n            ENDCG\n        }\n    }\n    Fallback \"Diffuse\"\n}\n<\/code><\/pre>\n\n\n\n<p>        \u6211\u4eec\u7ee7\u7eed\u6765\u9010\u884c\u7ffb\u8bd1\uff0c\u4f46\u4e5f\u4e0d\u5fc5\u50cf\u4e4b\u524d\u90a3\u6837\u9010\u884c\uff0c\u6211\u4eec\u53ea\u7ffb\u8bd1\u7c7b\u6bd4\u4e0a\u4e00\u7bc7\u4ee3\u7801\u4e2d\u7684\u4e0d\u540c\u90e8\u5206\u3002\u9996\u5148\u6211\u4eec\u5728Properties\u4e0b\u589e\u52a0\u4e86_MainTex\u8fd9\u4e2a\u5c5e\u6027\uff0c\u4ed6\u7684\u9762\u677f\u540d\u79f0\u4e3a\u201cMain Tex\u201d\uff0c\u5c5e\u6027\u662f2D\u8d34\u56fe\uff0c\u9ed8\u8ba4\u662f\u767d\u8272\u3002\u7531\u4e8e\u6211\u4eec\u5728\u8fd9\u6b21shader\u4e2d\u8981\u8c03\u7528_MainTex\u8fd9\u4e2a\u81ea\u5b9a\u4e49\u5c5e\u6027\uff0c\u6240\u4ee5\u6211\u4eec\u8981\u5728Pass\u4e2d\u5b9a\u4e49\u5b83\u4e3asampler2D\u3002sampler2D\u662f\u4e00\u4e2aCG\u4e2d\u7684\u4e00\u4e2d\u6570\u636e\u7c7b\u578b\uff0c\u4e3b\u8981\u662f\u7528\u6765\u50a8\u5b58\u7eb9\u7406\u4fe1\u606f\u7684\uff0c\u5e38\u89c1\u7684\u4e00\u822c\u6709sampler\uff0csampler2D\uff0csamplerCUBE\u7b49\u3002\u6211\u4eec\u8fd9\u91cc\u8981\u5b9a\u4e49_MainTex\u6240\u4ee5\u8fdb\u884c\u5b9a\u4e49<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sampler2D _MainTex;\nfixed4 _Color;<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u6211\u4eec\u6b63\u5e38\u5b9a\u4e49\u9876\u70b9\u7740\u8272\u5668\u4e8e\u7247\u5143\u7740\u8272\u5668\u7684\u5165\u53e3\uff0c\u4e00\u822c\u6211\u4f1a\u76f4\u63a5\u5b9a\u4e49<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#pragma vertex vert\n#pragma fragmengt frag<\/code><\/pre>\n\n\n\n<p>        \u6211\u4eec\u6682\u65f6\u5148\u4e0d\u7ba1\u7ed3\u6784\u4f53struct\u7684\u4e66\u5199\uff0c\u6839\u636e\u4e0a\u7bc7\u7684\u5185\u5bb9\u6211\u4eec\u5e94\u8be5\u76f4\u63a5\u8fdb\u884c\u9876\u70b9\u7740\u8272\u5668\u7684\u7f16\u5199\uff0c\u6211\u4eec\u987a\u7740\u8fd9\u4e2a\u601d\u8def\u8d70<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>float4 vert(float4 vertex:POSITION):SV_POSITION{\n    return UnityObjectToClipPos(vertex);\n}<\/code><\/pre>\n\n\n\n<p>        \u8fd9\u90e8\u5206\u8ddf\u4e0a\u7bc7\u4e00\u6837\uff0c\u6211\u4eec\u7565\u8fc7\u7ffb\u8bd1\uff0c\u63a5\u7740\u6211\u4eec\u5f00\u59cb\u5199\u672c\u7bc7\u7684\u65b0\u5185\u5bb9\uff0c\u7eb9\u7406\u8d34\u56fe\u3002_MainTex,<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fixed4 frag( float2 uv:TEXCOORD0):SV_Target{\n    return tex2D(_MainTex,uv);\n}<\/code><\/pre>\n\n\n\n<p>        \u8fd9\u90e8\u5206\uff0c\u5df2\u7ecf\u6709\u4e86\u533a\u522b\uff0c\u9996\u5148\u6211\u4eec\u7684\u7247\u5143\u7740\u8272\u5668\u9700\u8981\u8f93\u5165\u6e32\u67d3pipline\u4e2d\u4e09\u89d2\u5f62\u904d\u5386\u540e\u6240\u4ea7\u751f\u7684UV\uff0c\u53c8\u56e0\u4e3aUV\u53ea\u662f\u4e00\u4e2a\u4e8c\u7ef4\u5750\u6807\uff0c\u6240\u4ee5\u4ee5float2\u6765\u5b9a\u4e49\uff0c\u800cTEXCOORD0\u5219\u662f\u5c06\u7b2c\u4e00\u5957\u7eb9\u7406\u6307\u5b9a\u7ed9UV\u8fd9\u4e2a\u53c2\u6570\uff0c\u8ba9\u5176\u83b7\u5f97\u4e0a\u4e00\u6b65\u7247\u5143\u5750\u6807\u53c2\u6570\u3002\u4e4b\u540e\u6211\u4eec\u5728\u51fd\u6570\u4e2d\u8fd4\u56de\u7684\u662f\u4e00\u4e2atex2D\u7684\u503c\uff0ctex2D\u662f\u4e00\u4e2a\u5bf9\u7eb9\u7406\u91c7\u6837\u7684\u503c\uff0c\u4ed6\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u9700\u8981\u88ab\u91c7\u6837\u7684\u503c\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u4e00\u4e2afloat2\u7684\u7eb9\u7406\u5750\u6807\u3002\u6240\u4ee5\u8fd9\u4e2a\u8fc7\u7a0b\u7b49\u4e8e\u5728\u50cf\u7d20\u70b9\u4e0a\u8fdb\u884c\u70b9\u5bf9\u70b9\u7684\u6d82\u8272\u3002\u6240\u4ee5\u6309\u7167\u4e0a\u4e00\u7bc7\u7684\u601d\u8def\uff0c\u6211\u4eec\u7684texture shader\u5e94\u8be5\u662f\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Shader\"Custom\/textureShader\"{\n    Properties{\n        _MainTex(\"Main Tex\",2D)=\"white\"{}\n        _Color(\"COlor Tint\",Color)=(1,1,1,1)\n    }\n    Subshader{\n        Pass{\n            CGPROGRAM\n            #pragma vertex vert\n            #pragma fragment frag\n\n            fixed4 _Color;\n            sampler2D _MainTex;\n\n            float4 vert (float4 vertex:POSITION):SV_POSITION{\n                return UnityObjectToClipPos(vertex);\n            }\n\n            fixed4 frag(float2 uv:TEXCOORD0):SV_Target{\n                return tex2D(_MainTex,uv);\n            }\n\n            ENDCG\n        }\n\n    }\n    Fallback \"Diffuse\"\n}<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e2ashader\u5728unity\u4e2d\u6ca1\u6709\u62a5\u9519\uff0c\u4f46\u5448\u73b0\u7684\u6548\u679c\u4e0d\u662f\u6211\u4eec\u60f3\u8981\u7684\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"574\" height=\"363\" src=\"http:\/\/meecarlo.com\/wp-content\/uploads\/2020\/12\/4.png\" alt=\"\" class=\"wp-image-486\" srcset=\"https:\/\/meecarlo.com\/old\/wp-content\/uploads\/2020\/12\/4.png 574w, https:\/\/meecarlo.com\/old\/wp-content\/uploads\/2020\/12\/4-300x190.png 300w\" sizes=\"auto, (max-width: 574px) 100vw, 574px\" \/><figcaption>\u6211\u4eec\u5e76\u4e0d\u662f\u60f3\u8981\u8fd9\u79cd\u7eaf\u8272\u7684\u8d34\u56fe\uff0c\u800c\u662f\u66f4\u52a0\u4e30\u5bcc\u7684<\/figcaption><\/figure>\n\n\n\n<p>        \u4f46\u8fd9\u4e2a\u9519\u8bef\u53ea\u57285.6\u4e4b\u540e\u7684\u7248\u672c\u6709\uff0c5.6\u4e4b\u524d\u7684\u6ca1\u6709\uff0c\u53ea\u80fd\u8bf4\u662f\u66f4\u65b0\u9519\u8bef\u7684\u9505\uff0c\u6709\u4e00\u79cd\u89e3\u91ca\u662f\uff0c5.6\u66f4\u65b0\u4e4b\u540e\u4e00\u4e2a\u7279\u6027\u662f\u4e0d\u80fd\u76f4\u63a5\u5728vertex\u7684\u51fd\u6570\u4e2d\u83b7\u53d6POSITION\u518d\u8fd4\u56de\uff0c\u5fc5\u987b\u8981\u4ece\u7ed3\u6784\u4f53\u4e2d\u83b7\u53d6\u518d\u8fd4\u56de\uff0c\u4f46\u6211\u8bd5\u4e86\u8bd5\u8fd9\u79cd\u8bf4\u6cd5\uff0c\u4f9d\u7136\u4e0d\u884c\uff0c\u5e94\u8be5\u662f\u5728vertex\u4e0efragment\u4e2d\u540c\u65f6\u53c8\u76f8\u540c\u7684UV\u7684\u5750\u6807\u8fd4\u56de\u624d\u80fd\u6709\u6b63\u5e38\u7684\u7ed3\u679c\uff0c\u4e5f\u5c31\u662f\u8bf4vertex\u4e0efragment\u4e2d\u7684uv\u5e94\u5f53\u5339\u914d\u624d\u80fd\u6709\u6b63\u786e\u7684\u7ed3\u679c\uff0c\u6240\u4ee5\u6211\u4eec\u8fdb\u884c\u7ed3\u6784\u4f53\u7684\u7f16\u5199\uff0c\u8fd9\u90e8\u5206\u7f16\u5199\u4e0eC\u8bed\u8a00\u5f88\u76f8\u4f3c\u9996\u5148\u662f\u9876\u70b9\u7740\u8272\u5668\u7684\u8f93\u5165\u7ed3\u6784\u4f53\uff0c\u9996\u5148\u6211\u4eec\u8981\u4ece\u9876\u70b9\u6570\u636e\u4e2d\u83b7\u5f97\u4e24\u4e2a\u6570\u636e\uff0c\u4e00\u4e2a\u662f\u6211\u4eec\u4e00\u5b9a\u8981\u7684\u9876\u70b9\u5750\u6807\uff0c\u4e5f\u5c31\u662fPOSITION\uff0c\u53e6\u5916\u4e00\u4e2a\u662f\u9876\u70b9\u7684UV\u5750\u6807\u4e5f\u5c31\u662f\u8bf4\u57fa\u4e8e\u6a21\u578b\u672c\u8eab\u53c2\u8003\u7cfb\u7684UV\u5750\u6807\u8fdb\u884c\u8f6c\u6362\u6210\u6211\u4eec\u9700\u8981\u7684\u57fa\u4e8e\u6444\u50cf\u673a\u7684UV\u5750\u6807\uff0c\u6240\u4ee5\u6211\u4eec\u7b2c\u4e00\u4e2a\u7ed3\u6784\u4f53\u53ef\u4ee5\u8fd9\u4e48\u5199<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>struct a2v{\n        float4 vertex:POSITION;\n        float2 uv:TEXCOORD0;\n};<\/code><\/pre>\n\n\n\n<p>        \u5199\u5b8c\u4e86\u7ed3\u6784\u4f53\uff0c\u6211\u4eec\u53ef\u4ee5\u5728vertex\u4e2d\u76f4\u63a5\u8c03\u7528\u8fd9\u4e2a\u7ed3\u6784\u4f53\u4f5c\u4e3a\u8f93\u5165<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>v2f vert(a2v v):SV_POSITION{\n    v2f o;\n    o.vertex=UnityObjectToClipPos(v.vertex);\n    o.uv=v.uv;\n    return o;\n}<\/code><\/pre>\n\n\n\n<p>        \u5f53\u6211\u4eec\u8fdb\u884c\u5e26\u6709\u7ed3\u6784\u4f53\u7684\u9876\u70b9\u7740\u8272\u5668\u7684\u7f16\u8f91\u7684\u65f6\u5019\uff0c\u7531\u4e8e\u8f93\u51fa\u7684\u5e76\u4e0d\u4e00\u5b9a\u662f\u540c\u4e00\u7c7b\u578b\u7684\u6570\u636e\uff0c\u6240\u4ee5\u6211\u4eec\u4e0d\u4f1a\u5728\u51fd\u6570\u4e0a\u8fdb\u884c\u8f93\u51fa\u5b9a\u4e49\uff0c\u6211\u4eec\u8f93\u51fa\u7684\u66f4\u591a\u662f\u4e00\u4e2a\u5e26\u6709\u591a\u79cd\u5c5e\u6027\u7684\u53c2\u6570\uff0c\u4e00\u822c\u6211\u4eec\u5c31\u7528o\u6765\u4f5c\u4e3a\u9876\u70b9\u7740\u8272\u5668\u7684\u8f93\u51fa\u53c2\u6570\u3002\u6240\u4ee5\u8fd9\u4e2a\u9876\u70b9\u7740\u8272\u5668\u7684\u8f93\u5165\u662f\u53c2\u6570v\uff0cv\u7684\u6570\u636e\u4ece\u6e32\u67d3pipline\u7684\u9876\u70b9\u6570\u636e\u53d6\u5f97\u3002v2f o;\u4e2d\u7684v2f \u4e5f\u662fCG\u4e2d\u7684\u8bed\u53e5\uff0c\u610f\u601d\u662fvertex to fragment \u5c06\u9876\u70b9\u7740\u8272\u5668\u4e2d\u7684\u6570\u636e\u4f20\u8f93\u5230\u7247\u5143\u7740\u8272\u5668\u4e2d\uff0c\u76f8\u5f53\u4e8e\u4e00\u4e2a\u53c2\u6570\u5b9a\u4e49\uff0c\u5c06\u8f93\u51fa\u7684\u53c2\u6570\u6682\u65f6\u5148\u50a8\u5b58\u5728o\u4e0b\u9762\u3002\u800co.uv=v.uv\u5c31\u662f\u5b57\u9762\u610f\u4e49\u7684\u5750\u6807\u4f20\u8f93\u3002<\/p>\n\n\n\n<p>        \u63a5\u7740\u6211\u4eec\u6765\u5b9a\u4e49fragment\u7684\u7ed3\u6784\u4f53\uff0c\u6211\u4eec\u4ece\u9876\u70b9\u7740\u8272\u5668\u62ff\u5230\u4e86\u4ec0\u4e48\uff1f\u53d8\u6362\u540e\u7684\u9876\u70b9\u5750\u6807\u4e0euv\u5750\u6807\uff0c\u90a3\u6211\u4eec\u8981\u8f93\u51fa\u4ec0\u4e48\uff0c\u9876\u70b9\u5750\u6807\u4e0d\u7528\u53d8\u6362\uff0c\u4f46\u6211\u4eec\u9700\u8981\u8f93\u51fa\u7684\u662f\u4e00\u5f20\u6211\u4eec\u51c6\u5907\u597d\u7684\u81ea\u5b9a\u4e49\u8d34\u56fe\u800c\u4e0d\u662f\u5355\u7eaf\u7684uv\u5750\u6807\uff0c\u6240\u4ee5\u6211\u4eec\u8981\u7528\u6211\u4eec\u51c6\u5907\u597d\u7684_MainTex\u5339\u914d\u6240\u5f97\u5230\u7684uv\u5750\u6807\uff0c\u901a\u4fd7\u7684\u8bb2\u5c31\u662f\u7528\u8d34\u56fe\uff0c\u70b9\u5bf9\u70b9\u7684\u8fdb\u884c\u6bcf\u4e00\u4e2a\u50cf\u7d20\u7684\u989c\u8272\u586b\u5145\u3002\u6240\u4ee5\u6211\u4eec\u9996\u5148\u5b9a\u4e49\u7ed3\u6784\u4f53<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>struct v2f{\n    float4 pos:SV_POSITION;\n    float2 uv:TEXCOORD1;\n};<\/code><\/pre>\n\n\n\n<p>    \u6211\u4eec\u5c06\u88c1\u526a\u540e\u7684\u9876\u70b9\u6570\u636e\u7ed9\u5230pos\uff0c\u7b2c\u4e8c\u5957\u7eb9\u7406\u5750\u6807\u7ed9\u5230uv\u4f5c\u4e3afragment\u7684\u8f93\u5165\u3002\u4e4b\u540e\u6211\u4eec\u7247\u5143\u7740\u8272\u5668\u7684\u8f93\u51fa\u4f9d\u65e7\u662ffixed4\u989c\u8272\uff0c\u4f46\u8fd9\u91cc\u6211\u4eec\u5c06\u7528tex2D\u51fd\u6570\u8fdb\u884c\u5bf9\u5750\u6807\u7684\u586b\u5145\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fixed4 frag(v2f i):SV_Target{\n    return tex2D(_MainTex,i.uv)\n}<\/code><\/pre>\n\n\n\n<p>    \u7ed3\u5408\u4e0a\u6587\uff0c\u6211\u4eec\u7684\u5b8c\u6574\u4ee3\u7801\u5e94\u8be5\u662f\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Shader\"Custom\/textureShader\"{\n\tProperties{\n\t\t_MainTex(\"Main Tex\",2D) = \"white\"{}\n\t\t_Color(\"COlor Tint\",Color) = (1,1,1,1)\n\t}\n\t\tSubshader{\n\t\t\tPass{\n\t\t\t\tCGPROGRAM\n\t\t\t\t#pragma vertex vert\n\t\t\t\t#pragma fragment frag\n\n\t\t\t\tfixed4 _Color;\n\t\t\t\tsampler2D _MainTex;\n\n\t\t\t\tstruct a2v {\n\t\t\t\t\tfloat4 vertex:POSITION;\n\t\t\t\t\tfloat4 uv:TEXCOORD0;\n\t\t\t\t};\n\n\t\t\t\tstruct v2f {\n\t\t\t\t\tfloat4 pos:SV_POSITION;\n\t\t\t\t\tfloat2 uv:TEXCOORD1;\n\t\t\t\t};\n\n\t\t\t\tv2f vert(a2v v):SV_POSITION {\n\t\t\t\t\tv2f o;\n\t\t\t\t\to.pos = UnityObjectToClipPos(v.vertex);\n\t\t\t\t\to.uv = v.uv;\n\t\t\t\t\treturn o;\n\t\t\t\t}\n\n\t\t\t\tfixed4 frag(v2f i) :SV_Target{\n\t\t\t\t\treturn tex2D(_MainTex,i.uv);\n\t\t\t\t}\n\n\t\t\t\tENDCG\n\t\t\t}\n\n\t\t}\n\t\t\tFallback \"Diffuse\"\n}<\/code><\/pre>\n\n\n\n<p>    \u4f46\u522b\u6025\u5f97\u6fc0\u52a8\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u4ee3\u7801\u4f1a\u62a5\u9519\uff0c\u4ed6\u7ed9\u7684\u62a5\u9519\u4fe1\u606f\u5e94\u8be5\u662f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>invalid output semantic 'SV_POSITION': Legal indices are in &#91;0,0]<\/code><\/pre>\n\n\n\n<p>    \u9519\u8bef\u662f\u5728SV_POSITION\u8fd9\u4e2a\u8bed\u4e49\u4e0a\uff0c\u6211\u4eec\u518d\u6b21\u7406\u89e3\u4e0b\u8fd9\u4e2a\u8bed\u4e49\uff0cSV_POSITION\u662f\u88c1\u526a\u4e4b\u540e\u7684\u7a7a\u95f4\u9876\u70b9\u5750\u6807\uff0c\u8fd9\u4e2a\u4fe1\u606f\u6211\u4eec\u5e94\u8be5\u5b58\u50a8\u5728\u4e86struct v2f\u8fd9\u4e2a\u7ed3\u6784\u4f53\u7684pos\u4e4b\u4e2d\uff0c\u800c\u8fd9\u4e2a\u7ed3\u6784\u4f53\u5df2\u7ecf\u5728frag\u4f5c\u4e3a\u8f93\u5165\u4e2d\u8f93\u51fa\u4e86\u8fd9\u4e2a\u9876\u70b9\u95f4\u5750\u6807\uff0c\u800cv2f vert(a2v v)\u6240\u8f93\u51fa\u7684\u4e5f\u5e76\u4e0d\u662f\u4ec5\u4ec5\u7684\u7a7a\u95f4\u5750\u6807\uff0c\u5728\u8fd9\u5176\u5b9e\u628aSV_POSITION\u5220\u9664\u662f\u4e00\u4e2a\u6b63\u786e\u7684\u9009\u9879\u3002\u6240\u4ee5\u4fee\u6539\u4e4b\u540e\u7684\u4ee3\u7801\u662f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Shader\"Custom\/textureShader\"{\n\tProperties{\n\t\t_MainTex(\"Main Tex\",2D) = \"white\"{}\n\t\t_Color(\"COlor Tint\",Color) = (1,1,1,1)\n\t}\n\t\tSubshader{\n\t\t\tPass{\n\t\t\t\tCGPROGRAM\n\t\t\t\t#pragma vertex vert\n\t\t\t\t#pragma fragment frag\n\n\t\t\t\tfixed4 _Color;\n\t\t\t\tsampler2D _MainTex;\n\n\t\t\t\tstruct a2v {\n\t\t\t\t\tfloat4 vertex:POSITION;\n\t\t\t\t\tfloat4 uv:TEXCOORD0;\n\t\t\t\t};\n\n\t\t\t\tstruct v2f {\n\t\t\t\t\tfloat4 pos:SV_POSITION;\n\t\t\t\t\tfloat2 uv:TEXCOORD1;\n\t\t\t\t};\n\n\t\t\t\tv2f vert(a2v v){\n\t\t\t\t\tv2f o;\n\t\t\t\t\to.pos = UnityObjectToClipPos(v.vertex);\n\t\t\t\t\to.uv = v.uv;\n\t\t\t\t\treturn o;\n\t\t\t\t}\n\n\t\t\t\tfixed4 frag(v2f i) :SV_Target{\n\t\t\t\t\treturn tex2D(_MainTex,i.uv);\n\t\t\t\t}\n\n\t\t\t\tENDCG\n\t\t\t}\n\n\t\t}\n\t\t\tFallback \"Diffuse\"\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"693\" height=\"369\" src=\"http:\/\/meecarlo.com\/wp-content\/uploads\/2020\/12\/5.png\" alt=\"\" class=\"wp-image-487\" srcset=\"https:\/\/meecarlo.com\/old\/wp-content\/uploads\/2020\/12\/5.png 693w, https:\/\/meecarlo.com\/old\/wp-content\/uploads\/2020\/12\/5-300x160.png 300w\" sizes=\"auto, (max-width: 693px) 100vw, 693px\" \/><figcaption>\u6b63\u786e\u8f93\u51fa\u7684\u8d34\u56fe\u7eb9\u7406<\/figcaption><\/figure>\n\n\n\n<p>        \u81f3\u6b64\uff0c\u6211\u4eec\u5728unity shader\u7684\u7f16\u5199\u7ed3\u675f\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>        \u6211\u4eec\u63a5\u7740\u5728shader graph\u4e2d\u5b9e\u73b0\u6211\u4eec\u7684\u8d34\u56fe\u6548\u679c<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1366\" height=\"728\" src=\"http:\/\/meecarlo.com\/wp-content\/uploads\/2020\/12\/6-1024x546.png\" alt=\"\" class=\"wp-image-488\" srcset=\"https:\/\/meecarlo.com\/old\/wp-content\/uploads\/2020\/12\/6-1024x546.png 1024w, https:\/\/meecarlo.com\/old\/wp-content\/uploads\/2020\/12\/6-300x160.png 300w, https:\/\/meecarlo.com\/old\/wp-content\/uploads\/2020\/12\/6-768x409.png 768w, https:\/\/meecarlo.com\/old\/wp-content\/uploads\/2020\/12\/6.png 1366w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><figcaption>shader graph\u4e2d\u76842D\u7eb9\u7406\u8d34\u56fe<\/figcaption><\/figure>\n\n\n\n<p>        \u9700\u8981\u6ce8\u610f\u7684\u662f\u5982\u679c\u6211\u4eec\u76f4\u63a5\u521b\u5efatexture\u8282\u70b9\u662f\u4e0d\u80fd\u76f4\u63a5\u62d6\u5165Albedo\u7684\u8f93\u5165\u7684\uff0c\u5728shader graph\u4e2d\u9700\u8981\u50cf\u4e0a\u9762\u7684shader\u4ee3\u7801\u4e00\u6837\uff0c\u8fdb\u884c\u4e00\u4e2a\u7eb9\u7406\u503c\u7684\u91c7\u6837\u624d\u80fd\u6b63\u5e38\u8f93\u5165albedo\u3002\u6240\u4ee5\u6211\u4eec\u8981\u5c06texture\u8282\u70b9\u4f5c\u4e3a\u8f93\u5165\u8fde\u63a5sampler2D\u8fd9\u4e2a\u8282\u70b9\uff0c\u7136\u540e\u518d\u5c06sampler2D\u8fd9\u4e2a\u8282\u70b9\u7684\u8f93\u51fa\u4f5c\u4e3aalbedo\u7684\u8f93\u5165\u3002<\/p>\n\n\n\n<p>        \u7136\u540e\u662f\u6211\u4eec\u518dUE4\u4e2d\u7684\u6750\u8d28shader\u7f16\u5199\uff0c\u5728UE4\u7684shader\u7f16\u8f91\u4e2d\uff0c\u4ed6\u7684texture sample\u8282\u70b9\u4f1a\u603b\u52a8\u5c06\u7eb9\u7406\u8fdb\u884c\u91c7\u6837\uff0c\u6240\u4ee5\u6211\u4eec\u53ea\u9700\u8981\u8fdb\u884c\u5c06texture sample\u7684rgb\u8282\u70b9\u8fde\u63a5\u5230basecolor\u5c31\u80fd\u5c06\u7eb9\u7406\u8f93\u51fa<\/p>\n\n\n\n<p>       <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"579\" src=\"http:\/\/meecarlo.com\/wp-content\/uploads\/2020\/12\/7-1024x579.png\" alt=\"\" class=\"wp-image-490\" srcset=\"https:\/\/meecarlo.com\/old\/wp-content\/uploads\/2020\/12\/7-1024x579.png 1024w, https:\/\/meecarlo.com\/old\/wp-content\/uploads\/2020\/12\/7-300x169.png 300w, https:\/\/meecarlo.com\/old\/wp-content\/uploads\/2020\/12\/7-768x434.png 768w, https:\/\/meecarlo.com\/old\/wp-content\/uploads\/2020\/12\/7.png 1278w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>UE4\u4e2d\u7684\u7eb9\u7406\u8d34\u56fe<\/figcaption><\/figure>\n\n\n\n<p>        SD\u4e2d\u8fdb\u884c\u7eb9\u7406\u8d34\u56fe\u4e0eUE4\u4e2d\u76f8\u4f3c\uff0c\u4f46\u8d34\u56fe\u8282\u70b9\u7684\u540d\u79f0\u4e3abitmap\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"650\" src=\"http:\/\/meecarlo.com\/wp-content\/uploads\/2020\/12\/9-1024x650.png\" alt=\"\" class=\"wp-image-492\" srcset=\"https:\/\/meecarlo.com\/old\/wp-content\/uploads\/2020\/12\/9-1024x650.png 1024w, https:\/\/meecarlo.com\/old\/wp-content\/uploads\/2020\/12\/9-300x190.png 300w, https:\/\/meecarlo.com\/old\/wp-content\/uploads\/2020\/12\/9-768x488.png 768w, https:\/\/meecarlo.com\/old\/wp-content\/uploads\/2020\/12\/9.png 1079w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>SD\u4e2d\u7684bitmap\u8282\u70b9<\/figcaption><\/figure>\n\n\n\n<p>        bitmap\u4e3b\u8981\u5b58\u50a8\u7684\u662f\u4e00\u4e2argba\u7684\u50cf\u7d20\u7ec4\uff0c\u4f46SD\u4f5c\u4e3a\u4e00\u4e2a\u9020\u8f6e\u5b50\u7684\u8f6f\u4ef6\uff0c\u4ed6\u7684\u6750\u8d28\u4e0d\u9700\u8981\u5bf9geometry\u8d1f\u8d23\uff0c\u6240\u4ee5\u4e00\u822c\u4e0d\u4f1a\u5728SD\u4e2d\u8fdb\u884c\u4f7f\u7528\u8d34\u56fe\uff0c\u4e5f\u6709\u5176\u4ed6\u7684\u60c5\u51b5\u9700\u8981\u8fdb\u884c\u8d4b\u4e88\u8d34\u56fe\uff0c\u8fd9\u91cc\u4e0d\u518d\u8d58\u8ff0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u8282\u6211\u4eec\u8fdb\u884c\u6750\u8d28\u4e0a\u6700\u57fa\u672c\u7684\u8d34\u56fe\u3002\u4e5f\u5c31\u662f\u6700\u5e38\u7528\u7684\u8d34\u56fe\u6750\u8d28\u7f16\u5199\u3002\u9996\u5148\u662funity shader\u7684\u4ee3\u7801\u7f16\u5199\u3002 \u6211\u4eec\u7ee7 &hellip; <a href=\"https:\/\/meecarlo.com\/old\/2020\/10\/08\/shader%e5%85%a5%e9%97%a8-2%e8%b4%b4%e5%9b%be%e6%9d%90%e8%b4%a8\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">Shader\u5165\u95e8\u2014\u20142\u8d34\u56fe\u6750\u8d28<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":336,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,1],"tags":[],"class_list":["post-73","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-study-note","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/meecarlo.com\/old\/wp-json\/wp\/v2\/posts\/73","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meecarlo.com\/old\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meecarlo.com\/old\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meecarlo.com\/old\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/meecarlo.com\/old\/wp-json\/wp\/v2\/comments?post=73"}],"version-history":[{"count":3,"href":"https:\/\/meecarlo.com\/old\/wp-json\/wp\/v2\/posts\/73\/revisions"}],"predecessor-version":[{"id":564,"href":"https:\/\/meecarlo.com\/old\/wp-json\/wp\/v2\/posts\/73\/revisions\/564"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/meecarlo.com\/old\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/meecarlo.com\/old\/wp-json\/wp\/v2\/media?parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meecarlo.com\/old\/wp-json\/wp\/v2\/categories?post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meecarlo.com\/old\/wp-json\/wp\/v2\/tags?post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}