{"id":280,"date":"2017-12-24T15:12:54","date_gmt":"2017-12-24T07:12:54","guid":{"rendered":"http:\/\/kogasa.moe\/?p=280"},"modified":"2019-05-14T00:38:14","modified_gmt":"2019-05-13T16:38:14","slug":"%e6%b0%b4%e9%9d%a2%e6%95%88%e6%9e%9c%e7%9a%842d%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/flandre-scarlet.moe\/blog\/280\/","title":{"rendered":"\u6c34\u9762\u6548\u679c\u76842D\u5b9e\u73b0"},"content":{"rendered":"<p>\u6e38\u620f\u91cc\u9700\u8981\u4e00\u4e2a\u80cc\u666f\uff0c\u76f4\u63a5\u8d34 2d \u56fe\u7247\u7684\u8bdd\u663e\u5f97\u6709\u4e9b\u5355\u8c03\u4e86\uff0c\u6253\u7b97\u505a\u4e2a\u52a8\u6001\u7684\u80cc\u666f\u3002\u7528\u6c34\u9762\u7684\u8bdd\u89c6\u91ce\u6bd4\u8f83\u5e7f\u9614\uff0c\u611f\u89c9\u6bd4\u8f83\u5408\u9002\u3002<\/br>\u56e0\u4e3a\u6e38\u620f\u662f\u76f4\u63a5\u7528 dx \u5199\u7684\uff0c\u6240\u4ee5\u6c34\u9762\u7684\u5b9e\u73b0\u4e5f\u81ea\u7136\u662f\u5199 shader \u6765\u5b8c\u6210\u4e86\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u57fa\u672c\u7684\u539f\u7406\u5c31\u662f\u901a\u8fc7 PSshader \u6765\u505a uv \u52a8\u753b\uff0c\u6539\u53d8\u50cf\u7d20\u548c\u8d34\u56fe\u95f4\u7684\u6620\u5c04\uff0c\u4ece\u800c\u6a21\u62df\u51fa\u6c34\u9762\u6ce2\u52a8\u7684\u6548\u679c\u3002\u56e0\u4e3a\u4e5f\u6ca1\u505a\u5149\u7167\u4e4b\u7c7b\u7684\u5904\u7406\uff0c\u6548\u679c\u5c31\u5dee\u4e86\u4e9b\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/flandre-scarlet.moe\/blog\/wp-content\/uploads\/2017\/12\/uvwater.gif\" alt=\"\u6c34\u9762\" \/><\/p>\n<p> \u76f4\u63a5\u9644\u4e0a shader \u4ee3\u7801\uff0c\u6838\u5fc3\u5c31\u662f\u4e24\u6761\u4e09\u89d2\u51fd\u6570\u53d8\u6362\u7684\u8bed\u53e5\u4e86\u3002<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">cbuffer ConstantBuffer : register(b0)\r\n{\r\n    matrix World;\r\n    matrix View;\r\n    matrix Projection;\r\n    float4 vMeshColor;\r\n    float2 param;\r\n}\r\n\r\nTexture2D txDiffuse    : register(t0);\r\nTexture2D txAnother    : register(t1);\r\nTexture2D txMask       : register(t2);\r\nSamplerState samLinear : register(s0);\r\n\r\n\r\nstruct VS_INPUT\r\n{\r\n    float4 Pos : POSITION;\r\n    float2 Tex : TEXCOORD0;\r\n};\r\n\r\nstruct PS_INPUT\r\n{\r\n    float4 Pos : SV_POSITION;\r\n    float2 Tex : TEXCOORD0;\r\n};\r\n\r\nPS_INPUT VS(VS_INPUT input)\r\n{\r\n    PS_INPUT output = (PS_INPUT)0;\r\n    output.Pos = mul(input.Pos, World);\r\n    output.Pos = mul(output.Pos, View);\r\n    output.Pos = mul(output.Pos, Projection);    \r\n    output.Tex = input.Tex;\r\n    return output;\r\n}\r\n\r\nfloat4 PS(PS_INPUT input) : SV_Target\r\n{\r\n    float4 another = txAnother.Sample(samLinear, input.Tex);\r\n    float4 alpha = txMask.Sample(samLinear, input.Tex);\r\n    \r\n    \/\/ \u66f4\u65b0\u50cf\u7d20\u70b9\u7684 uv \u504f\u79fb\uff0c\u76f8\u5f53\u4e8e\u70b9\u5728\u505a\u5706\u5468\u8fd0\u52a8\r\n    \/\/ param.x \u662f\u4ee5\u79d2\u4e3a\u5355\u4f4d\u7684\u65f6\u95f4\r\n    float2 bg = input.Tex;\r\n    bg.x += sin(param.x + bg.x * 15) * 0.01;\r\n    bg.y += cos(param.x + 0.003 + bg.y * 15) * 0.01;\r\n\r\n    float4 color = txDiffuse.Sample(samLinear, bg) * vMeshColor;\r\n    float4 finanl = color * (1.0f - alpha) + alpha * another;\r\n    float4 blend = saturate(finanl);\r\n    return color;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6e38\u620f\u91cc\u9700\u8981\u4e00\u4e2a\u80cc\u666f\uff0c\u76f4\u63a5\u8d34 2d \u56fe\u7247\u7684\u8bdd\u663e\u5f97\u6709\u4e9b\u5355\u8c03\u4e86\uff0c\u6253\u7b97\u505a\u4e2a\u52a8\u6001\u7684\u80cc\u666f\u3002\u7528\u6c34\u9762\u7684\u8bdd\u89c6\u91ce\u6bd4\u8f83\u5e7f\u9614\uff0c\u611f\u89c9\u6bd4\u8f83&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/flandre-scarlet.moe\/blog\/280\/\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[7,114,10,14,112,113],"class_list":["post-280","post","type-post","status-publish","format-standard","hentry","category-directx","tag-c","tag-d3d","tag-directx","tag-hlsl","tag-uv","tag-113"],"_links":{"self":[{"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/posts\/280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/comments?post=280"}],"version-history":[{"count":0,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/posts\/280\/revisions"}],"wp:attachment":[{"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/media?parent=280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/categories?post=280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/flandre-scarlet.moe\/blog\/wp-json\/wp\/v2\/tags?post=280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}