{"id":957,"date":"2017-11-06T00:44:31","date_gmt":"2017-11-05T15:44:31","guid":{"rendered":"http:\/\/naochang.me\/?p=957"},"modified":"2017-11-06T00:44:31","modified_gmt":"2017-11-05T15:44:31","slug":"shader%e3%81%a7%e3%83%a1%e3%82%ac%e3%83%8d","status":"publish","type":"post","link":"https:\/\/stacstar.jp\/blog\/?p=957","title":{"rendered":"Shader\u3067\u30e1\u30ac\u30cd"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/wp-content\/uploads\/shader_glasses.gif\" alt=\"\" width=\"600\" height=\"275\" class=\"aligncenter size-full wp-image-959\" \/><\/p>\n<p>PC\u30e1\u30ac\u30cd\u3092\u5272\u3068\u5f37\u3081\u306b\u5e8a\u306b\u304a\u3044\u305f\u3089\u58ca\u308c\u3066\u3057\u307e\u3044\u307e\u3057\u305f&#8230;<br \/>\n\u305d\u3093\u306a\u308f\u3051\u3067\u3001\u4eca\u56de\u306f\u30e1\u30ac\u30cd\u3067Shader\u306e\u7df4\u7fd2\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u30e2\u30c7\u30ea\u30f3\u30b0\u306f\u3061\u3087\u3063\u3068\u9069\u5f53\u3067\u3059\u304c\u3001\u30ec\u30f3\u30ba\u306f\u6e7e\u66f2\u3092\u6301\u305f\u305b\u3066\u3044\u3066\u3001\u305d\u306e\u6e7e\u66f2\u5177\u5408\u306b\u3088\u3063\u3066\u5f8c\u65b9\u306e\u5199\u308a\u8fbc\u307f\u3092\u64cd\u4f5c\u3002\u4eca\u56de\u306f\u7c21\u6613\u7684\u306b\u8996\u7dda\u30d9\u30af\u30c8\u30eb\u3068\u6cd5\u7dda\u30d9\u30af\u30c8\u30eb\u3092\u4f7f\u3063\u3066\u3001\u53cd\u5c04\u89d2\u3092\u6c42\u3081\u305f\u5024\u3092\u3061\u3087\u3063\u3068\u3044\u3058\u308c\u3070\u3067\u304d\u308b\u304b\u306a\u3068\u601d\u3063\u3066\u3084\u3063\u3066\u307f\u305f\u3002\u53cd\u5c04\u89d2\u81ea\u4f53\u306freflect()\u3067\u305d\u306e\u307e\u307e\u51fa\u305b\u308b\u3002GrabPass\u3067\u53d6\u5f97\u3057\u305f\u30d4\u30af\u30bb\u30eb\u30ab\u30e9\u30fc\u3092\u53d6\u5f97\u3059\u308b IN.screenPos.xy \/IN.screenPos.w \u306e\u5206\u6bcd\u306e\u5024\u306b\u3001reflect()\u304b\u3089\u53d6\u5f97\u3057\u305f\u30d9\u30af\u30c8\u30eb\u306ex\u3068y\u3092\u4f7f\u3063\u3066\u8abf\u6574\u3057\u3066\u307f\u305f\u3002\u4e00\u5fdc\u305d\u308c\u3063\u307d\u304f\u898b\u3048\u3066\u3044\u308b\u6c17\u304c\u3059\u308b\u3002\u30e1\u30ac\u30cd\u306e\u30d5\u30ec\u30fc\u30e0\u81ea\u4f53\u304c\u30b0\u30e9\u30b9\u306e\u6b6a\u307f\u306b\u8868\u793a\u3055\u308c\u3066\u3057\u307e\u3046\u306e\u3092\u9632\u3050\u305f\u3081\u30e1\u30ac\u30cd\u306e\u30d5\u30ec\u30fc\u30e0\u306f\u30ec\u30f3\u30c0\u30fc\u9806\u3092\u305a\u3089\u3059\u305f\u3081Transparent\u306b\u8a2d\u5b9a\u3002\u30e1\u30ac\u30cd\u306e\u67c4\u306e\u90e8\u5206\u306fOpaque\u3060\u3051\u3069\u3001\u3061\u3087\u3063\u3068\u8868\u793a\u304c\u304a\u304b\u3057\u3044\u306e\u306f&#8230;\u306a\u3093\u3067\u3060\u308d&#8230;(?)<br \/>\n\u30d5\u30c1\u306e\u660e\u308b\u3055\u306f\u4e0b\u8a18\u306e\u30b5\u30a4\u30c8\u3092\u53c2\u8003\u306b\u3001\u8996\u7dda\u30d9\u30af\u30c8\u30eb\u3068\u6cd5\u7dda\u30d9\u30af\u30c8\u30eb\u306e\u5185\u7a4d\u306e\u89d2\u5ea6\u304b\u3089\u8abf\u6574\u3057\u3066\u89d2\u5ea6\u304c\u30ad\u30c4\u30a4\u5834\u5408\u306b\u5c11\u3057\u660e\u308b\u304fEmission\u3092\u8abf\u6574\u3002<\/p>\n<p>\u53c2\u8003\uff09<a href=\"http:\/\/marupeke296.com\/UNI_S_No4_Glass.html\" rel=\"noopener\" target=\"_blank\">\u25cb\u00d7\u3064\u304f\u308d\u30fc\u3069\u3063\u3068\u30b3\u30e0 | \u305d\u306e\uff14 \u30b5\u30fc\u30d5\u30a7\u30a4\u30b9\u30b7\u30a7\u30fc\u30c0\u3067\u30ac\u30e9\u30b9\u3092\u4f5c\u308b<\/a><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nShader &quot;Glasses&quot; {\r\n\tProperties {\r\n\t\t_Color (&quot;Color&quot;, Color) = (1,1,1,1)\r\n\t\t_MainTex (&quot;Albedo (RGB)&quot;, 2D) = &quot;white&quot; {}\r\n\t\t_Glossiness (&quot;Smoothness&quot;, Range(0,1)) = 0.5\r\n\t\t_Metallic (&quot;Metallic&quot;, Range(0,1)) = 0.0\r\n\t}\r\n\tSubShader {\r\n\t\tTags {\r\n\t\t\t&quot;Queue&quot;=&quot;Transparent&quot;\r\n\t\t\t&quot;RenderType&quot;=&quot;Transparent&quot;\r\n\t\t}\r\n\t\tLOD 200\r\n\r\n\t\tGrabPass {}\r\n\r\n\t\tCGPROGRAM\r\n\t\t\/\/ Physically based Standard lighting model, and enable shadows on all light types\r\n\t\t#pragma surface surf Standard fullforwardshadows\r\n\r\n\t\t\/\/ Use shader model 3.0 target, to get nicer looking lighting\r\n\t\t#pragma target 3.0\r\n\r\n\t\tsampler2D _MainTex;\r\n\t\tsampler2D _GrabTexture;\r\n\r\n\t\tstruct Input {\r\n\t\t\tfloat2 uv_MainTex;\r\n\t\t\tfloat4 screenPos;\r\n\t\t\tfloat3 viewDir;\r\n\t\t\tfloat3 worldNormal;\r\n\t\t};\r\n\r\n\t\thalf _Glossiness;\r\n\t\thalf _Metallic;\r\n\t\tfixed4 _Color;\r\n\r\n\t\t\/\/ Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.\r\n\t\t\/\/ See https:\/\/docs.unity3d.com\/Manual\/GPUInstancing.html for more information about instancing.\r\n\t\t\/\/ #pragma instancing_options assumeuniformscaling\r\n\t\tUNITY_INSTANCING_CBUFFER_START(Props)\r\n\t\t\t\/\/ put more per-instance properties here\r\n\t\tUNITY_INSTANCING_CBUFFER_END\r\n\r\n\t\tvoid surf (Input IN, inout SurfaceOutputStandard o) {\r\n\t\t\tfloat adj = 0.2;\r\n\t\t\tfloat margin = 1.0 - dot(normalize(IN.viewDir), normalize(IN.worldNormal));\r\n\t\t\tfloat2 reflectDir = reflect(IN.worldNormal, IN.viewDir);\r\n\t\t\tfloat2 grabUV = float2(IN.screenPos.x + adj * reflectDir.x, IN.screenPos.y + adj * reflectDir.y) \/ IN.screenPos.w;\r\n\t\t\tfixed3 grabC = tex2D(_GrabTexture, grabUV).rgb;\r\n\r\n\t\t\to.Emission = 0.5 * margin;\r\n\t\t\to.Albedo = grabC * _Color;\r\n\t\t\to.Metallic = _Metallic;\r\n\t\t\to.Smoothness = _Glossiness;\r\n\t\t\to.Alpha = 1;\r\n\t\t}\r\n\t\tENDCG\r\n\t}\r\n\tFallBack &quot;Diffuse&quot;\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>PC\u30e1\u30ac\u30cd\u3092\u5272\u3068\u5f37\u3081\u306b\u5e8a\u306b\u304a\u3044\u305f\u3089\u58ca\u308c\u3066\u3057\u307e\u3044\u307e\u3057\u305f&#8230; \u305d\u3093\u306a\u308f\u3051\u3067\u3001\u4eca\u56de\u306f\u30e1\u30ac\u30cd\u3067Shader\u306e\u7df4\u7fd2\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,2],"tags":[],"class_list":["post-957","post","type-post","status-publish","format-standard","hentry","category-shader","category-unity"],"_links":{"self":[{"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/957","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=957"}],"version-history":[{"count":9,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/957\/revisions"}],"predecessor-version":[{"id":968,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/957\/revisions\/968"}],"wp:attachment":[{"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=957"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=957"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}