{"id":2431,"date":"2022-01-03T23:35:58","date_gmt":"2022-01-03T15:35:58","guid":{"rendered":"http:\/\/www.u3d8.com\/?p=2431"},"modified":"2022-01-07T14:41:53","modified_gmt":"2022-01-07T06:41:53","slug":"shader%e5%9b%ba%e5%ae%9a%e7%ae%a1%e7%ba%bf%e7%9d%80%e8%89%b2%e5%99%a8","status":"publish","type":"post","link":"http:\/\/www.u3d8.com\/?p=2431","title":{"rendered":"Shader\u56fa\u5b9a\u7ba1\u7ebf\u7740\u8272\u5668"},"content":{"rendered":"\n<h2>\u4ecb\u7ecd<\/h2>\n\n\n\n<p>\u56fa\u5b9a\u6e32\u67d3\u7ba1\u7ebfshader(fixed function shader)\uff0c\u662f\u76f8\u5bf9\u4e8e\u53ef\u7f16\u7a0b\u7684shader\u800c\u8a00\u7684\u3002<br>\u6240\u8c13\u56fa\u5b9a\u7ba1\u7ebf\uff0c\u662f\u8bf4\u82af\u7247\u4e0a\u4e00\u7ec4\u7535\u8def\u5df2\u7ecf\u56fa\u5b9a\u5b9e\u73b0\u4e86\u7279\u5b9a\u7684\u8fd0\u7b97\u529f\u80fd\uff0c\u7a0b\u5e8f\u80fd\u505a\u7684\u53ea\u662f\u63d0\u4f9b\u573a\u666f\u6570\u636e\u4ee5\u53ca\u5fae\u8c03\u8fd0\u7b97\u529f\u80fd\u7684\u53c2\u6570\u3002<br>\u5b83\u9002\u7528\u4e8e\u6240\u6709\u7684\u663e\u5361\uff0c\u5e38\u7528\u4e8e\u9ad8\u7ea7Shader\u5728\u8001\u663e\u5361\u65e0\u6cd5\u663e\u793a\u65f6\u7684Fallback\u3002<br>Unity\u4e2d\u7684\u56fa\u5b9a\u7ba1\u7ebfshader\u4f7f\u7528ShaderLab\u8bed\u8a00\u3002<\/p>\n\n\n\n<p>\u5b83\u7684\u706f\u5149\u516c\u5f0f\u3001\u8d34\u56fe\u65b9\u5f0f\u7b49\u662f\u56fa\u5b9a\u7684\uff0c\u4e0d\u80fd\u81ea\u5b9a\u4e49\u7684\u4fee\u6539\uff0c\u6211\u4eec\u53ea\u80fd\u63a7\u5236\u529f\u80fd\u7684\u5f00\u548c\u5173<\/p>\n\n\n\n<h2>Material<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Shader \"Custom\/fixed function1\"\n{\n    Properties\n    {\n        _Color(\"Main Color\", color) = (1,1,1,1)\n        _Ambient(\"Ambient\", color) = (0.5,0.5,0.5,1)\n        _Specular(\"Specular\", color) = (1,1,1,1)\n        _Shininess(\"Shininess\", range(0,8)) = 4\n        _Emission(\"Emission\", color) = (1,1,1,1)\n    }\n    SubShader{\n        Pass{\n            \/\/\u6f2b\u53cd\u5c04\u9700\u8981\u6253\u5f00\u5149\u7167\n            Lighting On\n            \/\/\u5f00\u542f\u955c\u9762\u53cd\u5c04\uff08\u9ed8\u8ba4\u7684\u662f\u6f2b\u53cd\u5c04\uff0c\u9700\u8981\u955c\u9762\u53cd\u5c04\u7684\u65f6\u5019\u9700\u8981\u6253\u5f00\u955c\u9762\u53cd\u5c04\uff09\n            SeparateSpecular On\n            Material\n            {\n                Diffuse(1,0,0,1)\/\/\u56fa\u5b9a\u6f2b\u53cd\u5c04\n                Diffuse&#91;_Color]\/\/\u53ef\u8c03\u6f2b\u53cd\u5c04\n                \/\/\u5f53\u6f2b\u53cd\u5c04\u8c03\u6210\u767d\u8272\uff0c\u5c31\u53ef\u4ee5\u770b\u51fa\u73af\u5883\u5149\u7684\u6548\u679c\n                Ambient&#91;_Ambient]\/\/\u53ef\u8c03\u73af\u5883\u5149\u989c\u8272\n                Emission&#91;_Emission]\/\/\u81ea\u53d1\u5149\u989c\u8272,\u5f3a\u5ea6\u6bd4\u8f83\u9ad8\n                \/\/\u4e0b\u9762\u662f\u955c\u9762\u53cd\u5c04\n                \/\/\u9ad8\u5149\u989c\u8272\n                Specular&#91;_Specular]\n                \/\/\u5149\u6cfd\u5ea6(range)\u8c03\u6574\u5149\u6cfd\u5ea6\u7684\u65f6\u5019\u4e00\u822c\u90fd\u5148\u5173\u95ed\u81ea\u53d1\u5149\uff08\u81ea\u53d1\u5149\u7684\u5f3a\u5ea6\u9ad8\uff0c\u5f71\u54cd\u6548\u679c\uff09\n                Shininess&#91;_Shininess]\n            }\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<h2>TextureSetup<\/h2>\n\n\n\n<ul><li>Combine\uff1a\u5c06\u4e24\u79cd\u989c\u8272\u8fdb\u884c\u6df7\u5408\uff0c\u53ef\u4ee5\u662f\u4e0a\u6b21SetTexture\u7684\u5904\u7406\u7ed3\u679c\uff0c\uff08previous\u3001constant\u3001primary\u3001Texture\u4e2d\u7684\u4e00\u79cd\uff09<\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote\"><p><strong>Previous<\/strong>\u00a0is the the result of the previous SetTexture.\u00a0<br>\u4e0a\u4e00\u6b21SetTexture\u7684\u7ed3\u679c<\/p><p><strong>Primary<\/strong>\u00a0is the color from the\u00a0lighting calculation\u00a0or the vertex color if it is\u00a0bound.\u00a0<br>\u6765\u81ea\u5149\u7167\u8ba1\u7b97\u7684\u989c\u8272\u6216\u662f\u5f53\u5b83\u7ed1\u5b9a\u65f6\u7684\u9876\u70b9\u989c\u8272<\/p><p><strong>Texture<\/strong>\u00a0is the color of the texture specified by\u00a0<em>[_TextureName]<\/em>\u00a0in the SetTexture (see above).\u00a0<br>\u5728SetTexture\u4e2d\u88ab\u5b9a\u4e49\u7684\u7eb9\u7406\u7684\u989c\u8272<\/p><p><strong>Constant<\/strong>\u00a0is the color specified in\u00a0<strong>ConstantColor<\/strong>.\u00a0<br>\u88abConstantColor\u5b9a\u4e49\u7684\u989c\u8272<\/p><\/blockquote>\n\n\n\n<ul><li>constantColor\uff1a\u8bbe\u7f6e\u4e00\u4e2a\u5e38\u91cf\u7684\u989c\u8272\u503c<\/li><li>matriax:\u8bbe\u7f6e\u77e9\u9635\u7eb9\u7406\u5750\u6807\u8fdb\u884c\u53d8\u6362<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>Shader \"Custom\/Texture\"\n{\n    Properties\n    {\n        _MainTex(\"\u7eb9\u7406\u56fe\u7247\",2D)=\"\"{}\n        _SeconTex(\"\u7b2c\u4e8c\u4e2a\u7eb9\u7406\",2D)=\"\"{}\n        _MainCol(\"\u6f2b\u53cd\u5c04\u989c\u8272\",Color)=(1,0,0,1)\n      \t_LerpValue(\"\u63d2\u503c\u6bd4\u4f8b\",Range(0,1))=0\n    }\n    \n    SubShader\n    {\n        Pass\n        {\n            Lighting On     \n            Material\n            {\n                Diffuse&#91;_MainCol]\n            }\n\n\t\t\t\/\/\u8bbe\u7f6e\u7eb9\u7406\n            \/\/SetTexture&#91;_MainTex]\n            \/\/{\n            \/\/    \/\/ \u878d\u5408\u7eb9\u7406\u548c\u5176\u4ed6\n            \/\/    \/\/ Combine:\u878d\u5408\u547d\u4ee4\n            \/\/    \/\/ Primary \u662f\u6765\u2f83\u5149\u7167\u8ba1\u7b97\u7684\u989c\u2f8a\u6216\u662f\u5f53\u5b83\u7ed1\u5b9a\u65f6\u7684\u9876\u70b9\u989c\u2f8a\n            \/\/    Combine texture * Primary\n            \/\/}\n            SetTexture&#91;_MainTex]\n            {\n            \t\/\/ \u7eb9\u7406\u7684\u989c\u8272\u4e0e\u4e0a\u9762\u7684\u56fa\u5b9a\u989c\u8272\u505a\u6df7\u5408\n                ConstantColor&#91;_MainCol]\n                \/\/ combine src1 * src2 \u66f4\u6697\n\t\t\t\t\/\/ combine src1 + src2 \u66f4\u4eae\n\t\t\t\t\/\/ combine src1 - src2\n                Combine texture * Constant Quad\n                \/\/ Texture\u662f\u5728SetTexture\u4e2d\u88ab\u5b9a\u4e49\u7684\u7eb9\u7406\u7684\u989c\u2f8a\n                \/\/ Constant\u662f\u88abConstantColor\u5b9a\u4e49\u7684\u989c\u2f8a\n                \/\/ \u53cc\u500d\/\u56db\u500d Double \/ Quad\n            } \n            SetTexture&#91;_SecondTex]\n            {\n                ConstantColor(0,0,0,&#91;_LerpValue])\n                \/\/ \u4f7f\u2f64\u6e902\u7684\u900f\u660e\u5ea6\u901a\u9053\u503c\u5728\u6e903\u548c\u6e901\u4e2d\u8fdb\u2f8f\u63d2\u503c\uff0c\u6ce8\u610f\u63d2\u503c\u662f\u53cd\u5411\u7684\uff1a\u5f53\u900f\u660e\u5ea6\u503c\u662f1\u662f\u4f7f\u2f64\u6e901\uff0c\u900f\u660e\u5ea6\u4e3a0\u65f6\u4f7f\u2f64\u6e903\n                Combine Previous lerp(Constant) texture\n                \/\/ Previous \u662f\u4e0a\u2f00\u6b21SetTexture\u7684\u7ed3\u679c\n            }\n        }\n    }\n    Fallback \"Diffuse\"\n}\n<\/code><\/pre>\n\n\n\n<h2>\u591a\u8fb9\u5f62\u5254\u9664<\/h2>\n\n\n\n<p>\u4e00\u822c\u90fd\u662f\u901a\u8fc7\u591a\u901a\u9053\u8fdb\u884c\u5254\u9664\uff0c\u5254\u9664\u540e\u7684\u6548\u679c\u662f\u6b63\u9762\u548c\u53cd\u9762\u7684\u989c\u8272\u4e0d\u540c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Pass{\n\u3000\u3000\/\/\u5254\u9664\u6b63\u9762\n\u3000\u3000Cull Front\n}\nPass{\n\u3000\u3000\/\/\u5254\u9664\u53cd\u9762\n\u3000\u3000Cull Back\n}\n\u3000\u3000\/\/\u4e0d\u5254\u9664\n\u3000\u3000\/\/Cull Off<\/code><\/pre>\n\n\n\n<h2>\u6df1\u5ea6<\/h2>\n\n\n\n<p>\u6df1\u5ea6\u5c31\u662f\u6839\u636e\u9876\u70b9\u548c\u50cf\u7d20\u8ddd\u79bb\u6444\u50cf\u673a\u7684\u8ddd\u79bb<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Shader \"Custom\/Three\"\n{\n\tProperties\n\t{\n\t\t_Mask(\"\u906e\u6321\u65f6\u7684\u989c\u8272\",Color)=(0,1,0,1)\n\t\t_Noocclusion(\"\u6ca1\u88ab\u906e\u6321\u65f6\u7684\u989c\u8272\",Color)=(1,0,1,1)\n\t}\n\tSubShader\n\t{\n\t    Pass\n\t\t{\n\t\t\t\/\/ZTest (Less | Greater | LEqual | GEqual |Equal | NotEqual | Always) \u5206\u522b\u8868\u793a \u5c0f\u4e8e | \u5927\u4e8e | \u5c0f\u4e8e\u7b49\u4e8e | \u5927\u4e8e\u7b49\u4e8e | \u7b49\u4e8e | \u4e0d\u7b49\u4e8e | \u603b\u662f\n\t\t\tZTest Greater\n\t\t\t\/\/\u5173\u95ed\u6df1\u5ea6\u7f13\u5b58\uff0c\u53ea\u6e32\u67d3\u6211\u81ea\u5df1\n\t\t\tZWrite Off\n\t\t\t\/\/\u8bbe\u7f6e\u989c\u8272\n\t\t\tColor&#91;_Mask]\n\t\t}\n\t\tPass \n\t\t{\n\t\t\tZTest LEqual\n\t\t\t\/\/\u8bbe\u7f6e\u989c\u8272\n\t\t\tColor&#91;_Noocclusion]\n\t\t}\t\t\n\t}\n\tFallback \"Diffuse\"\n}\n<\/code><\/pre>\n\n\n\n<h2>\u6df7\u5408<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Shader \"Custom\/Four\"\n{\n\tProperties\n\t{\n\t\t_Color(\"Color\",Color)=(1,0,0,1)\n\t}\n\tSubShader\n\t{\n\t    Pass\n\t\t{\n\u3000\u3000\t\t\/\/ \u5f00\u542f\u900f\u660e\u6df7\u5408\n\u3000\u3000\t\tBlend SrcAlpha OneMinusSrcAlpha\n\t\t\t\/\/ \u76f8\u52a0\n\t\t\tBlend One One\n\t\t\t\/\/ \u2f50\u8f83\u67d4\u548c\u7684\u76f8\u52a0\n\t\t\tBlend One OneMinusDstColor\n\t\t\t\/\/ \u4e58\u6cd5\n\t\t\tBlend DstColor Zero\n\t\t\t\/\/ 2\u500d\u4e58\u6cd5\n\t\t\tBlend DstColor SrcColor\n\u3000\u3000\t\t\/\/ \u5f00\u542f\u9876\u70b9\u5149\u7167\n\u3000\u3000\t\tLighting On\n\u3000\u3000\t\tMaterial\n\t\t\t{\n\u3000\u3000\u3000\t\t\tDiffuse&#91;_Color]\n\t\t\t}\n\u3000\t\t}\n\t}\n\tFallback \"Diffuse\"\n}\n<\/code><\/pre>\n\n\n\n<h2>\u6e32\u67d3\u961f\u5217\uff08Render Queue\uff09<\/h2>\n\n\n\n<p>\u65e2\u6e32\u67d3\u7684\u5148\u540e\u987a\u5e8f<\/p>\n\n\n\n<p>\u3000\u3000\u4e00\u822c\u7684\uff0c\u8ddd\u79bb\u6444\u50cf\u673a\u8d8a\u8fdc\u7684\u7269\u4f53\u8d8a\u5148\u6e32\u67d3\uff0c\u8d8a\u8fd1\u7684\u7269\u4f53\u6700\u540e\u6e32\u67d3\u3002\u4f46\u6709\u65f6\u5019\u9700\u8981\u4e00\u4e2a\u7269\u4f53\u5728\u4efb\u4f55\u60c5\u51b5\u4e0b\u90fd\u6700\u540e\u53bb\u6e32\u67d3\uff0c\u4e0d\u60f3\u4efb\u4f55\u7269\u4f53\u6321\u4f4f\uff0c\u8fd9\u65f6\u5019\u5c31\u9700\u8981\u5728Shader\u91cc\u9762\u624b\u52a8\u7684\u8bbe\u7f6e\u6e32\u67d3\u961f\u5217<\/p>\n\n\n\n<p>\u3000\u3000\u5728\u4f7f\u7528\u6e32\u67d3\u961f\u5217\u7684\u65f6\u5019\uff0c\u9700\u8981\u5173\u95ed\u6df1\u5ea6\u6d4b\u8bd5\uff08\u6df1\u5ea6\u6d4b\u8bd5\u548c\u6df1\u5ea6\u7f13\u5b58\uff08ZWrite On\/Off\uff09\u9ed8\u8ba4\u90fd\u662f\u5f00\u542f\u7684\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Background\uff081000\uff09   \u6700\u65e9\u88ab\u6e32\u67d3\u7684\u7269\u4f53\u7684\u961f\u5217\u3002\nGeometry   \uff082000\uff09   \u4e0d\u900f\u660e\u7269\u4f53\u7684\u6e32\u67d3\u961f\u5217\u3002\u5927\u591a\u6570\u7269\u4f53\u90fd\u5e94\u8be5\u4f7f\u7528\u8be5\u961f\u5217\u8fdb\u884c\u6e32\u67d3\uff0c\u4e5f\u662fUnity Shader\u4e2d\u9ed8\u8ba4\u7684\u6e32\u67d3\u961f\u5217\u3002 \nAlphaTest   \uff082450\uff09   \u6709\u900f\u660e\u901a\u9053\uff0c\u9700\u8981\u8fdb\u884cAlpha Test\u7684\u7269\u4f53\u7684\u961f\u5217\uff0c\u6bd4\u5728Geomerty\u4e2d\u66f4\u6709\u6548\u3002 \nTransparent\uff083000\uff09 \u534a\u900f\u7269\u4f53\u7684\u6e32\u67d3\u961f\u5217\u3002\u4e00\u822c\u662f\u4e0d\u5199\u6df1\u5ea6\u7684\u7269\u4f53\uff0cAlpha Blend\u7b49\u7684\u5728\u8be5\u961f\u5217\u6e32\u67d3\u3002 \nOverlay      \uff084000\uff09 \u6700\u540e\u88ab\u6e32\u67d3\u7684\u7269\u4f53\u7684\u961f\u5217\uff0c\u4e00\u822c\u662f\u8986\u76d6\u6548\u679c\uff0c\u6bd4\u5982\u955c\u5934\u5149\u6655\uff0c\u5c4f\u5e55\u8d34\u7247\u4e4b\u7c7b\u7684\u3002\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>SubShader{\n\u3000\u3000\/\/\u8bbe\u7f6e\u6e32\u67d3\u961f\u5217\n\u3000\u3000Tags{\"Queue\"=\"BackGround+500\"}\n\u3000\u3000\/\/\u5173\u95ed\u6df1\u5ea6\u6d4b\u8bd5\n\u3000\u3000ZText Off\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4ecb\u7ecd \u56fa\u5b9a\u6e32\u67d3\u7ba1\u7ebfshader(fixed function shader)\uff0c\u662f &hellip; <a href=\"http:\/\/www.u3d8.com\/?p=2431\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":2434,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[419],"tags":[],"_links":{"self":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/2431"}],"collection":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2431"}],"version-history":[{"count":5,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/2431\/revisions"}],"predecessor-version":[{"id":2539,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/2431\/revisions\/2539"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/media\/2434"}],"wp:attachment":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2431"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}