{"id":2275,"date":"2020-09-04T14:55:03","date_gmt":"2020-09-04T06:55:03","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=2275"},"modified":"2020-09-04T14:56:55","modified_gmt":"2020-09-04T06:56:55","slug":"%e5%9c%b0%e8%a1%a8%e9%81%ae%e7%bd%a9","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=2275","title":{"rendered":"[UnityShader]\u5730\u8868\u906e\u7f69\u5b9e\u73b0"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"746\" src=\"http:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2020\/09\/2-1024x746.png\" alt=\"\" class=\"wp-image-2276\" srcset=\"https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2020\/09\/2-1024x746.png 1024w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2020\/09\/2-300x219.png 300w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2020\/09\/2-768x560.png 768w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2020\/09\/2-70x50.png 70w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2020\/09\/2.png 1515w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>R0\uff1a\u62cd\u6444RT\u7684\u5de6\u4e0b\u89d2\uff08\u5c0f\u503c\uff09<br>R1\uff1a\u62cd\u6444RT\u7684\u53f3\u4e0a\u89d2\uff08\u5927\u503c)<br>C\uff1a\u5f53\u524d\u6444\u50cf\u673a\u6ce8\u89c6\u5730\u56fe\u7684\u4e2d\u5fc3\u70b9<br>P\uff1a\u6444\u50cf\u673a\u53e3\u5185\u4efb\u610f\u4e00\u70b9<br><br>\u6240\u4ee5\uff0cP\u7684UV\u7b49\u4e8e<br>(P-R0)\/(R1-R0)<br><br>\u4e00\u3001\u6784\u5efa\u6b63\u4ea4\u6444\u50cf\u673a<br>camera.transform.position.xz = (R1-R0)\/2;<br>camera.transform.position.y = 100;<br>camera.orthographic=true;<br>camera.aspect = (R1.x-R0.x)\/(R1.y-R0.y);<br>camera.farClipPlane = 200;<br>camera.transform.localRotation = Quaternion.Euler(90,0,0);<br>camera.clearFlags = CameraClearFlags.Color;<br>camera.backgroundColor = Color.clear;<br>camera.cullingMask = XXXX;<br>\u5728\u9700\u8981\u66f4\u65b0\u7684\u5730\u65b9\uff0c\u8fdb\u884ccamera.Render();<br><br>\u4e8c\u3001\u5411Shader\u4e2d\u4f20\u9012R0\u548cR1\u7684\u4fe1\u606f<br>Shader.SetGlobalVector(&#8220;Offset&#8221;, new Vector4(R0.x, R0.y, R1.x-R0.x, R1.y-R0.y);<\/p>\n\n\n\n<p>\u4e09\u3001\u5728Shader\u4e2d\u4f7f\u7528\u4e16\u754c\u5750\u6807\u91c7\u6837&nbsp;<br>half&nbsp;uv_x&nbsp;=&nbsp;(&nbsp;wpos.x&nbsp;&#8211;&nbsp; Offset.x&nbsp;)&nbsp;\/&nbsp; Offset .z;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>half&nbsp;uv_y&nbsp;=&nbsp;(&nbsp;wpos.z&nbsp;&#8211;&nbsp; Offset .y&nbsp;)&nbsp;\/&nbsp; Offset .w;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>fixed4&nbsp;maskColor&nbsp;=&nbsp;tex2D(MaskTes,&nbsp;half2(uv_x,&nbsp;uv_y)); <\/p>\n\n\n\n<p>\u4e09\u3001\u906e\u7f69\u56fe\uff0c\u4f7f\u75281+1\u7684\u6df7\u5408\u6a21\u5f0f<br>Blend\u00a0One\u00a0One\uff0c\u8fd9\u6837\u53ef\u4ee5\u8ba9\u591a\u5c42RGB\u901a\u9053\u6b63\u5e38\u53e0\u52a0\u6df7\u5408<\/p>\n\n\n\n<p>\u56db\u3001\u4f18\u5316<br>\u5f53\u6444\u50cf\u673a\u5728\u4e00\u5c4f\u5185\u79fb\u52a8\u65f6\uff0c\u53ef\u4ee5\u4e0d\u7528\u91cd\u590d\u62cd\u6444\u6b64RT<\/p>\n","protected":false},"excerpt":{"rendered":"<p>R0\uff1a\u62cd\u6444RT\u7684\u5de6\u4e0b\u89d2\uff08\u5c0f\u503c\uff09R1\uff1a\u62cd\u6444RT\u7684\u53f3\u4e0a\u89d2\uff08\u5927\u503c)C\uff1a\u5f53\u524d\u6444\u50cf\u673a\u6ce8\u89c6\u5730\u56fe\u7684\u4e2d\u5fc3\u70b9P\uff1a\u6444\u50cf\u673a\u53e3\u5185\u4efb\u610f\u4e00 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[18],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/2275"}],"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=2275"}],"version-history":[{"count":4,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/2275\/revisions"}],"predecessor-version":[{"id":2280,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/2275\/revisions\/2280"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}