{"id":250,"date":"2026-05-31T14:37:54","date_gmt":"2026-05-31T06:37:54","guid":{"rendered":"http:\/\/47.109.106.217:21080\/?p=250"},"modified":"2026-05-31T14:37:54","modified_gmt":"2026-05-31T06:37:54","slug":"ai%e5%ba%94%e7%94%a8%e6%8a%a5%e5%91%8a","status":"publish","type":"post","link":"https:\/\/alffarmtale.cn\/?p=250","title":{"rendered":"SDF\u548cWeb\u7aef\u5b58\u6863\u673a\u5236"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Polygon2D<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>shader_type canvas_item;\nrender_mode unshaded;\n\nuniform vec4 color : source_color; \nuniform float angle : hint_range(0,360); \nuniform float max_dist : hint_range(0,1000) = 100; \nuniform sampler2D gradientTexture;\n\nvec4 get_gradient_color(float position) { \n    return texture(gradientTexture, vec2(position, 0.5)); \n}\n\nvoid fragment() { \n    float ang_rad = angle * 3.1416 \/ 180.0;\n    vec2 dir = vec2(sin(ang_rad),cos(ang_rad)); \n    vec2 at = screen_uv_to_sdf(SCREEN_UV); \n    float accum = 0.0;\n    while(accum &lt; max_dist) {\n        float d = texture_sdf(at);\n        accum+=d;\n        if (d &lt; 0.01) {\n            break;\n        }\n        at += d * dir;\n    }\n    float alpha = 1.0-min(1.0,accum\/max_dist);\n    \n    \/\/ the gradient controls the falloff of the shadow\n    alpha = get_gradient_color(alpha).r;\n    \n    COLOR = vec4(color.rgb,alpha * color.a);\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u5e73\u53f0<\/th><th>\u6e32\u67d3\u6a21\u5f0f<\/th><th>SDF\u652f\u6301<\/th><th>\u539f\u56e0<\/th><\/tr><\/thead><tbody><tr><td>\u684c\u9762<\/td><td>Forward Plus\/Vulkan<\/td><td>\u2705<\/td><td>\u5b8c\u5168\u652f\u6301<\/td><\/tr><tr><td><strong>Web<\/strong><\/td><td><strong>WebGL 2<\/strong><\/td><td><strong>\u2705<\/strong><\/td><td>SDF\u4f5c\u4e3a\u666e\u901a\u7eb9\u7406\u4e0a\u4f20<\/td><\/tr><tr><td>Web<\/td><td>WebGL 1 (gl_compatibility)<\/td><td>\u26a0\ufe0f<\/td><td>\u53ef\u80fd\u53d7\u9650\uff0c\u4f46Godot 4.x\u9ed8\u8ba4\u7528WebGL 2<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502                    \u5e27\u6e32\u67d3\u6d41\u7a0b                               \u2502\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n\u2502  1. CPU\u6536\u96c6\u6240\u6709OccluderPolygon2D                            \u2502\n\u2502                         \u2193                                  \u2502\n\u2502  2. CPU\u8f6f\u4ef6\u8ba1\u7b97\u751f\u6210SDF\u7eb9\u7406\uff08\u8ddd\u79bb\u573a\uff09                        \u2502\n\u2502                         \u2193                                  \u2502\n\u2502  3. \u5c06SDF\u7eb9\u7406\u4e0a\u4f20\u5230GPU\u4f5c\u4e3a\u666e\u901a\u7eb9\u7406                          \u2502\n\u2502                         \u2193                                  \u2502\n\u2502  4. \u7740\u8272\u5668\u6267\u884c\u5149\u7ebf\u6b65\u8fdb\u7b97\u6cd5\uff1a                                \u2502\n\u2502     - screen_uv_to_sdf() \u8f6c\u6362\u5750\u6807                           \u2502\n\u2502     - texture_sdf() \u91c7\u6837\u8ddd\u79bb\u503c                              \u2502\n\u2502     - \u6cbf\u5149\u7ebf\u65b9\u5411\u7d2f\u52a0\u8ddd\u79bb\u76f4\u5230\u78b0\u5230\u906e\u6321\u7269                      \u2502\n\u2502                         \u2193                                  \u2502\n\u2502  5. \u6839\u636e\u7d2f\u8ba1\u8ddd\u79bb\u8ba1\u7b97\u9634\u5f71\u900f\u660e\u5ea6                              \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u9879\u76ee\u80fd\u5728Web\u4e0a\u8fd0\u884c\u7684\u6838\u5fc3\u539f\u56e0\u662f\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Godot 4.x\u9ed8\u8ba4\u4f7f\u7528WebGL 2<\/strong>\uff0c\u800c\u975eWebGL 1\u7684<code>gl_compatibility<\/code>\u6a21\u5f0f<\/li>\n\n\n\n<li><strong>SDF\u6570\u636e\u662fCPU\u9884\u5148\u8ba1\u7b97<\/strong>\u540e\u4f5c\u4e3a\u666e\u901a\u7eb9\u7406\u4e0a\u4f20\u7684\uff0c\u4e0d\u4f9d\u8d56GPU\u7684\u7279\u6b8aSDF\u652f\u6301<\/li>\n\n\n\n<li><strong>\u7740\u8272\u5668\u53ea\u9700\u8981\u666e\u901a\u7684\u7eb9\u7406\u91c7\u6837\u80fd\u529b<\/strong>\uff0c\u8fd9\u5728\u6240\u6709WebGL\u73af\u5883\u4e2d\u90fd\u652f\u6301<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ea\u8981\u786e\u4fdd\u9879\u76ee\u8bbe\u7f6e\u4e3a<strong>WebGL 2\u6e32\u67d3\u6a21\u5f0f<\/strong>\uff08Godot 4.x\u9ed8\u8ba4\uff09\uff0c\u5c31\u80fd\u6b63\u5e38\u8fd0\u884c\u8fd9\u4e2a\u9634\u5f71\u6548\u679c\u3002<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Web \u5e73\u53f0\u6587\u4ef6\u7cfb\u7edf\u9650\u5236 +<\/strong> <strong>\u8d44\u6e90\u8def\u5f84\u8bfb\u5199\u89c4\u5219<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>res:\/\/ \u8def\u5f84\u5728 Web \u7aef\u662f\u53ea\u8bfb\u7684<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Web \u5bfc\u51fa\u540e\uff0cres:\/\/ \u662f\u6253\u5305\u540e\u7684<strong>\u538b\u7f29\u8d44\u6e90\u5305<\/strong>\uff0c<strong>\u4e0d\u80fd\u521b\u5efa\u6587\u4ef6\u5939\u3001\u4e0d\u80fd\u5199\u5165\u6587\u4ef6<\/strong>\uff0c\u8fd9\u662f\u6700\u6839\u672c\u7684\u539f\u56e0\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>DirAccess \u64cd\u4f5cres:\/\/\u5728 Web \u7aef\u65e0\u6743\u9650<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6d4f\u89c8\u5668\u73af\u5883\u4e0d\u5141\u8bb8 JS \u4fee\u6539\u539f\u59cb\u8d44\u6e90\u5305\uff0c\u4f60\u7684make_dir\u3001\u6587\u4ef6\u4fdd\u5b58\u90fd\u4f1a\u9759\u9ed8\u5931\u8d25\u3002 <strong>Web \u7aef\u552f\u4e00\u53ef\u5199\u5165\u8def\u5f84\uff1auser:\/\/<\/strong> Godot \u6240\u6709\u5e73\u53f0\uff08Web\/PC\/ \u79fb\u52a8\u7aef<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u552f\u4e00\u901a\u7528\u7684\u53ef\u8bfb\u5199\u8def\u5f84<\/strong>\u662f user:\/\/\uff0cWeb \u7aef\u4f1a\u6620\u5c04\u5230\u6d4f\u89c8\u5668\u7684\u672c\u5730\u5b58\u50a8\uff08IndexedDB\uff09\u3002<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u60f3\u77e5\u9053\u4f60\u6539\u7684\u8fd9\u4e2a\u5b58\u6863\u903b\u8f91\u662f\u65b0\u5efa\u5b58\u6863\u653e\u5728user\u91cc\u9762\uff0c\u7136\u540e\u52a0\u8f7d\u7684\u65f6\u5019\u4eceuser\u62ff\u5b58\u6863\u52a0\u8f7d\u5230res\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u65b0\u5b58\u6863\uff1a<br>res:\/\/resources\/bag.tres (\u6e90\u8d44\u6e90\uff0c\u6a21\u677f)<br>\u2193 \u6df1\u62f7\u8d1d\/\u53d6\u7a7a\u5b9e\u4f8b<br>{archives_dir}\/{slot}\/bag.tres \u2190 \u6211\u6539\u4e86\uff1aweb \u8d70 user:\/\/web_archives\/<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u52a0\u8f7d\u5b58\u6863\uff1a<br>res:\/\/resources\/bag.tres (\u6e90)<br>{archives_dir}\/{slot}\/bag.tres (\u5b58\u6863)<br>\u2193 \u628a\u5b58\u6863\u7684\u503c\u8986\u76d6\u5230\u6e90\u8d44\u6e90 (in-memory)<br>res:\/\/resources\/bag.tres (\u6e90\uff0c\u5df2\u8986\u76d6)<br>\u2193 ResourceSaver.save \u5199\u56de\u78c1\u76d8<br>res:\/\/resources\/bag.tres \u2190 !! \u8fd9\u91cc\u53c8\u5199\u56de res:\/\/ \u4e86\uff0c\u6211\u6ca1\u6539<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Polygon2D \u5e73\u53f0 \u6e32\u67d3\u6a21\u5f0f SDF\u652f\u6301 \u539f\u56e0 \u684c\u9762 Forward Plus\/Vulkan \u2705 \u5b8c\u5168\u652f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-250","post","type-post","status-publish","format-standard","hentry","category-developmentlog"],"_links":{"self":[{"href":"https:\/\/alffarmtale.cn\/index.php?rest_route=\/wp\/v2\/posts\/250","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alffarmtale.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alffarmtale.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alffarmtale.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alffarmtale.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=250"}],"version-history":[{"count":0,"href":"https:\/\/alffarmtale.cn\/index.php?rest_route=\/wp\/v2\/posts\/250\/revisions"}],"wp:attachment":[{"href":"https:\/\/alffarmtale.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alffarmtale.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alffarmtale.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}