{"id":924,"date":"2017-10-30T22:35:39","date_gmt":"2017-10-30T13:35:39","guid":{"rendered":"http:\/\/naochang.me\/?p=924"},"modified":"2017-10-30T22:35:39","modified_gmt":"2017-10-30T13:35:39","slug":"shader%e3%81%a7%e3%82%b3%e3%83%b3%e3%83%88%e3%83%a9%e3%82%b9%e3%83%88","status":"publish","type":"post","link":"https:\/\/stacstar.jp\/blog\/?p=924","title":{"rendered":"Shader\u3067\u30b3\u30f3\u30c8\u30e9\u30b9\u30c8"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/wp-content\/uploads\/shader_contrast_rgb.gif\" alt=\"\" width=\"640\" height=\"250\" class=\"aligncenter border size-full wp-image-926\" \/><\/p>\n<p>\u307e\u305a\u306fStandard\u306eShader\u3092\u30b3\u30d4\u30fc\u3057\u3066\u3001surface\u30b7\u30a7\u30fc\u30c0\u30fc\u5185\u306b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3067\u8a2d\u5b9a\u3092\u5897\u3084\u3057\u305f_Contrast\u3092\u639b\u3051\u308b\u3060\u3051\u30d0\u30fc\u30b8\u30e7\u30f3\u3002<\/p>\n<pre class=\"brush: unitycsharp; title: ; notranslate\" title=\"\">\r\nfixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;\r\nc.rgb *= _Contrast; \/\/ \u8db3\u3057\u305f\r\n<\/pre>\n<p>\u6b21\u306fRGB\u304b\u3089YCbCr\u8272\u7a7a\u9593\u306b\u5909\u63db\u3057\u3066\u8f1d\u5ea6\u3092\u8abf\u6574\u3002<\/p>\n<p><!--more--><\/p>\n<p>\u4eba\u9593\u306e\u76ee\u306e\u6027\u8cea\u4e0a\u8f1d\u5ea6\u306fG &gt; R &gt; B\u306e\u9806\u3067\u660e\u308b\u304f\u611f\u3058\u308b\u306e\u3067\u3001\u305d\u306e\u4fc2\u6570\u3092\u639b\u3051\u308b\u3002YCbCr\u306e\u5834\u5408\u3001Y\u304c\u8f1d\u5ea6\u3001Cb\u3068Cr\u304c\u8272\u5dee\u6210\u5206\u3002<br \/>\n\u3061\u306a\u307f\u306bR+B+G\/3\u3092\u660e\u308b\u3055\u3068\u898b\u306a\u3057\u305f\u5834\u5408\u3068\u3001\u4fc2\u6570\u3092\u304b\u3051\u3066\u8a08\u7b97\u3057\u305f\u5834\u5408\u306e\u9055\u3044\u306f<a href=\"https:\/\/codezine.jp\/article\/detail\/3750\" rel=\"noopener\" target=\"_blank\">\u3053\u306e\u30da\u30fc\u30b8\u306b\u3042\u308b\u56f33<\/a>\u304c\u308f\u304b\u308a\u3084\u3059\u3044\u3002<\/p>\n<p>\u3042\u3068\u306fRGB to YCbCr\u3068\u3001YCbCr to RGB\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u4f5c\u3063\u3066\u3001\u305d\u306e\u8f1d\u5ea6\u306e\u30d2\u30b9\u30c8\u30b0\u30e9\u30e0\u306e\u6700\u5c0f\u5024\u3068\u6700\u5927\u5024\u3092\u3044\u3058\u3063\u3066\u3042\u3052\u308c\u3070OK<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/wp-content\/uploads\/ezgif.com-optimize.gif\" alt=\"\" width=\"640\" height=\"250\" class=\"aligncenter border size-full wp-image-928\" \/><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nShader &quot;Contrast&quot; {\r\n\tProperties {\r\n\t\t_Color (&quot;Color&quot;, Color) = (1,1,1,1)\r\n\t\t_HistMin (&quot;Histgram Min&quot;, Range(0.0, 1.0)) = 0.0\r\n\t\t_HistMax (&quot;Histgram Max&quot;, Range(0.0, 1.0)) = 1.0\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 { &quot;RenderType&quot;=&quot;Opaque&quot; }\r\n\t\tLOD 200\r\n\t\t\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\r\n\t\tstruct Input {\r\n\t\t\tfloat2 uv_MainTex;\r\n\t\t};\r\n\r\n\t\thalf _Glossiness;\r\n\t\thalf _Metallic;\r\n\t\tfixed4 _Color;\r\n\t\tfloat _Contrast;\r\n\t\tfloat _HistMax;\r\n\t\tfloat _HistMin;\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\tfixed3 RGB2YCbCr(fixed3 c) {\r\n\t\t\treturn fixed3(\r\n\t\t\t\t0.256788 * c.r + 0.504129 * c.g + 0.097906 * c.b + 0.0625,\r\n\t\t\t\t-0.148223 * c.r - 0.290993 * c.g + 0.439216 * c.b + 0.5,\r\n\t\t\t\t0.439216 * c.r - 0.367788 * c.g - 0.071427 * c.b + 0.5\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\tfixed3 YCbCr2RGB(fixed3 yCbCr) {\r\n\t\t\tfloat c = yCbCr.r - 0.0625;\r\n\t\t\tfloat d = yCbCr.g - 0.5;\r\n\t\t\tfloat e = yCbCr.b - 0.5;\r\n\r\n\t\t\treturn fixed3(\r\n\t\t\t\t1.164383 * c + 1.596027 * e,\r\n\t\t\t\t1.164383 * c - (0.391762 * d) - (0.812968 * e),\r\n\t\t\t\t1.164383 * c +  2.017232 * d\r\n\t\t\t);\r\n\t\t}\r\n\r\n\t\tvoid surf (Input IN, inout SurfaceOutputStandard o) {\r\n\t\t\tfloat histRatio = 1.0 \/ (_HistMax - _HistMin);\r\n\r\n\t\t\t\/\/ Albedo comes from a texture tinted by color\r\n\t\t\tfixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;\r\n\r\n\t\t\tfixed3 YCbCr = RGB2YCbCr(c);\r\n\t\t\tfloat luminance = YCbCr.r;\r\n\r\n\t\t\tluminance = max(_HistMin, luminance);\r\n\t\t\tluminance = min(_HistMax, luminance);\r\n\t\t\tluminance = (luminance - _HistMin) * histRatio;\r\n\r\n\t\t\tYCbCr.r = luminance;\r\n\r\n\t\t\tc.rgb = YCbCr2RGB(YCbCr);\r\n\r\n\t\t\to.Albedo = c.rgb;\r\n\t\t\t\/\/ Metallic and smoothness come from slider variables\r\n\t\t\to.Metallic = _Metallic;\r\n\t\t\to.Smoothness = _Glossiness;\r\n\t\t\to.Alpha = c.a;\r\n\t\t}\r\n\t\tENDCG\r\n\t}\r\n\tFallBack &quot;Diffuse&quot;\r\n}\r\n<\/pre>\n<p>\u53c2\u8003\uff09<br \/>\n<a href=\"http:\/\/klabgames.tech.blog.jp.klab.com\/archives\/1054828175.html\" rel=\"noopener\" target=\"_blank\">KLabGames Tech Blog | YUV\u3092\u3061\u3083\u3093\u3068\u7406\u89e3\u3057\u3066\u304b\u3089RGB\u306b\u30b3\u30f3\u30d0\u30fc\u30c8\u3057\u307e\u3057\u3087\u3046\u306d<\/a><br \/>\n<a href=\"http:\/\/vision.kuee.kyoto-u.ac.jp\/~hiroaki\/firewire\/yuv.html\" rel=\"noopener\" target=\"_blank\">\u5ddd\u5d8b \u5b8f\u5f70 \u51c6\u6559\u6388 | YUV\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u53ca\u3073 YUV<->RGB\u5909\u63db<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u307e\u305a\u306fStandard\u306eShader\u3092\u30b3\u30d4\u30fc\u3057\u3066\u3001surface\u30b7\u30a7\u30fc\u30c0\u30fc\u5185\u306b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3067\u8a2d\u5b9a\u3092\u5897\u3084\u3057\u305f_Contrast\u3092\u639b\u3051\u308b\u3060\u3051\u30d0\u30fc\u30b8\u30e7\u30f3\u3002 fixed4 c = tex2D (_MainTex, IN.uv_M [&hellip;]<\/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-924","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\/924","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=924"}],"version-history":[{"count":7,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/924\/revisions"}],"predecessor-version":[{"id":934,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=\/wp\/v2\/posts\/924\/revisions\/934"}],"wp:attachment":[{"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=924"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=924"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stacstar.jp\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=924"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}