{"id":213253,"date":"2014-02-20T12:58:03","date_gmt":"2014-02-20T08:58:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=213253"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=213253","title":{"rendered":"<span class=\"post_title\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0438\u0433\u0440\u044b \u043d\u0430 \u0432\u0430\u0448\u0438\u0445 \u0433\u043b\u0430\u0437\u0430\u0445 \u2014 \u0447\u0430\u0441\u0442\u044c 4: \u0428\u0435\u0439\u0434\u0435\u0440 \u0434\u043b\u044f fade in \u043f\u043e \u043f\u0430\u043b\u0438\u0442\u0440\u0435 (\u0430-\u043b\u044f NES)<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0448\u0435\u0439\u0434\u0435\u0440\u0430, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0435\u0433\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c fade in\/out \u043f\u043e \u043f\u0430\u043b\u0438\u0442\u0440\u0435, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u043b\u043e\u0441\u044c \u0432 \u0441\u0442\u0430\u0440\u044b\u0445 NES-\u0438\u0433\u0440\u0430\u0445 \u0438 \u0442.\u043f.<\/p>\n<p>  \u0421\u0443\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0439 \u043f\u0430\u043b\u0438\u0442\u0440\u044b \u0446\u0432\u0435\u0442\u043e\u0432 \u043d\u0435\u043b\u044c\u0437\u044f \u0431\u044b\u043b\u043e \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u0437\u0430\u0442\u0435\u043c\u043d\u0438\u0442\u044c (\u0438\u043b\u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0438\u0437 \u0442\u0435\u043c\u043d\u043e\u0442\u044b) \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443, \u0442.\u043a. \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u043e \u043d\u0443\u0436\u043d\u044b\u0445 \u0446\u0432\u0435\u0442\u043e\u0432 \u0432 \u043f\u0430\u043b\u0438\u0442\u0440\u0435. \u0418 \u044d\u0442\u043e \u0440\u0435\u0448\u0430\u043b\u043e\u0441\u044c \u043f\u0443\u0442\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0446\u0432\u0435\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0431\u043e\u043b\u0435\u0435 \u0442\u0435\u043c\u043d\u044b\u0435. \u0422\u043e \u0435\u0441\u0442\u044c \u043d\u0443\u0436\u043d\u043e \u0432\u0430\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c fade in \u0436\u0435\u043b\u0442\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0430 \u0432 \u043f\u0430\u043b\u0438\u0442\u0440\u0435 \u043d\u0435\u0442 \u0442\u0435\u043c\u043d\u043e-\u0436\u0435\u043b\u0442\u044b\u0445 \u043e\u0442\u0442\u0435\u043d\u043a\u043e\u0432 \u2014 \u0432\u043e\u0442 \u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0438\u043d\u0438\u043c (\u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0435\u043c\u043d\u044b\u043c), \u043f\u043e\u0442\u043e\u043c \u2014 \u043a\u0440\u0430\u0441\u043d\u044b\u043c \u0438 \u0442.\u043f.<\/p>\n<p>  \u041d\u0438\u0436\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0448\u0435\u0439\u0434\u0435\u0440\u0430:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/b44\/ec1\/d1f\/b44ec1d1f78b349acd274cfa285cfced.gif\"\/><\/p>\n<p>  \u0421\u0440\u0430\u0437\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0433\u043e\u0432\u043e\u0440\u044e\u0441\u044c \u2014 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0438\u043b\u0438 \u043d\u0435\u0442 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u0448\u0435\u0439\u0434\u0435\u0440 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0438\u0433\u0440\u0435, \u043c\u044b \u0435\u0449\u0435 \u043d\u0435 \u0440\u0435\u0448\u0438\u043b\u0438. \u0422\u0430\u043a \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u043d \u043d\u0430 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c \u043f\u0438\u043a\u0441\u0435\u043b\u044c-\u0430\u0440\u0442\u0435 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0446\u0432\u0435\u0442\u043e\u0432, \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u043f\u043e\u0440\u043d\u043e. <br \/>  <a name=\"habracut\"><\/a><br \/>  \u0418\u0442\u0430\u043a, \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0431\u043e\u043b\u0432\u0430\u043d\u043a\u0443 \u0448\u0435\u0439\u0434\u0435\u0440\u0430:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">shader<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">Shader &quot;Custom\/Palette Shader&quot;  { \tProperties { \t\t_MainTex (&quot;Base (RGB)&quot;, 2D) = &quot;white&quot; {} \t}  \tSubShader { \t\tPass { \t\t\tZTest Always Cull Off ZWrite Off Fog { Mode off }  \t\t\tCGPROGRAM  \t\t\t#pragma vertex vert \t\t\t#pragma fragment frag \t\t\t#pragma fragmentoption ARB_precision_hint_fastest \t\t\t#include &quot;UnityCG.cginc&quot; \t\t\t#pragma target 3.0  \t\t\tstruct v2f  \t\t\t{ \t\t\t\tfloat4 pos      : POSITION; \t\t\t\tfloat2 uv       : TEXCOORD0; \t\t\t};  \t\t\tuniform sampler2D _MainTex;  \t\t\tv2f vert(appdata_img v) \t\t\t{ \t\t\t\tv2f o; \t\t\t\to.pos = mul(UNITY_MATRIX_MVP, v.vertex); \t\t\t\to.uv = MultiplyUV(UNITY_MATRIX_TEXTURE0, v.texcoord); \t\t\t\treturn o; \t\t\t}  \t\t\thalf4 frag(v2f i): COLOR \t\t\t{ \t\t\t\thalf4 color = tex2D(_MainTex, i.uv);  \t\t\t\t\/\/ \u0437\u0434\u0435\u0441\u044c \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u0434, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0449\u0438\u0439 \u0446\u0432\u0435\u0442  \t\t\t\thalf4 rc = color; \t\t\t\treturn rc; \t\t\t}  \t\t\tENDCG \t\t} \t} \tFallBack &quot;Diffuse&quot; } <\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"spoiler\"><b class=\"spoiler_title\">c#<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">using UnityEngine;  [ExecuteInEditMode] [RequireComponent(typeof(Camera))]  public class PaletteShader : MonoBehaviour  { \tpublic Shader shader; \tprivate Material _material; \t\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ \tprotected Material material \t{ \t\tget \t\t{ \t\t\tif (_material == null) \t\t\t{ \t\t\t\t_material = new Material(shader); \t\t\t\t_material.hideFlags = HideFlags.HideAndDontSave; \t\t\t}  \t\t\treturn _material; \t\t} \t} \t\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ \tprivate void OnRenderImage(RenderTexture source, RenderTexture destination) \t{ \t\tif (shader == null) return; \t\tMaterial mat = material; \t\tGraphics.Blit(source, destination, mat); \t} \t\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ \tvoid OnDisable() \t{ \t\tif (_material)\tDestroyImmediate(_material); \t} \t\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ }<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0434\u0443\u043c\u0430\u0435\u043c\u2026<\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u2014 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0442\u0435\u043e\u0440\u0438\u0438. \u041a\u0430\u043a \u044f \u0443\u0436\u0435 \u0441\u043a\u0430\u0437\u0430\u043b \u0432\u044b\u0448\u0435, \u0446\u0432\u0435\u0442\u0430 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443. \u0421\u0438\u043d\u0438\u0439 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u044b\u043c \u0442\u0435\u043c\u043d\u044b\u043c \u0438 \u0442.\u0434. \u0412\u043e\u043e\u0431\u0449\u0435, \u0435\u0441\u043b\u0438 \u0432\u044b \u0432\u043e\u0437\u044c\u043c\u0435\u0442\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0442\u0435\u043b\u0435\u0432\u0438\u0437\u043e\u0440\u0430 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0435\u0435 \u043d\u0430 \u0447\/\u0431 \u0442\u0435\u043b\u0435\u0432\u0438\u0437\u043e\u0440\u0435 \u2014 \u0442\u043e \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u0430 \u043e\u0442 c\u0432\u0435\u0442\u043b\u043e\u0433\u043e \u043a \u0442\u0435\u043c\u043d\u043e\u043c\u0443:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/47b\/51e\/9aa\/47b51e9aae7515e42063367fff8eb8a2.png\"\/><\/p>\n<p>  \u041e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u0430\u044f \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u044f \u0446\u0432\u0435\u0442\u0430 \u0432 \u0447\/\u0431 \u0432\u043e\u043b\u0448\u0435\u0431\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u043e\u0439: <code>R*0.21 + G*0.72 + B*0.07<\/code>. \u0411\u0443\u0434\u0435\u0442 \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u00ab\u044f\u0440\u043a\u043e\u0441\u0442\u044c\u00bb.<\/p>\n<p>  \u0428\u0435\u0439\u0434\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0431\u0440\u0430\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0435\u0433\u043e \u044f\u0440\u043a\u043e\u0441\u0442\u044c (\u043f\u043e\u043d\u0438\u0436\u0430\u0442\u044c), \u0430 \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u0439\u0442\u0438 \u0446\u0432\u0435\u0442 \u0438\u0437 \u043f\u0430\u043b\u0438\u0442\u0440\u044b \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b \u0431\u044b\u043b \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0431\u043b\u0438\u0437\u043e\u043a \u043f\u043e \u044f\u0440\u043a\u043e\u0441\u0442\u0438. \u0422\u043e \u0435\u0441\u0442\u044c \u043f\u043e \u0441\u0443\u0442\u0438, \u0448\u0435\u0439\u0434\u0435\u0440 \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430 \u0434\u0432\u0435 \u0447\u0430\u0441\u0442\u0438: 1) \u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u044f\u0440\u043a\u043e\u0441\u0442\u044c \u0438 2) \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0446\u0432\u0435\u0442 \u0438\u0437 \u043f\u0430\u043b\u0438\u0442\u0440\u044b.<\/p>\n<p>  \u0421 \u043e\u043f\u0443\u0441\u043a\u0430\u043d\u0438\u0435\u043c \u044f\u0440\u043a\u043e\u0441\u0442\u0438 \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u2014 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u043e \u0443\u043c\u043d\u043e\u0436\u0430\u0442\u044c \u0446\u0432\u0435\u0442 \u043d\u0430 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442. \u0410 \u0432\u043e\u0442 \u0441 \u043f\u043e\u0438\u0441\u043a\u043e\u043c \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0433\u043e \u0446\u0432\u0435\u0442\u0430 \u0432 \u043f\u0430\u043b\u0438\u0442\u0440\u0435 \u2014 \u0441\u043b\u043e\u0436\u043d\u0435\u0435.<\/p>\n<p>  \u0422\u0435, \u043a\u0442\u043e \u0437\u043d\u0430\u043a\u043e\u043c \u0441 \u0448\u0435\u0439\u0434\u0435\u0440\u0430\u043c\u0438, \u043f\u043e\u043d\u0438\u043c\u0430\u044e\u0442, \u0447\u0442\u043e \u043b\u044e\u0431\u043e\u0439 \u0446\u0438\u043a\u043b \u0432 \u0448\u0435\u0439\u0434\u0435\u0440\u0435 \u2014 \u0440\u0430\u0432\u043d\u043e\u0441\u0438\u043b\u044c\u043d\u043e \u0441\u0430\u043c\u043e\u0443\u0431\u0438\u0439\u0441\u0442\u0432\u0443. \u0422\u0430\u043a \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c \u043f\u0430\u043b\u0438\u0442\u0440\u0443 \u0432 \u043f\u043e\u0438\u0441\u043a\u0430\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0446\u0432\u0435\u0442\u0430 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0438\u043a\u0441\u0435\u043b\u044f \u2014 \u043f\u043b\u043e\u0445\u0430\u044f \u0438\u0434\u0435\u044f. \u041a\u0430\u043a \u0436\u0435 \u0431\u044b\u0442\u044c?<\/p>\n<p>  \u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0438 \u0438\u0437\u044f\u0449\u043d\u043e \u2014 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u044b \u0441\u043b\u0443\u0436\u0438\u043b\u0430 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440\u043e\u043c \u0446\u0432\u0435\u0442\u0430. \u0418 \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u0430\u0447\u043d\u043e, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0430\u043a\u0430\u044f \u0448\u0442\u0443\u043a\u0430, \u043a\u0430\u043a \u0442\u0440\u0435\u0445\u043c\u0435\u0440\u043d\u044b\u0435 \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u044b. \u0422\u043e \u0435\u0441\u0442\u044c \u043c\u044b \u0431\u0435\u0440\u0435\u043c \u0438 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u0430 \u0432 \u0438\u043d\u0434\u0435\u043a\u0441 \u0446\u0432\u0435\u0442\u0430 \u0432 \u043f\u0430\u043b\u0438\u0442\u0440\u0435. \u0410 \u0435\u0449\u0435 \u043b\u0443\u0447\u0448\u0435 \u2014 \u0441\u0440\u0430\u0437\u0443 \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0446\u0432\u0435\u0442. \u0412 \u0442\u0430\u043a\u043e\u0439 \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0435 \u043f\u043e \u0442\u0440\u0435\u043c \u043e\u0441\u044f\u043c \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u0430\u043d\u0435\u043d\u0442 R\/G\/B, \u0430 \u0446\u0432\u0435\u0442 \u043f\u0438\u043a\u0441\u0435\u043b\u044f \u0432 \u044d\u0442\u043e\u0439 \u0442\u043e\u0447\u043a\u0435 \u0438 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0448\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u043c \u0446\u0432\u0435\u0442\u043e\u043c. \u0412\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e! \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0443.<\/p>\n<p>  \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0434\u043b\u044f \u0442\u043e\u0447\u043d\u043e\u0439 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438 \u0446\u0432\u0435\u0442\u0430 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u043e\u043d\u0441\u0442\u0440\u043e\u043f\u043e\u0431\u043e\u0434\u043d\u0443\u044e \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0443, \u0433\u0434\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043e\u0441\u0435\u0439 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0430 \u0431\u044b \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u0433\u0440\u0430\u0434\u0430\u0446\u0438\u0439 \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043c\u043f\u0430\u043d\u0435\u043d\u0442\u044b. \u0422\u043e \u0435\u0441\u0442\u044c 256\u0445256\u0445256. \u041d\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0432\u0430\u0436\u043d\u0430 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c, \u0442.\u043a. \u043c\u044b \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u043c\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e \u043a\u0430\u043a \u0440\u0430\u0437 \u043f\u043e\u043d\u0438\u0436\u0430\u0435\u043c \u0446\u0432\u0435\u0442\u043e\u0432\u0443\u044e \u0433\u043b\u0443\u0431\u0438\u043d\u0443 \u0438 \u0441\u0432\u043e\u0434\u0438\u043c \u0432\u0441\u0435 \u0446\u0432\u0435\u0442\u0430 \u0434\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0446\u0432\u0435\u0442\u043e\u0432 \u0432 \u043f\u0430\u043b\u0438\u0442\u0440\u0435.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0430\u043b\u0438\u0442\u0440\u0443 \u0438 \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u0430 \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u043c \u0435\u0433\u043e \u044f\u0440\u043a\u043e\u0441\u0442\u044c:<\/p>\n<pre><code class=\"cs\">const int depth = 3; \/\/ \u043a\u043e\u043b-\u0432\u043e \u0433\u0440\u0430\u0434\u0430\u0446\u0438\u0439 \u0446\u0432\u0435\u0442\u0430 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0439 \u043f\u0430\u043b\u0438\u0442\u0440\u0435 const float f_depth = 1.0f \/ (1.0f * depth - 1.0f);  Color[] palette = new Color[depth*depth*depth]; float[] palette_grey = new float[depth*depth*depth];  \t\t\/\/ \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043f\u0430\u043b\u0438\u0442\u0440\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0446\u0432\u0435\u0442\u043e\u0432 \t\tfor (int r = 0; r &lt; depth; r++) \t\t{ \t\t\tfor (int g = 0; g &lt; depth; g++) \t\t\t{ \t\t\t\tfor (int b = 0; b &lt; depth; b++) \t\t\t\t{ \t\t\t\t\tColor c = new Color(r * f_depth \/ 2, g * f_depth, b * f_depth, 1); \t\t\t\t\tint n = r*depth*depth + g*depth + b; \t\t\t\t\tpalette[n] = c; \t\t\t\t\tpalette_grey[n] = c.r*0.21f + c.g*0.72f + c.b*0.07f; \t\t\t\t} \t\t\t} \t\t} <\/code><\/pre>\n<p>  \u0421\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u044f \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u0434\u0435\u043b\u0438\u043b R \u043a\u043e\u043c\u043f\u0430\u043d\u0435\u043d\u0442\u0443 \u043d\u0430 2, \u0442.\u043a. \u043c\u043d\u0435 \u043d\u0435 \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0439 \u043f\u0430\u043b\u0438\u0442\u0440\u0435 \u043a\u0440\u0430\u0441\u043d\u044b\u0439 \u0446\u0432\u0435\u0442 \u0443\u0436 \u043e\u0447\u0435\u043d\u044c \u00ab\u0432\u044b\u043f\u0438\u0440\u0430\u043b\u00bb.<\/p>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u2014 \u0441\u0430\u043c\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435. \u041d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c 3D \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0443 \u0434\u043b\u044f \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438.  <\/p>\n<pre><code class=\"cs\">const int dim = 16; \/\/ \u043a\u043e\u043b-\u0432\u043e \u0433\u0440\u0430\u0434\u0430\u0446\u0438\u0439 \u0446\u0432\u0435\u0442\u0430 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u043b\u0438\u0442\u0440\u0435 const float f_dim = 1.0f \/ (1.0f * dim - 1.0f);  Texture3D tex = new Texture3D(dim, dim, dim, TextureFormat.RGB565, false); tex.filterMode = FilterMode.Point; \/\/ \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044e! tex.wrapMode = TextureWrapMode.Clamp;  Color[] t = new Color[dim*dim*dim];  \/\/ \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0443 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f for (int r = 0; r &lt; dim; r++) { \tfor (int g = 0; g &lt; dim; g++) \t{ \t\tfor (int b = 0; b &lt; dim; b++) \t\t{ \t\t\tfloat grey = (r * 0.21f + g * 0.72f + b * 0.07f) * f_dim; \t\t\t\/\/ \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0439\u0434\u0435\u043c \u0441\u0430\u043c\u044b\u0439 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0439 \u0446\u0432\u0435\u0442 \u043f\u043e \u044f\u0440\u043a\u043e\u0441\u0442\u0438 \u0441\u0435\u0440\u043e\u0433\u043e \t\t\tint idx = 0; \t\t\tfloat min_d = grey; \t\t\tfor (int i = 1; i &lt; palette_grey.Length; i++) \t\t\t{ \t\t\t\tfloat d = Mathf.Abs(palette_grey[i] - grey); \t\t\t\tif (d &lt; min_d) \t\t\t\t{ \t\t\t\t\tmin_d = d; \t\t\t\t\tidx = i; \t\t\t\t} \t\t\t} \t\t\tt[r * dim * dim + g * dim + b] = palette[idx]; \/\/ \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u043f\u0430\u043b\u0438\u0442\u0440\u0443 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438 \t\t} \t} }  tex.SetPixels(t); tex.Apply(); <\/code><\/pre>\n<p>  \u041d\u0443, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0435\u0449\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0430\u043c \u0448\u0435\u0439\u0434\u0435\u0440, \u043d\u043e \u0442\u0443\u0442 \u0432\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e:  <\/p>\n<pre><code class=\"cpp\">half4 color = tex2D(_MainTex, i.uv); half4 rc = tex3D(_PaletteTex, color.rgb * _Br);  float d = abs(Luminance(color) - Luminance(rc));  if ((d &lt; 0.15) || (_Br == 1)) rc = color;  return rc; <\/code><\/pre>\n<p>  \u0422\u0443\u0442 \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0441\u0442\u0440\u043e\u0447\u043a\u0443 \u0441 <code>if<\/code>. \u0412\u0442\u043e\u0440\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u2014 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e \u2014 \u00ab\u0435\u0441\u043b\u0438 \u044f\u0440\u043a\u043e\u0441\u0442\u044c == 1, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0446\u0432\u0435\u0442 \u043d\u0435\u0442\u0440\u043e\u043d\u0443\u0442\u044b\u043c\u00bb. \u0410 \u0432\u043e\u0442 \u043f\u0435\u0440\u0432\u043e\u0435 \u2014 \u044d\u0442\u043e \u043d\u0435\u043a\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435, \u0447\u0442\u043e \u00ab\u043a\u043e\u0433\u0434\u0430 \u0446\u0432\u0435\u0442 \u0438\u0437 \u043f\u0430\u043b\u0438\u0442\u0440\u044b \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u043b\u0438\u0437\u043e\u043a (\u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 15%) \u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u043c\u0443, \u0442\u043e \u0442\u043e\u0436\u0435 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0446\u0432\u0435\u0442. \u042d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0435 \u043d\u0435\u043d\u0443\u0436\u043d\u043e\u0435 \u201e\u0434\u0440\u0435\u0431\u0435\u0437\u0436\u0430\u043d\u0438\u0435\u201c \u0446\u0432\u0435\u0442\u043e\u0432. \u041d\u0435\u043a\u0438\u0439 \u201esnapping\u201c, \u0435\u0441\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u0443\u0433\u043e\u0434\u043d\u043e. \u0418 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e-\u044d\u0442\u043e\u043c\u0443 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043d\u0430 \u043d\u0430\u0448\u0435\u043c \u0441\u043a\u0440\u0438\u043d\u0435 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0441\u0432\u043e\u0435\u0433\u043e \u0446\u0432\u0435\u0442\u0430 \u0440\u0430\u043d\u044c\u0448\u0435 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0444\u0430\u0437\u044b. \u0418\u043d\u0430\u0447\u0435 \u0431\u044b \u043e\u043d\u0438 \u0434\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0431\u044b\u043b\u0438 \u043d\u0435 \u0441\u0432\u043e\u0435\u0433\u043e \u0446\u0432\u0435\u0442\u0430, \u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0431\u043b\u0438\u0437\u043a\u043e\u0433\u043e \u0438\u0437 \u043f\u0430\u043b\u0438\u0442\u0440\u044b. \u0427\u0442\u043e \u043f\u043b\u043e\u0445\u043e \u0431\u044b \u0441\u043c\u043e\u0442\u0440\u0435\u043b\u043e\u0441\u044c \u0434\u043b\u044f \u0442\u0435\u043c\u043d\u044b\u0445 \u0446\u0432\u0435\u0442\u043e\u0432.<\/p>\n<p>  \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432\u0441\u0435. <\/p>\n<p>  \u041a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">shader<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cpp\">Shader &quot;Custom\/Palette Shader&quot;  { \tProperties { \t\t_MainTex (&quot;Base (RGB)&quot;, 2D) = &quot;white&quot; {} \t\t_Br(&quot;Brightness&quot;, Float) = 0 \t\t_PaletteTex (&quot;Pelette texture&quot;, 3D) = &quot;white&quot; {}  \t}  \tSubShader { \t\tPass { \t\t\tZTest Always Cull Off ZWrite Off Fog { Mode off }  \t\t\tCGPROGRAM  \t\t\t#pragma vertex vert \t\t\t#pragma fragment frag \t\t\t#pragma fragmentoption ARB_precision_hint_fastest \t\t\t#include &quot;UnityCG.cginc&quot; \t\t\t#pragma target 3.0  \t\t\tstruct v2f  \t\t\t{ \t\t\t\tfloat4 pos      : POSITION; \t\t\t\tfloat2 uv       : TEXCOORD0; \t\t\t};  \t\t\tuniform sampler2D _MainTex; \t\t\tuniform sampler3D _PaletteTex; \t\t\tuniform float _Br;  \t\t\tv2f vert(appdata_img v) \t\t\t{ \t\t\t\tv2f o; \t\t\t\to.pos = mul(UNITY_MATRIX_MVP, v.vertex); \t\t\t\to.uv = MultiplyUV(UNITY_MATRIX_TEXTURE0, v.texcoord); \t\t\t\treturn o; \t\t\t}  \t\t\thalf4 frag(v2f i): COLOR \t\t\t{ \t\t\t\thalf4 color = tex2D(_MainTex, i.uv); \t\t\t\thalf4 rc = tex3D(_PaletteTex, color.rgb * _Br);  \t\t\t\tfloat d = abs(Luminance(color) - Luminance(rc));  \t\t\t\tif ((d &lt; 0.15) || (_Br == 1)) rc = color;  \t\t\t\treturn rc; \t\t\t}  \t\t\tENDCG \t\t} \t} \tFallBack &quot;Diffuse&quot; }  <\/code><\/pre>\n<\/div>\n<\/div>\n<div class=\"spoiler\"><b class=\"spoiler_title\">c#<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">using UnityEngine;  [ExecuteInEditMode] [RequireComponent(typeof(Camera))]  public class PaletteShader : MonoBehaviour  { \tpublic Shader shader; \tprivate Material _material;  \t[Range(0, 1)] public float brightness = 0.0f; \t[Range(0, 1)] public float random = 1f;  \tprivate float _r = 0f; \tprivate Texture3D _tex; \t\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ \tprotected Material material \t{ \t\tget \t\t{ \t\t\tif (_material == null) \t\t\t{ \t\t\t\t_material = new Material(shader); \t\t\t\t_material.hideFlags = HideFlags.HideAndDontSave; \t\t\t}  \t\t\treturn _material; \t\t} \t} \t\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ \tprivate Texture3D GeneratePaletteTexture() \t{ \t\tconst int dim = 16; \/\/ \u043a\u043e\u043b-\u0432\u043e \u0433\u0440\u0430\u0434\u0430\u0446\u0438\u0439 \u0446\u0432\u0435\u0442\u0430 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u043b\u0438\u0442\u0440\u0435 \t\tconst int depth = 3; \/\/ \u043a\u043e\u043b-\u0432\u043e \u0433\u0440\u0430\u0434\u0430\u0446\u0438\u0439 \u0446\u0432\u0435\u0442\u0430 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0439 \u043f\u0430\u043b\u0438\u0442\u0440\u0435  \t\tconst float f_dim = 1.0f \/ (1.0f * dim - 1.0f); \t\tconst float f_depth = 1.0f \/ (1.0f * depth - 1.0f);  \t\tTexture3D tex = new Texture3D(dim, dim, dim, TextureFormat.RGB565, false); \t\ttex.filterMode = FilterMode.Point; \t\ttex.wrapMode = TextureWrapMode.Clamp;  \t\tColor[] palette = new Color[depth*depth*depth]; \t\tfloat[] palette_grey = new float[depth*depth*depth];  \t\t\/\/ \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043f\u0430\u043b\u0438\u0442\u0440\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0446\u0432\u0435\u0442\u043e\u0432 \t\tfor (int r = 0; r &lt; depth; r++) \t\t{ \t\t\tfor (int g = 0; g &lt; depth; g++) \t\t\t{ \t\t\t\tfor (int b = 0; b &lt; depth; b++) \t\t\t\t{ \t\t\t\t\tColor c = new Color(r * f_depth \/ 2, g * f_depth, b * f_depth, 1); \t\t\t\t\tint n = r*depth*depth + g*depth + b; \t\t\t\t\tpalette[n] = c; \t\t\t\t\tpalette_grey[n] = c.r*0.21f + c.g*0.72f + c.b*0.07f; \t\t\t\t} \t\t\t} \t\t}  \t\tColor[] t = new Color[dim*dim*dim]; \t\t\/\/ \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0443 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \t\tfor (int r = 0; r &lt; dim; r++) \t\t{ \t\t\tfor (int g = 0; g &lt; dim; g++) \t\t\t{ \t\t\t\tfor (int b = 0; b &lt; dim; b++) \t\t\t\t{ \t\t\t\t\tfloat grey = (r * 0.21f + g * 0.72f + b * 0.07f) * f_dim; \t\t\t\t\t\/\/ \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0439\u0434\u0435\u043c \u0441\u0430\u043c\u044b\u0439 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0439 \u0446\u0432\u0435\u0442 \u043f\u043e \u044f\u0440\u043a\u043e\u0441\u0442\u0438 \u0441\u0435\u0440\u043e\u0433\u043e \t\t\t\t\tint idx = 0; \t\t\t\t\tfloat min_d = grey; \t\t\t\t\tfor (int i = 1; i &lt; palette_grey.Length; i++) \t\t\t\t\t{ \t\t\t\t\t\tfloat d = Mathf.Abs(palette_grey[i] - grey); \t\t\t\t\t\tif (d &lt; min_d) \t\t\t\t\t\t{ \t\t\t\t\t\t\tmin_d = d; \t\t\t\t\t\t\tidx = i; \t\t\t\t\t\t} \t\t\t\t\t} \t\t\t\t\tt[r * dim * dim + g * dim + b] = palette[idx]; \/\/ \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u043f\u0430\u043b\u0438\u0442\u0440\u0443 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438 \t\t\t\t} \t\t\t} \t\t}  \t\ttex.SetPixels(t); \t\ttex.Apply(); \t\treturn tex; \t} \t\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ \tprivate void OnRenderImage(RenderTexture source, RenderTexture destination) \t{ \t\tif (shader == null) return; \t\tMaterial mat = material; \t\tmat.SetFloat(&quot;_Br&quot;, brightness);  \t\tif (_tex == null) _tex = GeneratePaletteTexture(); \t\tif (random != _r) \t\t{ \t\t\t_r = random; \t\t\t_tex = GeneratePaletteTexture(); \t\t} \t\tmat.SetTexture(&quot;_PaletteTex&quot;, _tex);  \t\tGraphics.Blit(source, destination, mat); \t} \t\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ \tvoid OnDisable() \t{ \t\tif (_material)\tDestroyImmediate(_material); \t} \t\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ }<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  \u0421\u0442\u043e\u0438\u0442 \u0435\u0449\u0435 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0447\u0442\u043e \u0432 \u043a\u043e\u0434\u0435 \u0432\u044b\u0448\u0435 \u044f \u0432\u0432\u0435\u043b \u0442\u0430\u043a\u043e\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u043a\u0430\u043a \u201erandom\u201c. \u042d\u0442\u043e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0446\u0432\u0435\u0442\u043e\u0432 \u043d\u0430 \u043b\u0435\u0442\u0443 \u0438 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u0430\u043b\u0438\u0442\u0440\u044b. \u0422\u043e \u0435\u0441\u0442\u044c \u043f\u043e\u043c\u0435\u043d\u044f\u043b \u043a\u043e\u0434, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043f\u0430\u043b\u0438\u0442\u0440\u0443 \u0438 \u0441\u0434\u0432\u0438\u043d\u0443\u0432 \u043f\u043e\u043b\u0437\u0443\u043d\u043e\u043a \u201erandom\u201c \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u043b \u0438\u0433\u0440\u0443 \u043f\u0435\u0440\u0435\u0433\u0435\u043d\u0435\u0440\u0438\u0442\u044c \u043f\u0430\u043b\u0438\u0442\u0440\u0443.    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/213253\/\"> http:\/\/habrahabr.ru\/post\/213253\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0448\u0435\u0439\u0434\u0435\u0440\u0430, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0435\u0433\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c fade in\/out \u043f\u043e \u043f\u0430\u043b\u0438\u0442\u0440\u0435, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u043b\u043e\u0441\u044c \u0432 \u0441\u0442\u0430\u0440\u044b\u0445 NES-\u0438\u0433\u0440\u0430\u0445 \u0438 \u0442.\u043f.<\/p>\n<p>  \u0421\u0443\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0439 \u043f\u0430\u043b\u0438\u0442\u0440\u044b \u0446\u0432\u0435\u0442\u043e\u0432 \u043d\u0435\u043b\u044c\u0437\u044f \u0431\u044b\u043b\u043e \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u0437\u0430\u0442\u0435\u043c\u043d\u0438\u0442\u044c (\u0438\u043b\u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0438\u0437 \u0442\u0435\u043c\u043d\u043e\u0442\u044b) \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443, \u0442.\u043a. \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u043e \u043d\u0443\u0436\u043d\u044b\u0445 \u0446\u0432\u0435\u0442\u043e\u0432 \u0432 \u043f\u0430\u043b\u0438\u0442\u0440\u0435. \u0418 \u044d\u0442\u043e \u0440\u0435\u0448\u0430\u043b\u043e\u0441\u044c \u043f\u0443\u0442\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0446\u0432\u0435\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0431\u043e\u043b\u0435\u0435 \u0442\u0435\u043c\u043d\u044b\u0435. \u0422\u043e \u0435\u0441\u0442\u044c \u043d\u0443\u0436\u043d\u043e \u0432\u0430\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c fade in \u0436\u0435\u043b\u0442\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0430 \u0432 \u043f\u0430\u043b\u0438\u0442\u0440\u0435 \u043d\u0435\u0442 \u0442\u0435\u043c\u043d\u043e-\u0436\u0435\u043b\u0442\u044b\u0445 \u043e\u0442\u0442\u0435\u043d\u043a\u043e\u0432 \u2014 \u0432\u043e\u0442 \u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0438\u043d\u0438\u043c (\u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0435\u043c\u043d\u044b\u043c), \u043f\u043e\u0442\u043e\u043c \u2014 \u043a\u0440\u0430\u0441\u043d\u044b\u043c \u0438 \u0442.\u043f.<\/p>\n<p>  \u041d\u0438\u0436\u0435 \u044f \u043f\u043e\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0448\u0435\u0439\u0434\u0435\u0440\u0430:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/b44\/ec1\/d1f\/b44ec1d1f78b349acd274cfa285cfced.gif\"\/><\/p>\n<p>  \u0421\u0440\u0430\u0437\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0433\u043e\u0432\u043e\u0440\u044e\u0441\u044c \u2014 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0438\u043b\u0438 \u043d\u0435\u0442 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u0448\u0435\u0439\u0434\u0435\u0440 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0438\u0433\u0440\u0435, \u043c\u044b \u0435\u0449\u0435 \u043d\u0435 \u0440\u0435\u0448\u0438\u043b\u0438. \u0422\u0430\u043a \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u043d \u043d\u0430 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c \u043f\u0438\u043a\u0441\u0435\u043b\u044c-\u0430\u0440\u0442\u0435 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0446\u0432\u0435\u0442\u043e\u0432, \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u043f\u043e\u0440\u043d\u043e.   <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-213253","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/213253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=213253"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/213253\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=213253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=213253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=213253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}