{"id":355109,"date":"2024-05-20T23:01:52","date_gmt":"2024-05-20T23:01:52","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=355109"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=355109","title":{"rendered":"<span>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 Gradient \u0447\u0435\u0440\u0435\u0437 jobs + burst<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 Unity \u0435\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441 Gradient, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043e\u043c \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435 \u0438 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\u0435. \u041d\u043e \u0442.\u043a. \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441, \u0430 \u043d\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0447\u0435\u0440\u0435\u0437 Job system \u0438 burst \u043d\u0435\u043b\u044c\u0437\u044f. \u042d\u0442\u043e \u043f\u0435\u0440\u0432\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u0412\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u2014 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430. \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043c\u0430\u0441\u0441\u0438\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0432 \u043a\u0443\u0447\u0435. \u0418 \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435 \u043d\u0430\u043f\u0440\u044f\u0433\u0430\u0435\u0442 \u0441\u0431\u043e\u0440\u0449\u0438\u043a \u043c\u0443\u0441\u043e\u0440\u0430.<\/p>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b. \u0418 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0431\u043e\u043d\u0443\u0441\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u043e 8 \u0440\u0430\u0437 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 Evaluate \u0447\u0435\u0440\u0435\u0437 burst.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/aab\/06a\/7dc\/aab06a7dc25442ebc08f41e4f9eaf3b7.png\" width=\"360\" height=\"182\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/aab\/06a\/7dc\/aab06a7dc25442ebc08f41e4f9eaf3b7.png\"\/><\/figure>\n<h2>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u044f\u043c\u043e\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430. \u042d\u0442\u043e\u0442 \u0430\u0434\u0440\u0435\u0441 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u043c \u043d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u0432\u0441\u0435\u0439 \u0436\u0438\u0437\u043d\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u0435\u0433\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043f\u0440\u044f\u043c\u044b\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430, \u043d\u0435 \u043f\u0435\u0440\u0435\u0436\u0438\u0432\u0430\u044f \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0430\u0434\u0440\u0435\u0441 \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c\u0441\u044f.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/664\/f00\/dee\/664f00deebc993a810fd0b825fee7869.png\" alt=\"m_Ptr \u2013 \u0430\u0434\u0440\u0435\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u044f c++ \u0447\u0430\u0441\u0442\u0438 \u0434\u0432\u0438\u0436\u043a\u0430.\" title=\"m_Ptr \u2013 \u0430\u0434\u0440\u0435\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u044f c++ \u0447\u0430\u0441\u0442\u0438 \u0434\u0432\u0438\u0436\u043a\u0430.\" width=\"418\" height=\"101\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/664\/f00\/dee\/664f00deebc993a810fd0b825fee7869.png\"\/><\/p>\n<div><figcaption>m_Ptr \u2013 \u0430\u0434\u0440\u0435\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u044f c++ \u0447\u0430\u0441\u0442\u0438 \u0434\u0432\u0438\u0436\u043a\u0430.<\/figcaption><\/div>\n<\/figure>\n<p>\u0412\u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0430\u0434\u0440\u0435\u0441, \u043d\u0435 \u043f\u0440\u0438\u0431\u0435\u0433\u0430\u044f \u043a \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u0438 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435. \u0418\u0437 \u043c\u0438\u043d\u0443\u0441\u043e\u0432, \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043a\u0440\u0435\u043f\u0438\u0442\u044c. \u0418\u0437 \u043f\u043b\u044e\u0441\u043e\u0432 \u0430\u0434\u0440\u0435\u0441 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0440\u0435\u043c\u044f, \u0437\u0430\u0442\u0440\u0430\u0447\u0435\u043d\u043d\u043e\u0435 \u043d\u0430 \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0435 \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e.<\/p>\n<pre><code class=\"cs\">public static class GradientExt {     private static readonly int m_PtrOffset;          static GradientExt()     {         var m_PtrMember = typeof(Gradient).GetField(\"m_Ptr\", BindingFlags.Instance | BindingFlags.NonPublic         m_PtrOffset = UnsafeUtility.GetFieldOffset(m_PtrMember);     }          public static unsafe IntPtr Ptr(this Gradient gradient)     {         var ptr = (byte*) UnsafeUtility.PinGCObjectAndGetAddress(gradient, out var handle);         var gradientPtr = *(IntPtr*) (ptr + m_PtrOffset);         UnsafeUtility.ReleaseGCObject(handle);         return gradientPtr;     } }<\/code><\/pre>\n<p>UnsafeUtility.GetFieldOffset \u2013 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438\u043b\u0438 \u043a\u043b\u0430\u0441\u0441\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043d\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f.<\/p>\n<p>UnsafeUtility.PinGCObjectAndGetAddress \u2013 \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u044f\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442. \u0418 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0430\u0434\u0440\u0435\u0441 \u0443\u0447\u0430\u0441\u0442\u043a\u0430 \u043f\u0430\u043c\u044f\u0442\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442.<\/p>\n<p>UnsafeUtility.ReleaseGCObject \u2013 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u0442 \u0445\u044d\u043d\u0434\u043b \u043e\u0431\u044a\u0435\u043a\u0442\u0430 GC, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0440\u0430\u043d\u0435\u0435.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0430\u0434\u0440\u0435\u0441 \u043d\u0430 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043f\u0430\u043c\u044f\u0442\u0438, \u0433\u0434\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430.<\/p>\n<pre><code class=\"cs\">public Gradient gradient; .... IntPtr gradientPtr = gradient.Ptr();<\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043d\u0443\u0436\u043d\u043e \u043d\u0435\u043c\u043d\u043e\u0436\u043a\u043e \u043f\u043e\u043a\u043e\u0432\u044b\u0440\u044f\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u0434\u0430\u043d\u043d\u044b\u0435 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f \u0432\u044b\u0432\u0435\u0434\u0443 \u0432 \u0438\u043d\u0441\u043f\u0435\u043a\u0442\u043e\u0440 Unity \u044d\u0442\u043e\u0442 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430. \u0417\u0430\u0442\u0435\u043c \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442 \u0438 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u0430\u043a\u0438\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u0443\u0447\u0430\u0441\u0442\u043a\u0438 \u044d\u0442\u043e \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u0435\u0442.<\/p>\n<pre><code class=\"cs\">[ExecuteAlways] public class MemoryResearch : MonoBehaviour {     public Gradient gradient = new Gradient();     public float[] gradientMemoryLocation = new float[50];     private static unsafe void CopyMemory&lt;T>(Gradient gradient, T[] gradientMemoryLocation) where T : unmanaged     {         IntPtr gradientPtr = gradient.Ptr();         fixed (T* gradientMemoryLocationPtr = gradientMemoryLocation)             UnsafeUtility.MemCpy(gradientMemoryLocationPtr, (void*) gradientPtr, gradientMemoryLocation.Length);     }          private void Update()     {         CopyMemory(gradient, gradientMemoryLocation);     } }<\/code><\/pre>\n<p>UnsafeUtility.MemCpy \u2013 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0430\u0439\u0442 \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u0434\u0440\u0443\u0433\u0443\u044e.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/832\/896\/e9a\/832896e9ae43da15f5d41fb8cfb34ba7.png\" alt=\"\u0414\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0446\u0432\u0435\u0442\u0430.\" title=\"\u0414\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0446\u0432\u0435\u0442\u0430.\" width=\"1486\" height=\"547\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/832\/896\/e9a\/832896e9ae43da15f5d41fb8cfb34ba7.png\"\/><\/p>\n<div><figcaption>\u0414\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0446\u0432\u0435\u0442\u0430.<\/figcaption><\/div>\n<\/figure>\n<p>\u041f\u0443\u0442\u0451\u043c \u043d\u0435\u0445\u0438\u0442\u0440\u044b\u0445 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0439 \u0438 \u0441\u043c\u0435\u043d\u044b \u0442\u0438\u043f\u0430 \u043f\u0430\u043c\u044f\u0442\u0438 float\/ushort\/byte \u0438 \u0442.\u0434. \u044f \u043d\u0430\u0448\u0451\u043b \u043f\u043e\u043b\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0443 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0434\u043b\u044f Unity 22.3, \u043d\u043e \u0435\u0441\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u0439. \u0421 \u043f\u043e\u043b\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 \u043a\u043e\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<pre><code class=\"cs\">\/\/\u041f\u043e\u0437\u0438\u0446\u0438\u0438 \u043a\u043b\u044e\u0447\u0435\u0439 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u043a\u0430\u043a ushort \u0433\u0434\u0435 0 = 0%, \u0430 65535 = 100%. public unsafe struct GradientStruct {     private fixed byte colors[sizeof(float) * 4 * 8]; \/\/8 rgba \u0446\u0432\u0435\u0442\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 (128 \u0431\u0430\u0439\u0442)     private fixed byte colorTimes[sizeof(ushort) * 8]; \/\/\u0432\u0440\u0435\u043c\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 (16 \u0431\u0430\u0439\u0442)     private fixed byte alphaTimes[sizeof(ushort) * 8]; \/\/\u0432\u0440\u0435\u043c\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0430\u043b\u044c\u0444\u0430 \u043a\u043b\u044e\u0447\u0430 (16 \u0431\u0430\u0439\u0442)     private byte colorCount; \/\/\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0446\u0432\u0435\u0442\u043e\u0432\u044b\u0445 \u043a\u043b\u044e\u0447\u0435\u0439     private byte alphaCount; \/\/\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u043b\u044c\u0444\u0430 \u043a\u043b\u044e\u0447\u0435\u0439     private byte mode; \/\/\u0440\u0435\u0436\u0438\u043c \u0441\u043c\u0435\u0448\u0438\u0432\u0430\u043d\u0438\u044f \u0446\u0432\u0435\u0442\u043e\u0432     private byte colorSpace; \/\/\u0446\u0432\u0435\u0442\u043e\u0432\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 GradientStruct:<\/p>\n<pre><code class=\"cs\">public static unsafe GradientStruct* DirectAccess(this Gradient gradient) {     return (GradientStruct*) gradient.Ptr(); }<\/code><\/pre>\n<h2>Gradient.colorKeys \u0447\u0435\u0440\u0435\u0437 NativeArray<\/h2>\n<p>\u0417\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0430\u043c\u044f\u0442\u0438 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Gradient.colorKeys \u0438 Gradient.alphaKeys \u0447\u0435\u0440\u0435\u0437 NativeArray.<\/p>\n<pre><code class=\"cs\">private float4* Colors(int index) {     fixed(byte* colorsPtr = colors) return (float4*) colorsPtr + index; }  private ushort* ColorsTimes(int index) {     fixed(byte* colorTimesPtr = colorTimes) return (ushort*) colorTimesPtr + index; }  private ushort* AlphaTimes(int index) {     fixed(byte* alphaTimesPtr = alphaTimes) return (ushort*) alphaTimesPtr + index; }  public void SetColorKey(int index, GradientColorKeyBurst value) {     #if ENABLE_UNITY_COLLECTIONS_CHECKS         if (index &lt; 0 || index > 7) IncorrectIndex();     #endif      Colors(index)->xyz = value.color.xyz;     *ColorsTimes(index) = (ushort) (65535 * value.time); }  public GradientColorKeyBurst GetColorKey(int index) {     #if ENABLE_UNITY_COLLECTIONS_CHECKS         if (index &lt; 0 || index > 7) IncorrectIndex();     #endif      return new GradientColorKeyBurst(*Colors(index), *ColorsTimes(index) \/ 65535f); }  public void SetColorKeys(NativeArray&lt;GradientColorKeyBurst> colorKeys) {     #if ENABLE_UNITY_COLLECTIONS_CHECKS         if (colorKeys.Length &lt; 2 || colorKeys.Length > 8) IncorrectLength();     #endif      var colorKeysTmp = new NativeArray&lt;GradientColorKeyBurst>(colorKeys, Allocator.Temp);     colorKeysTmp.Sort&lt;GradientColorKeyBurst, GradientColorKeyBurstComparer>(default);      colorCount = (byte) colorKeys.Length;          for (var i = 0; i &lt; colorCount; i++)     {         SetColorKey(i, colorKeysTmp[i]);     }      colorKeysTmp.Dispose(); }  public void SetColorKeysWithoutSort(NativeArray&lt;GradientColorKeyBurst> colorKeys) {     #if ENABLE_UNITY_COLLECTIONS_CHECKS         if (colorKeys.Length &lt; 2 || colorKeys.Length > 8) IncorrectLength();     #endif      colorCount = (byte) colorKeys.Length;          for (var i = 0; i &lt; colorCount; i++)     {         SetColorKey(i, colorKeys[i]);     } }  public NativeArray&lt;GradientColorKeyBurst> GetColorKeys(Allocator allocator) {     var colorKeys = new NativeArray&lt;GradientColorKeyBurst>(colorCount, allocator);          for (var i = 0; i &lt; colorCount; i++)     {         colorKeys[i] = GetColorKey(i);     }      return colorKeys; }  public void SetAlphaKey(int index, GradientAlphaKey value) {     #if ENABLE_UNITY_COLLECTIONS_CHECKS         if (index &lt; 0 || index > 7) IncorrectIndex();     #endif      Colors(index)->w = value.alpha;     *AlphaTimes(index) = (ushort) (65535 * value.time); }  public GradientAlphaKey GetAlphaKey(int index) {     #if ENABLE_UNITY_COLLECTIONS_CHECKS         if (index &lt; 0 || index > 7) IncorrectIndex();     #endif      return new GradientAlphaKey(Colors(index)->w, *AlphaTimes(index) \/ 65535f); }  public void SetAlphaKeys(NativeArray&lt;GradientAlphaKey> alphaKeys) {     #if ENABLE_UNITY_COLLECTIONS_CHECKS         if (alphaKeys.Length &lt; 2 || alphaKeys.Length > 8) IncorrectLength();     #endif      var alphaKeysTmp = new NativeArray&lt;GradientAlphaKey>(alphaKeys, Allocator.Temp);     alphaKeysTmp.Sort&lt;GradientAlphaKey, GradientAlphaKeyComparer>(default);      alphaCount = (byte) alphaKeys.Length;          for (var i = 0; i &lt; alphaCount; i++)     {         SetAlphaKey(i, alphaKeys[i]);     }      alphaKeysTmp.Dispose(); }  public void SetAlphaKeysWithoutSort(NativeArray&lt;GradientAlphaKey> alphaKeys) {     #if ENABLE_UNITY_COLLECTIONS_CHECKS         if (alphaKeys.Length &lt; 2 || alphaKeys.Length > 8) IncorrectLength();     #endif      alphaCount = (byte) alphaKeys.Length;          for (var i = 0; i &lt; alphaCount; i++)     {         SetAlphaKey(i, alphaKeys[i]);     } }  public NativeArray&lt;GradientAlphaKey> GetAlphaKeys(Allocator allocator) {     var alphaKeys = new NativeArray&lt;GradientAlphaKey>(alphaCount, allocator);          for (var i = 0; i &lt; alphaCount; i++)     {         alphaKeys[i] = GetAlphaKey(i);     }      return alphaKeys; }  private struct GradientColorKeyBurstComparer : IComparer&lt;GradientColorKeyBurst> {     public int Compare(GradientColorKeyBurst v1, GradientColorKeyBurst v2)     {         return v1.time.CompareTo(v2.time);     } }  private struct GradientAlphaKeyComparer : IComparer&lt;GradientAlphaKey> {     public int Compare(GradientAlphaKey v1, GradientAlphaKey v2)     {         return v1.time.CompareTo(v2.time);     } }<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435<\/p>\n<pre><code class=\"cs\">var colorKeys = gradient.colorKeys; var alphaKeys = gradient.alphaKeys;<\/code><\/pre>\n<p>\u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430<\/p>\n<pre><code class=\"cs\">var gradientPtr = gradient.DirectAccess(); var colorKeys = gradientPtr->GetColorKeys(Allocator.Temp); var alphaKeys = gradientPtr->GetAlphaKeys(Allocator.Temp);<\/code><\/pre>\n<p>\u0438 \u0437\u0430\u0431\u044b\u0442\u044c \u043e \u0441\u0431\u043e\u0440\u0449\u0438\u043a\u0435 \u043c\u0443\u0441\u043e\u0440\u0430 \u043f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0410 \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0432\u043d\u0443\u0442\u0440\u0438 Job system. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 gradient.DirectAccess() \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u0432\u0441\u0435\u0439 \u0436\u0438\u0437\u043d\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<h2>\u0424\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u043b\u044f Job system<\/h2>\n<p>\u041d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u0435\u0442\u043e\u0434\u0430 Evaluate, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u0434\u043e\u0441\u044f\u0433\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u0438\u0437 \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b. \u0412\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043d\u0435 \u0431\u0443\u0434\u0443. \u041e\u043d \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u0435\u043d \u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043a \u0442\u0435\u043c\u0435 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<pre><code class=\"cs\">public float4 Evaluate(float time) {     float3 color = default;     var colorCalculated = false;     var colorKey = GetColorKeyBurst(0);     if (time &lt;= colorKey.time)     {         color = colorKey.color.xyz;         colorCalculated = true;     }          if (!colorCalculated)         for (var i = 0; i &lt; colorCount - 1; i++)         {             var colorKeyNext = GetColorKeyBurst(i + 1);                              if (time &lt;= colorKeyNext.time)             {                 if (Mode == GradientMode.Blend)                 {                     var localTime = (time - colorKey.time) \/ (colorKeyNext.time - colorKey.time);                     color = math.lerp(colorKey.color.xyz, colorKeyNext.color.xyz, localTime);                 }                 else if (Mode == GradientMode.PerceptualBlend)                 {                     var localTime = (time - colorKey.time) \/ (colorKeyNext.time - colorKey.time);                     color = OklabToLinear(math.lerp(LinearToOklab(colorKey.color.xyz), LinearToOklab(colorKeyNext.color.xyz), localTime));                 }                 else                 {                     color = colorKeyNext.color.xyz;                 }                 colorCalculated = true;                 break;             }                          colorKey = colorKeyNext;         }        if (!colorCalculated) color = colorKey.color.xyz;                    float alpha = default;     var alphaCalculated = false;          var alphaKey = GetAlphaKey(0);     if (time &lt;= alphaKey.time)     {         alpha = alphaKey.alpha;         alphaCalculated = true;     }          if (!alphaCalculated)         for (var i = 0; i &lt; alphaCount - 1; i++)         {             var alphaKeyNext = GetAlphaKey(i + 1);                              if (time &lt;= alphaKeyNext.time)             {                 if (Mode == GradientMode.Blend || Mode == GradientMode.PerceptualBlend)                 {                     var localTime = (time - alphaKey.time) \/ (alphaKeyNext.time - alphaKey.time);                     alpha = math.lerp(alphaKey.alpha, alphaKeyNext.alpha, localTime);                 }                 else                 {                     alpha = alphaKeyNext.alpha;                 }                 alphaCalculated = true;                 break;             }                          alphaKey = alphaKeyNext;         }          if (!alphaCalculated) alpha = alphaKey.alpha;              return new float4(color, alpha); }<\/code><\/pre>\n<h2>\u041c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c<\/h2>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0430\u044f \u0432\u044b\u0448\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0443\u043c\u0435\u0435\u0442 \u043a\u0430\u043a \u0447\u0438\u0442\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u0438\u0445. \u0415\u0441\u043b\u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0435\u0451 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0442\u043e\u043a\u0430\u0445 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438, \u0442\u043e \u0431\u0443\u0434\u0435\u0442 Race Conditions. \u041d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0435\u0451 \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u043d\u0438\u0439. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u044e readonly \u0432\u0435\u0440\u0441\u0438\u044e.<\/p>\n<pre><code class=\"cs\">internal unsafe struct GradientStruct {    ...      public static ReadOnly AsReadOnly(GradientStruct* data) => new ReadOnly(data);    public readonly struct ReadOnly   {       private readonly GradientStruct* ptr;       public ReadOnly(GradientStruct* ptr)       {           this.ptr = ptr;       }              public int ColorCount => ptr->ColorCount;              public int AlphaCount => ptr->AlphaCount;              public GradientMode Mode => ptr->Mode;              #if UNITY_2022_2_OR_NEWER           public ColorSpace ColorSpace => ptr->ColorSpace;       #endif              public GradientColorKeyBurst GetColorKey(int index) => ptr->GetColorKey(index);              public NativeArray&lt;GradientColorKeyBurst> GetColorKeys(Allocator allocator) => ptr->GetColorKeys(allocator);              public GradientAlphaKey GetAlphaKey(int index) => ptr->GetAlphaKey(index);              public NativeArray&lt;GradientAlphaKey> GetAlphaKeys(Allocator allocator) => ptr->GetAlphaKeys(allocator);              public float4 Evaluate(float time)=> ptr->Evaluate(time);   } }<\/code><\/pre>\n<p>\u0418 \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"cs\">public static unsafe GradientStruct.ReadOnly DirectAccessReadOnly(this Gradient gradient) {     return GradientStruct.AsReadOnly(gradient.DirectAccess()); }<\/code><\/pre>\n<p>\u042d\u0442\u0443 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u043b\u044e\u0431\u043e\u0435 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u0435 \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u0434\u0435-\u0442\u043e \u0435\u0449\u0451 \u043d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u0432\u0441\u0435\u0439 \u0436\u0438\u0437\u043d\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"cs\">var gradientReadOnly = gradient.DirectAccessReadOnly(); var colorKeys = gradientReadOnly.GetColorKeys(Allocator.Temp); var alphaKeys = gradientReadOnly.GetAlphaKeys(Allocator.Temp); var color = gradientReadOnly.Evaluate(0.6f); colorKeys.Dispose(); alphaKeys.Dispose();<\/code><\/pre>\n<h2>\u0422\u0435\u0441\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/h2>\n<p>\u0414\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 AVX2. \u0414\u0430\u043d\u043d\u044b\u043c \u0442\u0435\u0441\u0442\u043e\u043c \u044f \u043d\u0435 \u0441\u0442\u0430\u0432\u0438\u043b \u0446\u0435\u043b\u044c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b. \u041d\u043e \u0442\u0435\u043d\u0434\u0435\u043d\u0446\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043f\u043e\u043d\u044f\u0442\u043d\u0430. \u0421\u0443\u0442\u044c \u0442\u0435\u0441\u0442\u0430: \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u043e \u0442\u044b\u0441\u044f\u0447 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u0446\u0432\u0435\u0442 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 Evaluate. \u0412\u043e \u0432\u0441\u0435\u0445 \u0440\u0435\u0436\u0438\u043c\u0430\u0445 \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u0438 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043e\u0442\u0440\u044b\u0432\u043e\u043c \u043b\u0438\u0434\u0438\u0440\u0443\u0435\u0442 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f. \u041e\u0433\u0440\u043e\u043c\u043d\u044b\u0439 overhead \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 c++ \u043c\u0435\u0442\u043e\u0434\u0430 \u0438\u0437 c# \u0434\u0430\u0451\u0442 \u043e \u0441\u0435\u0431\u0435 \u0437\u043d\u0430\u0442\u044c.<\/p>\n<pre><code class=\"cs\">public class PerformanceTest : MonoBehaviour {     public Gradient gradient = new Gradient();          [BurstCompile(OptimizeFor = OptimizeFor.Performance)]     private unsafe struct GradientBurstJob : IJob     {         public NativeArray&lt;float4> result;         [NativeDisableUnsafePtrRestriction] public GradientStruct* gradient;                  public void Execute()         {             var time = 1f;             var color = float4.zero;                          for (var i = 0; i &lt; 100000; i++)             {                 time *= 0.9999f;                 color += gradient->Evaluate(time);             }             result[0] = color;         }     }          private unsafe void Update()     {         var nativeArrayResult = new NativeArray&lt;float4>(1, Allocator.TempJob);         var job = new GradientBurstJob         {             result = nativeArrayResult,             gradient = gradient.DirectAccess()         };         var jobHandle = job.ScheduleByRef();         JobHandle.ScheduleBatchedJobs();                  Profiler.BeginSample(\"NativeGradient\");         var time = 1f;         var result = new Color(0, 0, 0, 0);                  for (var i = 0; i &lt; 100000; i++)         {             time *= 0.9999f;             result += gradient.Evaluate(time);         }         Profiler.EndSample();                  jobHandle.Complete();         nativeArrayResult.Dispose();     } }<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/39b\/688\/a7e\/39b688a7e22b27f6047f710e95227891.png\" alt=\"\u0420\u0435\u0436\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u0438 Fixed.\" title=\"\u0420\u0435\u0436\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u0438 Fixed.\" width=\"952\" height=\"464\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/39b\/688\/a7e\/39b688a7e22b27f6047f710e95227891.png\"\/><\/p>\n<div><figcaption>\u0420\u0435\u0436\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u0438 Fixed.<\/figcaption><\/div>\n<\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/957\/431\/9bd\/9574319bd09e6911cef405179084517c.png\" alt=\"\u0420\u0435\u0436\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u0438 Blend.\" title=\"\u0420\u0435\u0436\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u0438 Blend.\" width=\"694\" height=\"447\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/957\/431\/9bd\/9574319bd09e6911cef405179084517c.png\"\/><\/p>\n<div><figcaption>\u0420\u0435\u0436\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u0438 Blend.<\/figcaption><\/div>\n<\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/81a\/25e\/d72\/81a25ed727522df3a8655942c6508603.png\" alt=\"\u0420\u0435\u0436\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u0438 PerceptualBlend.\" title=\"\u0420\u0435\u0436\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u0438 PerceptualBlend.\" width=\"1070\" height=\"450\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/81a\/25e\/d72\/81a25ed727522df3a8655942c6508603.png\"\/><\/p>\n<div><figcaption>\u0420\u0435\u0436\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u044f\u0446\u0438\u0438 PerceptualBlend.<\/figcaption><\/div>\n<\/figure>\n<h2>\u0418\u0442\u043e\u0433<\/h2>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0445 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0439 \u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u043f\u0440\u044f\u043c\u043e\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u044f c++ \u0447\u0430\u0441\u0442\u0438 \u0434\u0432\u0438\u0436\u043a\u0430. \u041e\u0442\u043f\u0440\u0430\u0432\u0438\u043b \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u044d\u0442\u0443 \u043f\u0430\u043c\u044f\u0442\u044c \u0432 Job system \u0438 \u0441\u043c\u043e\u0433 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432\u0448\u0438\u0441\u044c \u0432\u0441\u0435\u043c\u0438 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430\u043c\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 burst.<\/p>\n<h2>\u0421\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c<\/h2>\n<p>\u0420\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u0430 \u0432\u043e \u0432\u0441\u0435\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 Unity \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 2020.3 \u0438 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044f 2023.2. 0a19.\u0421\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0432 Unity \u043d\u0435 \u0440\u0435\u0448\u0430\u0442 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u0444\u0438\u0447\u0438 \u0434\u043b\u044f \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430. \u0417\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0433\u043e\u0434\u044b \u0442\u0430\u043a\u043e\u0435 \u0441\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043b\u0438\u0448\u044c \u0435\u0434\u0438\u043d\u043e\u0436\u0434\u044b \u0432 \u0432\u0435\u0440\u0441\u0438\u0438 2022.2. \u041d\u043e \u044f \u043d\u0430\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e, \u043f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u044d\u0442\u0438\u043c \u043a\u043e\u0434\u043e\u043c \u0432 \u043d\u0435\u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u0435\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u043e\u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438.<\/p>\n<h2>\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043f\u043e\u043b\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e<\/h2>\n<p>\u041a\u0430\u043a \u0438 \u043e\u0431\u0435\u0449\u0430\u043b <a href=\"https:\/\/gist.github.com\/viruseg\/791789d63775d26a79ca32c0f5d31114\" rel=\"noopener noreferrer nofollow\"><u>\u0432\u043e\u0442 \u0441\u0441\u044b\u043b\u043a\u0430 <\/u><\/a>\u043d\u0430 \u043f\u043e\u043b\u043d\u044b\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/761572\/\"> https:\/\/habr.com\/ru\/articles\/761572\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 Unity \u0435\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441 Gradient, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043e\u043c \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435 \u0438 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\u0435. \u041d\u043e \u0442.\u043a. \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441, \u0430 \u043d\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0447\u0435\u0440\u0435\u0437 Job system \u0438 burst \u043d\u0435\u043b\u044c\u0437\u044f. \u042d\u0442\u043e \u043f\u0435\u0440\u0432\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430. \u0412\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u2014 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430. \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u043c\u0430\u0441\u0441\u0438\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0432 \u043a\u0443\u0447\u0435. \u0418 \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0435 \u043d\u0430\u043f\u0440\u044f\u0433\u0430\u0435\u0442 \u0441\u0431\u043e\u0440\u0449\u0438\u043a \u043c\u0443\u0441\u043e\u0440\u0430.<\/p>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b. \u0418 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0431\u043e\u043d\u0443\u0441\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u043e 8 \u0440\u0430\u0437 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 Evaluate \u0447\u0435\u0440\u0435\u0437 burst.<\/p>\n<figure class=\"\"><\/figure>\n<h2>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u044f\u043c\u043e\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430. \u042d\u0442\u043e\u0442 \u0430\u0434\u0440\u0435\u0441 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u043c \u043d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u0432\u0441\u0435\u0439 \u0436\u0438\u0437\u043d\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u041f\u043e\u043b\u0443\u0447\u0438\u0432 \u0435\u0433\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043f\u0440\u044f\u043c\u044b\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430, \u043d\u0435 \u043f\u0435\u0440\u0435\u0436\u0438\u0432\u0430\u044f \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0430\u0434\u0440\u0435\u0441 \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c\u0441\u044f.<\/p>\n<figure class=\"\">\n<div><figcaption>m_Ptr \u2013 \u0430\u0434\u0440\u0435\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u043e\u0439 \u0434\u043b\u044f c++ \u0447\u0430\u0441\u0442\u0438 \u0434\u0432\u0438\u0436\u043a\u0430.<\/figcaption><\/div>\n<\/figure>\n<p>\u0412\u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0430\u0434\u0440\u0435\u0441, \u043d\u0435 \u043f\u0440\u0438\u0431\u0435\u0433\u0430\u044f \u043a \u0440\u0435\u0444\u043b\u0435\u043a\u0441\u0438\u0438 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435. \u0418\u0437 \u043c\u0438\u043d\u0443\u0441\u043e\u0432, \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043a\u0440\u0435\u043f\u0438\u0442\u044c. \u0418\u0437 \u043f\u043b\u044e\u0441\u043e\u0432 \u0430\u0434\u0440\u0435\u0441 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0440\u0435\u043c\u044f, \u0437\u0430\u0442\u0440\u0430\u0447\u0435\u043d\u043d\u043e\u0435 \u043d\u0430 \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0435 \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u043e.<\/p>\n<pre><code class=\"cs\">public static class GradientExt {     private static readonly int m_PtrOffset;          static GradientExt()     {         var m_PtrMember = typeof(Gradient).GetField(\"m_Ptr\", BindingFlags.Instance | BindingFlags.NonPublic         m_PtrOffset = UnsafeUtility.GetFieldOffset(m_PtrMember);     }          public static unsafe IntPtr Ptr(this Gradient gradient)     {         var ptr = (byte*) UnsafeUtility.PinGCObjectAndGetAddress(gradient, out var handle);         var gradientPtr = *(IntPtr*) (ptr + m_PtrOffset);         UnsafeUtility.ReleaseGCObject(handle);         return gradientPtr;     } }<\/code><\/pre>\n<p>UnsafeUtility.GetFieldOffset \u2013 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438\u043b\u0438 \u043a\u043b\u0430\u0441\u0441\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043d\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f.<\/p>\n<p>UnsafeUtility.PinGCObjectAndGetAddress \u2013 \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u044f\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442. \u0418 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0430\u0434\u0440\u0435\u0441 \u0443\u0447\u0430\u0441\u0442\u043a\u0430 \u043f\u0430\u043c\u044f\u0442\u0438, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442.<\/p>\n<p>UnsafeUtility.ReleaseGCObject \u2013 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u0442 \u0445\u044d\u043d\u0434\u043b \u043e\u0431\u044a\u0435\u043a\u0442\u0430 GC, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0440\u0430\u043d\u0435\u0435.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0430\u0434\u0440\u0435\u0441 \u043d\u0430 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043f\u0430\u043c\u044f\u0442\u0438, \u0433\u0434\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430.<\/p>\n<pre><code class=\"cs\">public Gradient gradient; .... IntPtr gradientPtr = gradient.Ptr();<\/code><\/pre>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043d\u0443\u0436\u043d\u043e \u043d\u0435\u043c\u043d\u043e\u0436\u043a\u043e \u043f\u043e\u043a\u043e\u0432\u044b\u0440\u044f\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u0434\u0430\u043d\u043d\u044b\u0435 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u044f \u0432\u044b\u0432\u0435\u0434\u0443 \u0432 \u0438\u043d\u0441\u043f\u0435\u043a\u0442\u043e\u0440 Unity \u044d\u0442\u043e\u0442 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430. \u0417\u0430\u0442\u0435\u043c \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442 \u0438 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u0430\u043a\u0438\u0435 \u0438\u043c\u0435\u043d\u043d\u043e \u0443\u0447\u0430\u0441\u0442\u043a\u0438 \u044d\u0442\u043e \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u0435\u0442.<\/p>\n<pre><code class=\"cs\">[ExecuteAlways] public class MemoryResearch : MonoBehaviour {     public Gradient gradient = new Gradient();     public float[] gradientMemoryLocation = new float[50];     private static unsafe void CopyMemory&lt;T>(Gradient gradient, T[] gradientMemoryLocation) where T : unmanaged     {         IntPtr gradientPtr = gradient.Ptr();         fixed (T* gradientMemoryLocationPtr = gradientMemoryLocation)             UnsafeUtility.MemCpy(gradientMemoryLocationPtr, (void*) gradientPtr, gradientMemoryLocation.Length);     }          private void Update()     {         CopyMemory(gradient, gradientMemoryLocation);     } }<\/code><\/pre>\n<p>UnsafeUtility.MemCpy \u2013 \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0430\u0439\u0442 \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u0434\u0440\u0443\u0433\u0443\u044e.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u0414\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0446\u0432\u0435\u0442\u0430.<\/figcaption><\/div>\n<\/figure>\n<p>\u041f\u0443\u0442\u0451\u043c \u043d\u0435\u0445\u0438\u0442\u0440\u044b\u0445 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0439 \u0438 \u0441\u043c\u0435\u043d\u044b \u0442\u0438\u043f\u0430 \u043f\u0430\u043c\u044f\u0442\u0438 float\/ushort\/byte \u0438 \u0442.\u0434. \u044f \u043d\u0430\u0448\u0451\u043b \u043f\u043e\u043b\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0443 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0434\u043b\u044f Unity 22.3, \u043d\u043e \u0435\u0441\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u044f \u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0432\u0435\u0440\u0441\u0438\u0439. \u0421 \u043f\u043e\u043b\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 \u043a\u043e\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<pre><code class=\"cs\">\/\/\u041f\u043e\u0437\u0438\u0446\u0438\u0438 \u043a\u043b\u044e\u0447\u0435\u0439 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u043a\u0430\u043a ushort \u0433\u0434\u0435 0 = 0%, \u0430 65535 = 100%. public unsafe struct GradientStruct {     private fixed byte colors[sizeof(float) * 4 * 8]; \/\/8 rgba \u0446\u0432\u0435\u0442\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 (128 \u0431\u0430\u0439\u0442)     private fixed byte colorTimes[sizeof(ushort) * 8]; \/\/\u0432\u0440\u0435\u043c\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 (16 \u0431\u0430\u0439\u0442)     private fixed byte alphaTimes[sizeof(ushort) * 8]; \/\/\u0432\u0440\u0435\u043c\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0430\u043b\u044c\u0444\u0430 \u043a\u043b\u044e\u0447\u0430 (16 \u0431\u0430\u0439\u0442)     private byte colorCount; \/\/\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0446\u0432\u0435\u0442\u043e\u0432\u044b\u0445 \u043a\u043b\u044e\u0447\u0435\u0439     private byte alphaCount; \/\/\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u043b\u044c\u0444\u0430 \u043a\u043b\u044e\u0447\u0435\u0439     private byte mode; \/\/\u0440\u0435\u0436\u0438\u043c \u0441\u043c\u0435\u0448\u0438\u0432\u0430\u043d\u0438\u044f \u0446\u0432\u0435\u0442\u043e\u0432     private byte colorSpace; \/\/\u0446\u0432\u0435\u0442\u043e\u0432\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e }<\/code><\/pre>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 GradientStruct:<\/p>\n<pre><code class=\"cs\">public static unsafe GradientStruct* DirectAccess(this Gradient gradient) {     return (GradientStruct*) gradient.Ptr(); }<\/code><\/pre>\n<h2>Gradient.colorKeys \u0447\u0435\u0440\u0435\u0437 NativeArray<\/h2>\n<p>\u0417\u043d\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0430\u043c\u044f\u0442\u0438 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Gradient.colorKeys \u0438 Gradient.alphaKeys \u0447\u0435\u0440\u0435\u0437 NativeArray.<\/p>\n<pre><code class=\"cs\">private float4* Colors(int index) {     fixed(byte* colorsPtr = colors) return (float4*) colorsPtr + index; }  private ushort* ColorsTimes(int index) {     fixed(byte* colorTimesPtr = colorTimes) return (ushort*) colorTimesPtr + index; }  private ushort* AlphaTimes(int index) {     fixed(byte* alphaTimesPtr = alphaTimes) return (ushort*) alphaTimesPtr + index; }  public void SetColorKey(int index, GradientColorKeyBurst value) {     #if ENABLE_UNITY_COLLECTIONS_CHECKS         if (index &lt; 0 || index > 7) IncorrectIndex();     #endif      Colors(index)->xyz = value.color.xyz;     *ColorsTimes(index) = (ushort) (65535 * value.time); }  public GradientColorKeyBurst GetColorKey(int index) {     #if ENABLE_UNITY_COLLECTIONS_CHECKS         if (index &lt; 0 || index > 7) IncorrectIndex();     #endif      return new GradientColorKeyBurst(*Colors(index), *ColorsTimes(index) \/ 65535f); }  public void SetColorKeys(NativeArray&lt;GradientColorKeyBurst> colorKeys) {     #if ENABLE_UNITY_COLLECTIONS_CHECKS         if (colorKeys.Length &lt; 2 || colorKeys.Length > 8) IncorrectLength();     #endif      var colorKeysTmp = new NativeArray&lt;GradientColorKeyBurst>(colorKeys, Allocator.Temp);     colorKeysTmp.Sort&lt;GradientColorKeyBurst, GradientColorKeyBurstComparer>(default);      colorCount = (byte) colorKeys.Length;          for (var i = 0; i &lt; colorCount; i++)     {         SetColorKey(i, colorKeysTmp[i]);     }      colorKeysTmp.Dispose(); }  public void SetColorKeysWithoutSort(NativeArray&lt;GradientColorKeyBurst> colorKeys) {     #if ENABLE_UNITY_COLLECTIONS_CHECKS         if (colorKeys.Length &lt; 2 || colorKeys.Length > 8) IncorrectLength();     #endif      colorCount = (byte) colorKeys.Length;          for (var i = 0; i &lt; colorCount; i++)     {         SetColorKey(i, colorKeys[i]);     } }  public NativeArray&lt;GradientColorKeyBurst> GetColorKeys(Allocator allocator) {     var colorKeys = new NativeArray&lt;GradientColorKeyBurst>(colorCount, allocator);          for (var i = 0; i &lt; colorCount; i++)     {         colorKeys[i] = GetColorKey(i);     }      return colorKeys; }  public void SetAlphaKey(int index, GradientAlphaKey value) {     #if ENABLE_UNITY_COLLECTIONS_CHECKS         if (index &lt; 0 || index > 7) IncorrectIndex();     #endif      Colors(index)->w = value.alpha;     *AlphaTimes(index) = (ushort) (65535 * value.time); }  public GradientAlphaKey GetAlphaKey(int index) {     #if ENABLE_UNITY_COLLECTIONS_CHECKS         if (index &lt; 0 || index > 7) IncorrectIndex();     #endif      return new GradientAlphaKey(Colors(index)->w, *AlphaTimes(index) \/ 65535f); }  public void SetAlphaKeys(NativeArray&lt;GradientAlphaKey> alphaKeys) {     #if ENABLE_UNITY_COLLECTIONS_CHECKS         if (alphaKeys.Length &lt; 2 || alphaKeys.Length > 8) IncorrectLength();     #endif      var alphaKeysTmp = new NativeArray&lt;GradientAlphaKey>(alphaKeys, Allocator.Temp);     alphaKeysTmp.Sort&lt;GradientAlphaKey, GradientAlphaKeyComparer>(default);      alphaCount = (byte) alphaKeys.Length;          for (var i = 0; i &lt; alphaCount; i++)     {         SetAlphaKey(i, alphaKeys[i]);     }      alphaKeysTmp.Dispose(); }  public void SetAlphaKeysWithoutSort(NativeArray&lt;GradientAlphaKey> alphaKeys) {     #if ENABLE_UNITY_COLLECTIONS_CHECKS         if (alphaKeys.Length &lt; 2 || alphaKeys.Length > 8) IncorrectLength();     #endif      alphaCount = (byte) alphaKeys.Length;          for (var i = 0; i &lt; alphaCount; i++)     {         SetAlphaKey(i, alphaKeys[i]);     } }  public NativeArray&lt;GradientAlphaKey> GetAlphaKeys(Allocator allocator) {     var alphaKeys = new NativeArray&lt;GradientAlphaKey>(alphaCount, allocator);          for (var i = 0; i &lt; alphaCount; i++)     {         alphaKeys[i] = GetAlphaKey(i);     }      return alphaKeys; }  private struct GradientColorKeyBurstComparer : IComparer&lt;GradientColorKeyBurst> {     public int Compare(GradientColorKeyBurst v1, GradientColorKeyBurst v2)     {         return v1.time.CompareTo(v2.time);     } }  private struct GradientAlphaKeyComparer : IComparer&lt;GradientAlphaKey> {     public int Compare(GradientAlphaKey v1, GradientAlphaKey v2)     {         return v1.time.CompareTo(v2.time);     } }<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435<\/p>\n<pre><code class=\"cs\">var colorKeys = gradient.colorKeys; var alphaKeys = gradient.alphaKeys;<\/code><\/pre>\n<p>\u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0430<\/p>\n<pre><code class=\"cs\">var gradientPtr = gradient.DirectAccess(); var colorKeys = gradientPtr->GetColorKeys(Allocator.Temp); var alphaKeys = gradientPtr->GetAlphaKeys(Allocator.Temp);<\/code><\/pre>\n<p>\u0438 \u0437\u0430\u0431\u044b\u0442\u044c \u043e \u0441\u0431\u043e\u0440\u0449\u0438\u043a\u0435 \u043c\u0443\u0441\u043e\u0440\u0430 \u043f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439. \u0410 \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0432\u043d\u0443\u0442\u0440\u0438 Job system. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 gradient.DirectAccess() \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043a\u0435\u0448\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u0432\u0441\u0435\u0439 \u0436\u0438\u0437\u043d\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<h2>\u0424\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u043b\u044f Job system<\/h2>\n<p>\u041d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0432\u043e\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u0435\u0442\u043e\u0434\u0430 Evaluate, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u0434\u043e\u0441\u044f\u0433\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u0438\u0437 \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b. \u0412\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043d\u0435 \u0431\u0443\u0434\u0443. \u041e\u043d \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u0435\u043d \u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043a \u0442\u0435\u043c\u0435 \u0441\u0442\u0430\u0442\u044c\u0438.<\/p>\n<pre><code class=\"cs\">public float4 Evaluate(float time) {     float3 color = default;     var colorCalculated = false;     var colorKey = GetColorKeyBurst(0);     if (time &lt;= colorKey.time)     {         color = colorKey.color.xyz;         colorCalculated = true;     }          if (!colorCalculated)         for (var i = 0; i &lt; colorCount - 1; i++)         {             var colorKeyNext = GetColorKeyBurst(i + 1);                              if (time &lt;= colorKeyNext.time)             {                 if (Mode == GradientMode.Blend)                 {              <\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-355109","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/355109","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=355109"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/355109\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=355109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=355109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=355109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}