{"id":330877,"date":"2022-03-21T09:00:39","date_gmt":"2022-03-21T09:00:39","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=330877"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=330877","title":{"rendered":"<span>\u0414\u0435\u043b\u0430\u0435\u043c \u0442\u0440\u0430\u0432\u0443 \u0432 Unity \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 GPU Instancing<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c! \u0425\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u0432\u0430\u043c\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u043f\u044b\u0442\u043e\u043c \u043f\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c GPU Instancing.<\/p>\n<p>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u0430\u044f: \u0438\u0433\u0440\u0430 \u043f\u043e\u0434 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0435 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b, \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0435 \u0441 \u0442\u0440\u0430\u0432\u043e\u0439. \u0424\u043e\u0442\u043e\u0440\u0435\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f, low poly \u0441\u0442\u0438\u043b\u044c. \u041d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0438\u0433\u0440\u043e\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0442\u0440\u0430\u0432\u043e\u0439. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u044b\u043a\u0430\u0448\u0438\u0432\u0430\u0442\u044c. \u0414\u0435\u043b\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u043d\u0430 Unity 2021.2.7 (\u043d\u043e \u0436\u0435\u0441\u0442\u043a\u043e\u0439 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u043a \u0432\u0435\u0440\u0441\u0438\u0438 \u043d\u0435\u0442) \u0441 URP.<\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043d\u0430 \u0433\u0438\u0444\u043a\u0435.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/123\/3cd\/cdf\/1233cdcdf9f6507df06fa34953e34387.gif\" width=\"208\" height=\"208\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/123\/3cd\/cdf\/1233cdcdf9f6507df06fa34953e34387.gif\"\/><figcaption><\/figcaption><\/figure>\n<h2>\u041f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u0438\u044f<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0430\u0448\u0443 low poly \u0442\u0440\u0430\u0432\u0438\u043d\u043a\u0443. \u0422\u0430\u043a \u043a\u0430\u043a \u043a\u0430\u043c\u0435\u0440\u0430 \u0432 \u0438\u0433\u0440\u0435 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0432\u0430 \u0442\u0440\u0435\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a\u0430:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/9d4\/106\/696\/9d4106696759138ad5c497682c8b71ba.png\" width=\"233\" height=\"436\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9d4\/106\/696\/9d4106696759138ad5c497682c8b71ba.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412\u0440\u044f\u0434 \u043b\u0438 \u044d\u0442\u043e\u0442 \u043c\u0435\u0448 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u0442\u0440\u0430\u0432\u0443, \u0435\u0441\u043b\u0438 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u043e\u0445\u043e\u0436\u0435\u0435 \u043d\u0430 \u0432\u0435\u0442\u0435\u0440. \u0414\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0448\u0435\u0439\u0434\u0435\u0440\u043e\u043c \u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c UV, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e: \u043d\u0438\u0436\u043d\u0438\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432\u043d\u0438\u0437\u0443 \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u044b, \u0430 \u0432\u0435\u0440\u0445\u043d\u044f\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0432\u0435\u0440\u0445\u0443. \u041f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/fa7\/9f4\/752\/fa79f4752a090cb5b4d2948ab5118bf6.png\" width=\"85\" height=\"382\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fa7\/9f4\/752\/fa79f4752a090cb5b4d2948ab5118bf6.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0434\u0435\u043b\u0430\u0435\u043c Shader Subgraph, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043d\u0430\u0448\u0438\u0445 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0445 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u0445:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/349\/9a1\/63e\/3499a163e257308755c11780d1179460.png\" width=\"1680\" height=\"752\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/349\/9a1\/63e\/3499a163e257308755c11780d1179460.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0439. \u041d\u0430 \u0432\u0445\u043e\u0434 \u043f\u043e\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0437\u0430 \u0432\u0435\u0442\u0435\u0440 \u0438 \u043c\u0438\u0440\u043e\u0432\u0430\u044f \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u044b. \u0414\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0435\u0435 \u0441\u0434\u0432\u0438\u0433\u0430 \u0432\u0435\u0442\u0440\u043e\u043c \u043c\u044b \u043f\u0440\u043e\u0433\u043e\u043d\u044f\u0435\u043c \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0447\u0435\u0440\u0435\u0437 Simple Noise \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u0442\u0440\u0430\u0432\u0438\u043d\u043a\u0438 \u043d\u0430 \u0441\u0446\u0435\u043d\u0435 \u043a\u043e\u043b\u044b\u0445\u0430\u043b\u0438\u0441\u044c \u043d\u0435 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e. \u0418 \u0434\u0430\u043b\u0435\u0435 \u0447\u0435\u0440\u0435\u0437 UV \u0438 Lerp \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0442\u0440\u043e\u0432\u043e\u0439 \u0441\u0434\u0432\u0438\u0433 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d \u043a \u0434\u0430\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u0435.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0430\u0448\u0438 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u044b.<\/p>\n<p><strong>\u0422\u0430\u043a \u0436\u0435 \u0445\u043e\u0447\u0443 \u0441\u0440\u0430\u0437\u0443 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0447\u0442\u043e \u0432\u0441\u0435 \u0437\u0430\u043c\u0435\u0440\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u0435 \u0441\u0430\u043c\u043e\u043c \u0431\u044b\u0441\u0442\u0440\u043e\u043c Xiaomi Redmi 8A.<\/strong><\/p>\n<h2>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 &#171;\u0432 \u043b\u043e\u0431&#187;<\/h2>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0447\u0442\u043e-\u0442\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u0435\u0441\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u0441\u0435\u0431\u044f SRP Batcher \u043d\u0430 \u0442\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0440\u0430\u0432\u0438\u043d\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0443\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u043d\u0430\u0441 \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e.<\/p>\n<p>\u0421\u043f\u0435\u0440\u0432\u0430 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0439 \u0448\u0435\u0439\u0434\u0435\u0440:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/506\/df1\/0f3\/506df10f34f05c0cf1e0ed06c7afeba3.png\" width=\"1180\" height=\"960\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/506\/df1\/0f3\/506df10f34f05c0cf1e0ed06c7afeba3.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0435\u043c \u043a \u0437\u0430\u0441\u0435\u0432\u0443 \u043f\u043e\u043b\u044f\u043d\u044b:<\/p>\n<pre><code class=\"cs\">_startPosition = -_fieldSize \/ 2.0f; _cellSize = new Vector2(_fieldSize.x \/ GrassDensity, _fieldSize.y \/ GrassDensity);  var grassEntities = new Vector2[GrassDensity, GrassDensity]; var halfCellSize = _cellSize \/ 2.0f;  for (var i = 0; i &lt; grassEntities.GetLength(0); i++) {   for (var j = 0; j &lt; grassEntities.GetLength(1); j++) {     grassEntities[i, j] =     new Vector2(_cellSize.x * i + _startPosition.x, _cellSize.y * j + _startPosition.y)        + new Vector2(Random.Range(-halfCellSize.x, halfCellSize.x),     Random.Range(-halfCellSize.y, halfCellSize.y));   } } _abstractGrassDrawer.Init(grassEntities, _fieldSize);<\/code><\/pre>\n<p>\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0435 \u043f\u043e\u043b\u0435 \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0434\u043e\u043b\u0435\u0439 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0441\u0442\u0438. \u041e\u043d\u043e \u0443 \u043d\u0430\u0441 \u043f\u043b\u043e\u0441\u043a\u043e\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 Vector2 \u0432\u043f\u043e\u043b\u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043b\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442. \u0414\u0430\u043b\u0435\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u044d\u0442\u043e\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442 \u043d\u0430 &#171;\u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0443&#187;. \u0421\u0435\u0439\u0447\u0430\u0441 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0430\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 GameObject \u0432 \u043d\u0443\u0436\u043d\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435.<\/p>\n<pre><code class=\"cs\">public override void Init(Vector2[,] grassEntities, Vector2 fieldSize) {   _grassEntities = new GameObject[grassEntities.GetLength(0), grassEntities.GetLength(1)];   for (var i = 0; i &lt; grassEntities.GetLength(0); i++) {     for (var j = 0; j &lt; grassEntities.GetLength(1); j++) {       _grassEntities[i, j] = Instantiate(_grassPrefab,       new Vector3(grassEntities[i, j].x, 0.0f, grassEntities[i, j].y), Quaternion.identity);     }   } }<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u0430\u043a\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/1bf\/7bb\/261\/1bf7bb26185687301ec402e1f5a4fddd.jpg\" width=\"720\" height=\"595\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1bf\/7bb\/261\/1bf7bb26185687301ec402e1f5a4fddd.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e \u043c\u044b \u0434\u043e\u0441\u0442\u0438\u0433\u043b\u0438 \u0436\u0435\u043b\u0430\u0435\u043c\u043e\u0433\u043e (\u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u0433\u0440\u0435 \u0434\u0440\u0443\u0433\u043e\u0439 \u0440\u0430\u043a\u0443\u0440\u0441 \u043a\u0430\u043c\u0435\u0440\u044b, \u0435\u0441\u0442\u044c \u0434\u0435\u043a\u043e\u0440, \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0430 \u0437\u0435\u043c\u043b\u0438 \u0438 \u043f\u0440\u043e\u0447\u0435\u0435, \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u0441\u0430\u043c\u0430 \u0442\u0440\u0430\u0432\u0430 \u0437\u0430\u0441\u0435\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043d\u0443\u0436\u043d\u044b\u0445 \u043e\u0431\u043b\u0430\u0441\u0442\u044f\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u043e\u043b\u0443\u0447\u0448\u0435, \u043d\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u0440\u0430\u0432\u0438\u043d\u043e\u043a \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442: 15-20\u043a). \u041d\u043e \u0432\u043e\u0442 fps \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043f\u043e\u0434\u0432\u043e\u0434\u0438\u0442. \u0417\u043d\u0430\u0447\u0438\u0442 \u043c\u043e\u0436\u043d\u043e \u0434\u0443\u043c\u0430\u0442\u044c \u043e\u0431 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<h2>GPU Instancing<\/h2>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u044f <a href=\"https:\/\/docs.unity3d.com\/2021.2\/Documentation\/Manual\/GPUInstancing.html\" rel=\"noopener noreferrer nofollow\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a> \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u044d\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0438\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p>\u0412 \u0438\u043d\u0441\u043f\u0435\u043a\u0442\u043e\u0440\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u043d\u0430\u0448\u0435\u0439 \u0442\u0440\u0430\u0432\u044b \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0433\u0430\u043b\u043e\u0447\u043a\u0443 &#171;Enable GPU Instancing&#187; \u0438 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0435\u0435. \u041d\u043e, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, <a href=\"https:\/\/forum.unity.com\/threads\/srp-batcher-and-gpu-instancing.833362\/\" rel=\"noopener noreferrer nofollow\">\u0432\u0441\u0435 \u043d\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e<\/a>. \u0415\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0441\u0446\u0435\u043d\u0443 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 Frame Debugger, \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 SRP Batcher, \u043d\u043e \u043d\u0435 GPU Instancing. \u0412\u0441\u0435 \u0434\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u0438 \u0434\u0432\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043a\u0430\u043a-\u0442\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c SRP Batcher. \u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e.<\/p>\n<h4>1. \u0412\u044b\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445 URP<\/h4>\n<p>\u042d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u0432\u0440\u044f\u0434 \u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u043c. \u041d\u0435 \u0437\u0440\u044f \u0432 \u0441\u0432\u0435\u0436\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 Unity \u044d\u0442\u0443 \u0433\u0430\u043b\u043e\u0447\u043a\u0443 \u0443\u0431\u0440\u0430\u043b\u0438 \u0438\u0437 \u0438\u043d\u0441\u043f\u0435\u043a\u0442\u043e\u0440\u0430. \u041d\u043e \u043d\u0430\u0439\u0442\u0438 \u0435\u0435 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u0447\u0435\u0440\u0435\u0437 Debug \u0440\u0435\u0436\u0438\u043c \u0438\u043d\u0441\u043f\u0435\u043a\u0442\u043e\u0440\u0430 \u0432\u0430\u0448\u0435\u0433\u043e URP \u0430\u0441\u0441\u0435\u0442\u0430. \u041d\u0430\u043c \u044d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043a\u0440\u043e\u043c\u0435 \u0442\u0440\u0430\u0432\u044b \u0432 \u0438\u0433\u0440\u0435 \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u0438\u0445 \u0432\u0435\u0449\u0435\u0439, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 SRP Batcher \u043d\u0430\u0441 \u0443\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442.<\/p>\n<h4>2. \u0421\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u043c \u0448\u0435\u0439\u0434\u0435\u0440<\/h4>\n<p>\u0421\u043f\u043e\u0441\u043e\u0431 \u043d\u0435 \u0441\u0430\u043c\u044b\u0439 \u0443\u0434\u043e\u0431\u043d\u044b\u0439, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e <a href=\"https:\/\/docs.unity3d.com\/Manual\/SRPBatcher.html#intentionally-removing-compatibility\" rel=\"noopener noreferrer nofollow\">\u043e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0430\u043c \u0448\u0435\u0439\u0434\u0435\u0440<\/a>. \u0410 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 Shader Graph \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0435\u0449\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0448\u0435\u0439\u0434\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0442\u043e\u043c \u043e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0418 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0433\u0440\u0430\u0444\u0430 \u044d\u0442\u0443 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c. \u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438: &#171;<em>Add a new\u00a0<\/em><a href=\"https:\/\/docs.unity3d.com\/Manual\/SL-Properties.html\" rel=\"noopener noreferrer nofollow\"><em>material property<\/em><\/a><em>\u00a0declaration into the shader\u2019s\u00a0<\/em><code>Properties<\/code>\u00a0block. Don\u2019t declare the new material property in the\u00a0<code>UnityPerMaterial<\/code>\u00a0constant buffer&#187;. \u041f\u043e\u0447\u0435\u043c\u0443-\u0442\u043e \u0432 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u0438 \u0448\u0435\u0439\u0434\u0435\u0440 \u043e\u0441\u0442\u0430\u0432\u0430\u043b\u0441\u044f SRP compatible, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0431\u0443\u0444\u0435\u0440\u0430:<\/p>\n<pre><code>\/\/CBUFFER_START(UnityPerMaterial) float4 _MainTexture_TexelSize; half _WindShiftStrength; half _WindSpeed; half _WindStrength; \/\/CBUFFER_END<\/code><\/pre>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u043d\u0435\u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u044d\u0442\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430, \u044f \u0432\u044b\u0431\u0440\u0430\u043b \u0438\u043c\u0435\u043d\u043d\u043e \u0435\u0433\u043e. \u041f\u0440\u043e\u0441\u0442\u043e \u0447\u0442\u043e\u0431\u044b \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0441\u0430\u043c\u0438 \u043f\u0440\u0435\u0444\u0430\u0431\u044b \u043e\u0441\u0442\u0430\u0432\u0430\u043b\u0438\u0441\u044c \u0442\u0435\u043c\u0438 \u0436\u0435, \u0447\u0442\u043e \u0438 \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0435.\u00a0<\/p>\n<h4>3. \u0421\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u043c \u0440\u0435\u043d\u0434\u0435\u0440\u0435\u0440<\/h4>\n<p>\u041f\u043e\u0436\u0430\u043b\u0443\u0439, \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435 \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0448\u0435\u0439\u0434\u0435\u0440 \u0441 SRP Batcher \u0438 \u0441 GPU Instancing. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0438\u0442\u044c \u0440\u0435\u043d\u0434\u0435\u0440\u0435\u0440\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/MaterialPropertyBlock.html\" rel=\"noopener noreferrer nofollow\">MaterialPropertyBlock<\/a>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d <a href=\"https:\/\/forum.unity.com\/threads\/materialpropertyblock-and-srp-batcher.815499\/\" rel=\"noopener noreferrer nofollow\">\u043d\u0435 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c \u0441 SRP Batcher<\/a>. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435 MaterialPropertyBlock \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043f\u043e\u043b\u044c\u0437\u0443. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u044b\u0445\u0430\u043d\u0438\u0435 \u0442\u0440\u0430\u0432\u044b \u043d\u0435 \u0447\u0435\u0440\u0435\u0437 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u0448\u0443\u043c, \u0430 \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0441\u0432\u043e\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c. \u041b\u0438\u0431\u043e \u0440\u0430\u0441\u043a\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u0442\u0440\u0430\u0432\u0443 \u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u043d\u0435\u0435.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043b\u044e\u0431\u043e\u0439 \u0438\u0437 \u044d\u0442\u0438\u0445 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0439, \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0438\u043d\u0433 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0f0\/764\/c27\/0f0764c27297de07328bc10d4033f512.png\" width=\"448\" height=\"322\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0f0\/764\/c27\/0f0764c27297de07328bc10d4033f512.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u043c\u0435\u0440\u044b:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/c55\/84f\/b32\/c5584fb326821e9bec89dee08d7274b3.jpg\" width=\"720\" height=\"466\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c55\/84f\/b32\/c5584fb326821e9bec89dee08d7274b3.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<h2>Graphics API<\/h2>\n<p>\u041e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0448 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c GPU Instancing \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0447\u0435\u0440\u0435\u0437 Graphics API, \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f GameObject. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 3 \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<p><strong>1. <\/strong><a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/Graphics.DrawMeshInstanced.html\" rel=\"noopener noreferrer nofollow\"><strong>Graphics.DrawMeshInstanced<\/strong><\/a><\/p>\n<p>\u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431. \u041f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043c\u0435\u0448, \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u043c\u0430\u0442\u0440\u0438\u0446. \u041d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0448\u0435\u0439\u0434\u0435\u0440\u0430, \u043d\u043e \u0438\u043c\u0435\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0432 1023 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430 \u0437\u0430 \u043e\u0434\u0438\u043d \u0432\u044b\u0437\u043e\u0432. \u041c\u0430\u043b\u043e\u0432\u0430\u0442\u043e \u0431\u0443\u0434\u0435\u0442.<\/p>\n<p><strong>2. <\/strong><a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/Graphics.DrawMeshInstancedIndirect.html\" rel=\"noopener noreferrer nofollow\"><strong>Graphics.DrawMeshInstancedIndirect<\/strong><\/a><\/p>\n<p>\u041d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 ComputeBuffer. \u041d\u043e \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0443\u0436\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u0443\u0444\u0435\u0440\u043e\u043c \u0432 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b. \u0427\u0442\u043e \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0448\u0435\u0439\u0434\u0435\u0440\u0430.<\/p>\n<p><strong>3. <\/strong><a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/Graphics.DrawMeshInstancedProcedural.html\" rel=\"noopener noreferrer nofollow\"><strong>Graphics.DrawMeshInstancedProcedural<\/strong><\/a><\/p>\n<p>\u0421\u0445\u043e\u0436 \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u043e\u0432 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u0438\u0437 \u0441\u043a\u0440\u0438\u043f\u0442\u0430. \u041d\u0430 \u043d\u0435\u043c \u043c\u044b \u0438 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c\u0441\u044f.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043d\u0430\u0448\u0438\u0445 \u0442\u0440\u0430\u0432\u0438\u043d\u043e\u043a \u0432 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b:<\/p>\n<pre><code class=\"cs\">_positionsCount = _positions.Count; _positionBuffer?.Release(); if (_positionsCount == 0) return; _positionBuffer = new ComputeBuffer(_positionsCount, 8); _positionBuffer.SetData(_positions); _instanceMaterial.SetBuffer(PositionsShaderProperty, _positionBuffer);<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0441\u0430\u043c\u0430 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u0430\u0434\u0440:<\/p>\n<pre><code class=\"cs\">private void Update() {   if (_positionsCount == 0) return;   Graphics.DrawMeshInstancedProcedural(_instanceMesh, 0, _instanceMaterial,   _grassBounds, _positionsCount,   null, ShadowCastingMode.Off, false); }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u043f\u0440\u0435\u0436\u043d\u0438\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b, \u0442\u043e \u0432\u0441\u0435 \u0442\u044b\u0441\u044f\u0447\u0438 \u0442\u0440\u0430\u0432\u0438\u043d\u043e\u043a \u0431\u0443\u0434\u0443\u0442 \u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0430\u0448 \u0448\u0435\u0439\u0434\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u0442\u0435\u043f\u0435\u0440\u044c \u0431\u0440\u0430\u0442\u044c \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0438\u0437 \u0431\u0443\u0444\u0435\u0440\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c \u0448\u0435\u0439\u0434\u0435\u0440:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/642\/fb2\/d43\/642fb2d43a183f7e6f970d6b3b0f6f7f.png\" width=\"1680\" height=\"1430\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/642\/fb2\/d43\/642fb2d43a183f7e6f970d6b3b0f6f7f.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0434\u0432\u0435 \u043d\u043e\u0434\u044b \u0441 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438.<\/p>\n<p>\u00a0\u041f\u0435\u0440\u0432\u0430\u044f \u043d\u0443\u0436\u043d\u0430 \u043d\u0430\u043c \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f unity_InstanceID, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430 \u0438\u0437 \u0431\u0443\u0444\u0435\u0440\u0430. \u0421\u0430\u043c\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u043d\u0430\u0439\u0434\u0435\u043d\u043e <a href=\"https:\/\/forum.unity.com\/threads\/using-instanced-or-indirect-properties-in-a-vertex-shader.536542\/\" rel=\"noopener noreferrer nofollow\">\u0433\u0434\u0435-\u0442\u043e \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430\u0445<\/a> \u0438 \u043f\u043e\u043b\u043d\u043e\u0435 \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0434\u0430\u0442\u044c \u043d\u0435 \u043c\u043e\u0433\u0443. \u0411\u0443\u0434\u0443 \u043f\u0440\u0438\u0437\u043d\u0430\u0442\u0435\u043b\u0435\u043d \u0437\u0430 \u0441\u0441\u044b\u043b\u043a\u0438 \u0441 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<pre><code>#pragma instancing_options procedural:ConfigureProcedural Out = In;<\/code><\/pre>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f &#8212; \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0438\u0437 \u0431\u0443\u0444\u0435\u0440\u0430.<\/p>\n<pre><code>#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED) StructuredBuffer&lt;float2> PositionsBuffer; #endif  float2 position;  void ConfigureProcedural () { #if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED) position = PositionsBuffer[unity_InstanceID]; #endif }  void ShaderGraphFunction_float (out float2 PositionOut) { PositionOut = position; }  void ShaderGraphFunction_half (out half2 PositionOut) { PositionOut = position; }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u043c\u0435\u0440\u044b:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/392\/947\/749\/392947749b6bc928f05d5ad43c07275f.jpg\" width=\"720\" height=\"462\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/392\/947\/749\/392947749b6bc928f05d5ad43c07275f.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0440\u043e\u043c\u0435 \u043d\u0435\u043f\u043b\u043e\u0445\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Compute Shader \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u0431\u0443\u0444\u0435\u0440\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043b\u0435\u0442\u0430\u044e\u0449\u0435\u0439 \u043f\u043e \u0441\u0446\u0435\u043d\u0435 \u0442\u0440\u0430\u0432\u044b \u0438\u0437 C# \u0432 \u0448\u0435\u0439\u0434\u0435\u0440. <a href=\"https:\/\/www.ronja-tutorials.com\/post\/051-draw-procedural\/\" rel=\"noopener noreferrer nofollow\">\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a<\/a>.<\/p>\n<h2>\u0415\u0449\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438<\/h2>\n<p>\u041a\u0430\u043c\u0435\u0440\u0430 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0438\u0433\u0440\u0435 \u043d\u0435 \u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f, \u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u0432\u0434\u043e\u043b\u044c \u043e\u0441\u0438 Z. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043b\u0435\u0433\u043a\u043e\u0435 \u043f\u043e\u0434\u043e\u0431\u0438\u0435 \u043a\u0443\u043b\u0438\u043d\u0433\u0430. \u0422\u0430\u043a \u043a\u0430\u043a \u0442\u0440\u0430\u0432\u0443 \u043c\u044b \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u043b\u0438 \u043f\u043e \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0439 \u0441\u0435\u0442\u043a\u0435, \u0442\u043e \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u0430\u043a\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0442\u0440\u0430\u0432\u0438\u043d\u043e\u043a \u043d\u0430\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442.<\/p>\n<p>\u0412 \u043a\u043b\u0430\u0441\u0441\u0435 \u043d\u0430\u0448\u0435\u0439 \u043f\u043e\u043b\u044f\u043d\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u043a\u0430\u043c\u0435\u0440\u043e\u0439 \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u0433\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<pre><code class=\"cs\">private void Update() { if (_camera.transform.hasChanged) { UpdateCameraCells(); } }  private Vector3 Raycast(Vector3 position) { var ray = _camera.ScreenPointToRay(position); _plane.Raycast(ray, out var enter); return ray.GetPoint(enter); }  private void UpdateCameraCells() { if (!PerformCulling) { _abstractGrassDrawer.UpdatePositions(Vector2Int.zero, new Vector2Int(GrassDensity, GrassDensity)); return; } var bottomLeftCameraCorner = Raycast(Vector3.zero); var topLeftCameraCorner = Raycast(new Vector3(0.0f, Screen.height)); var topRightCameraCorner = Raycast(new Vector3(Screen.width, Screen.height)); var bottomLeftCameraCell = new Vector2Int( Mathf.Clamp(Mathf.FloorToInt((topLeftCameraCorner.x - _startPosition.x) \/ _cellSize.x), 0, GrassDensity - 1), Mathf.Clamp(Mathf.FloorToInt((bottomLeftCameraCorner.z - _startPosition.y) \/ _cellSize.y), 0, GrassDensity - 1));  var topRightCameraCell = new Vector2Int( Mathf.Clamp(Mathf.FloorToInt((topRightCameraCorner.x - _startPosition.x) \/ _cellSize.x) + 1, 0, GrassDensity - 1), Mathf.Clamp(Mathf.FloorToInt((topRightCameraCorner.z - _startPosition.y) \/ _cellSize.y) + 1, 0, GrassDensity - 1)); _abstractGrassDrawer.UpdatePositions(bottomLeftCameraCell, topRightCameraCell); }<\/code><\/pre>\n<p>\u0412 instanced \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0431\u0443\u0444\u0435\u0440\u0430.<\/p>\n<pre><code class=\"cs\">public override void UpdatePositions(Vector2Int bottomLeftCameraCell, Vector2Int topRightCameraCell) { _positions.Clear(); for (var i = bottomLeftCameraCell.x; i &lt; topRightCameraCell.x; i++) { for (var j = bottomLeftCameraCell.y; j &lt; topRightCameraCell.y; j++) { _positions.Add(_grassEntities[i, j]); } }  _positionsCount = _positions.Count; _positionBuffer?.Release(); if (_positionsCount == 0) return; _positionBuffer = new ComputeBuffer(_positionsCount, 8); _positionBuffer.SetData(_positions); _instanceMaterial.SetBuffer(PositionsShaderProperty, _positionBuffer); }<\/code><\/pre>\n<p>\u0412 GameObject \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0435 \u0431\u0443\u0434\u0435\u043c \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c\/\u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0442\u0440\u0430\u0432\u044b.<\/p>\n<pre><code class=\"cs\">public override void UpdatePositions(Vector2Int bottomLeftCameraCell, Vector2Int topRightCameraCell) {   for (var i = 0; i &lt; _grassEntities.GetLength(0); i++) {     for (var j = 0; j &lt; _grassEntities.GetLength(1); j++) {       _grassEntities[i, j].SetActive(i >= bottomLeftCameraCell.x &amp;&amp; i &lt; topRightCameraCell.x &amp;&amp; j >= bottomLeftCameraCell.y &amp;&amp;       j &lt; topRightCameraCell.y);     }   } }<\/code><\/pre>\n<p>\u041d\u0443 \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u043c\u0435\u0440\u044b \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/513\/6a7\/fe2\/5136a7fe203b7decaf3fac35453a2194.jpg\" width=\"720\" height=\"277\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/513\/6a7\/fe2\/5136a7fe203b7decaf3fac35453a2194.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0410 \u0432\u043e\u0442 \u0442\u0430\u043a \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043d\u0430 \u043f\u0440\u0438\u0435\u043c\u043b\u0435\u043c\u044b\u0445 \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u0438\u0445 \u0438\u0433\u0440 ~30 fps.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/1f2\/851\/fd7\/1f2851fd713065c34d1b10a6051828b7.jpg\" width=\"719\" height=\"362\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1f2\/851\/fd7\/1f2851fd713065c34d1b10a6051828b7.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0437\u0430\u043c\u0435\u0442\u043d\u044b\u0439 \u0432\u044b\u0438\u0433\u0440\u044b\u0448 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0437\u0430 \u0441\u0447\u0435\u0442 \u043e\u0442\u043a\u0430\u0437\u0430 \u043e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f GameObject. \u0418 \u0447\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u043e\u0432 \u043c\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u043c, \u0442\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0431\u0443\u0434\u0435\u0442 \u044d\u0442\u0430 \u0440\u0430\u0437\u043d\u0438\u0446\u0430.<\/p>\n<h2>\u041f\u043e\u0434\u0432\u043e\u0434\u043d\u044b\u0435 \u043a\u0430\u043c\u043d\u0438<\/h2>\n<p>\u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0438\u043d\u0433 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435 \u043d\u0430 \u0432\u0441\u0435\u0445 \u0434\u0435\u0432\u0430\u0439\u0441\u0430\u0445. \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0447\u0435\u0440\u0435\u0437 <em>SystemInfo.supportsInstancing.\u00a0<\/em>\u0414\u043b\u044f \u044d\u0442\u0438\u0445 \u0434\u0435\u0432\u0430\u0439\u0441\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c fallback \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441\u043e \u0441\u0442\u0430\u0440\u044b\u043c\u0438 \u0434\u043e\u0431\u0440\u044b\u043c\u0438 GameObject, \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0432 \u0438\u0445 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e.<\/p>\n<p>\u0418 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u043b\u0438\u0441\u044c Samsung \u0441 \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c Galaxy A50. \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e <em>SystemInfo.supportsInstancing\u00a0<\/em>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 true (\u0447\u0442\u043e \u043f\u043e \u0432\u0441\u0435\u0439 \u0432\u0438\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0440\u0430\u0432\u0434\u0430, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u044d\u043a\u0441\u0435\u043f\u0448\u0435\u043d\u043e\u0432 \u043d\u0435\u0442), \u043d\u043e \u0447\u0442\u043e-\u0442\u043e \u0443 \u043d\u0438\u0445 \u043d\u0435 \u0442\u0430\u043a \u0441 \u0431\u0443\u0444\u0435\u0440\u043e\u043c. \u0412\u0441\u044f \u0442\u0440\u0430\u0432\u0430 \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u0434\u0435\u0432\u0430\u0439\u0441\u0435 \u0443\u043f\u043e\u0440\u043d\u043e \u0440\u0438\u0441\u0443\u0435\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043a\u043e\u0441\u0442\u044b\u043b\u044f\u043c\u0438. \u041d\u043e \u043e\u0431 \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0440\u0430\u0437, \u0435\u0441\u043b\u0438 \u043a\u043e\u043c\u0443-\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e.\u00a0<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043d\u0435 \u043f\u0440\u0435\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b \u0446\u0435\u043b\u0438 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043e\u0442\u043b\u0438\u0447\u0438\u0439 SRP Batcher \u0438 GPU Instancing. \u0414\u0430 \u0438 \u0441\u0430\u043c \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0438\u043d\u0433 \u043e\u043f\u0438\u0441\u0430\u043d \u043c\u043d\u043e\u0439 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u043d\u043e. \u041c\u043d\u0435 \u0441\u043a\u043e\u0440\u0435\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u043e \u0442\u043e \u0433\u0434\u0435 \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u0435\u043d. \u0418 \u043a\u0430\u043a \u043e\u043d \u043f\u043e\u043c\u043e\u0433 \u0440\u0435\u0448\u0438\u0442\u044c \u043e\u0434\u043d\u0443 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443.<\/p>\n<p>\u041f\u0440\u043e\u0435\u043a\u0442 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 <a href=\"https:\/\/github.com\/utkaka\/unity-gpu-instanced-grass\" rel=\"noopener noreferrer nofollow\">\u0432\u043e\u0442 \u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>\u0421\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432\u0430\u044f \u043a\u0440\u0438\u0442\u0438\u043a\u0430 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442\u0441\u044f. \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/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\/post\/656597\/\"> https:\/\/habr.com\/ru\/post\/656597\/<\/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_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0414\u043e\u0431\u0440\u044b\u0439 \u0434\u0435\u043d\u044c! \u0425\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u0432\u0430\u043c\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u043f\u044b\u0442\u043e\u043c \u043f\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c GPU Instancing.<\/p>\n<p>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u0430\u044f: \u0438\u0433\u0440\u0430 \u043f\u043e\u0434 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0435 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b, \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0435 \u0441 \u0442\u0440\u0430\u0432\u043e\u0439. \u0424\u043e\u0442\u043e\u0440\u0435\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f, low poly \u0441\u0442\u0438\u043b\u044c. \u041d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0438\u0433\u0440\u043e\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0442\u0440\u0430\u0432\u043e\u0439. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u044b\u043a\u0430\u0448\u0438\u0432\u0430\u0442\u044c. \u0414\u0435\u043b\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u043d\u0430 Unity 2021.2.7 (\u043d\u043e \u0436\u0435\u0441\u0442\u043a\u043e\u0439 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u043a \u0432\u0435\u0440\u0441\u0438\u0438 \u043d\u0435\u0442) \u0441 URP.<\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043d\u0430 \u0433\u0438\u0444\u043a\u0435.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<h2>\u041f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u0438\u044f<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0430\u0448\u0443 low poly \u0442\u0440\u0430\u0432\u0438\u043d\u043a\u0443. \u0422\u0430\u043a \u043a\u0430\u043a \u043a\u0430\u043c\u0435\u0440\u0430 \u0432 \u0438\u0433\u0440\u0435 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0432\u0430 \u0442\u0440\u0435\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a\u0430:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u0440\u044f\u0434 \u043b\u0438 \u044d\u0442\u043e\u0442 \u043c\u0435\u0448 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u0442\u0440\u0430\u0432\u0443, \u0435\u0441\u043b\u0438 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u043e\u0445\u043e\u0436\u0435\u0435 \u043d\u0430 \u0432\u0435\u0442\u0435\u0440. \u0414\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0448\u0435\u0439\u0434\u0435\u0440\u043e\u043c \u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c UV, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e: \u043d\u0438\u0436\u043d\u0438\u0435 \u0432\u0435\u0440\u0448\u0438\u043d\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432\u043d\u0438\u0437\u0443 \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u044b, \u0430 \u0432\u0435\u0440\u0445\u043d\u044f\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0432\u0435\u0440\u0445\u0443. \u041f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0434\u0435\u043b\u0430\u0435\u043c Shader Subgraph, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043d\u0430\u0448\u0438\u0445 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0445 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u0445:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0439. \u041d\u0430 \u0432\u0445\u043e\u0434 \u043f\u043e\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0437\u0430 \u0432\u0435\u0442\u0435\u0440 \u0438 \u043c\u0438\u0440\u043e\u0432\u0430\u044f \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0432\u0435\u0440\u0448\u0438\u043d\u044b. \u0414\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0435\u0435 \u0441\u0434\u0432\u0438\u0433\u0430 \u0432\u0435\u0442\u0440\u043e\u043c \u043c\u044b \u043f\u0440\u043e\u0433\u043e\u043d\u044f\u0435\u043c \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0447\u0435\u0440\u0435\u0437 Simple Noise \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u0442\u0440\u0430\u0432\u0438\u043d\u043a\u0438 \u043d\u0430 \u0441\u0446\u0435\u043d\u0435 \u043a\u043e\u043b\u044b\u0445\u0430\u043b\u0438\u0441\u044c \u043d\u0435 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e. \u0418 \u0434\u0430\u043b\u0435\u0435 \u0447\u0435\u0440\u0435\u0437 UV \u0438 Lerp \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0442\u0440\u043e\u0432\u043e\u0439 \u0441\u0434\u0432\u0438\u0433 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d \u043a \u0434\u0430\u043d\u043d\u043e\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u0435.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0430\u0448\u0438 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u044b.<\/p>\n<p><strong>\u0422\u0430\u043a \u0436\u0435 \u0445\u043e\u0447\u0443 \u0441\u0440\u0430\u0437\u0443 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0447\u0442\u043e \u0432\u0441\u0435 \u0437\u0430\u043c\u0435\u0440\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u0435 \u0441\u0430\u043c\u043e\u043c \u0431\u044b\u0441\u0442\u0440\u043e\u043c Xiaomi Redmi 8A.<\/strong><\/p>\n<h2>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 &#171;\u0432 \u043b\u043e\u0431&#187;<\/h2>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u0447\u0442\u043e-\u0442\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u0435\u0441\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u0441\u0435\u0431\u044f SRP Batcher \u043d\u0430 \u0442\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0440\u0430\u0432\u0438\u043d\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0443\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u043d\u0430\u0441 \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e.<\/p>\n<p>\u0421\u043f\u0435\u0440\u0432\u0430 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0439 \u0448\u0435\u0439\u0434\u0435\u0440:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0435\u043c \u043a \u0437\u0430\u0441\u0435\u0432\u0443 \u043f\u043e\u043b\u044f\u043d\u044b:<\/p>\n<pre><code class=\"cs\">_startPosition = -_fieldSize \/ 2.0f; _cellSize = new Vector2(_fieldSize.x \/ GrassDensity, _fieldSize.y \/ GrassDensity);  var grassEntities = new Vector2[GrassDensity, GrassDensity]; var halfCellSize = _cellSize \/ 2.0f;  for (var i = 0; i &lt; grassEntities.GetLength(0); i++) {   for (var j = 0; j &lt; grassEntities.GetLength(1); j++) {     grassEntities[i, j] =     new Vector2(_cellSize.x * i + _startPosition.x, _cellSize.y * j + _startPosition.y)        + new Vector2(Random.Range(-halfCellSize.x, halfCellSize.x),     Random.Range(-halfCellSize.y, halfCellSize.y));   } } _abstractGrassDrawer.Init(grassEntities, _fieldSize);<\/code><\/pre>\n<p>\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0435 \u043f\u043e\u043b\u0435 \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0434\u043e\u043b\u0435\u0439 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0441\u0442\u0438. \u041e\u043d\u043e \u0443 \u043d\u0430\u0441 \u043f\u043b\u043e\u0441\u043a\u043e\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 Vector2 \u0432\u043f\u043e\u043b\u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043b\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442. \u0414\u0430\u043b\u0435\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u044d\u0442\u043e\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442 \u043d\u0430 &#171;\u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0443&#187;. \u0421\u0435\u0439\u0447\u0430\u0441 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0430\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 GameObject \u0432 \u043d\u0443\u0436\u043d\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435.<\/p>\n<pre><code class=\"cs\">public override void Init(Vector2[,] grassEntities, Vector2 fieldSize) {   _grassEntities = new GameObject[grassEntities.GetLength(0), grassEntities.GetLength(1)];   for (var i = 0; i &lt; grassEntities.GetLength(0); i++) {     for (var j = 0; j &lt; grassEntities.GetLength(1); j++) {       _grassEntities[i, j] = Instantiate(_grassPrefab,       new Vector3(grassEntities[i, j].x, 0.0f, grassEntities[i, j].y), Quaternion.identity);     }   } }<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u0430\u043a\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e \u043c\u044b \u0434\u043e\u0441\u0442\u0438\u0433\u043b\u0438 \u0436\u0435\u043b\u0430\u0435\u043c\u043e\u0433\u043e (\u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u0433\u0440\u0435 \u0434\u0440\u0443\u0433\u043e\u0439 \u0440\u0430\u043a\u0443\u0440\u0441 \u043a\u0430\u043c\u0435\u0440\u044b, \u0435\u0441\u0442\u044c \u0434\u0435\u043a\u043e\u0440, \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0430 \u0437\u0435\u043c\u043b\u0438 \u0438 \u043f\u0440\u043e\u0447\u0435\u0435, \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u0441\u0430\u043c\u0430 \u0442\u0440\u0430\u0432\u0430 \u0437\u0430\u0441\u0435\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043d\u0443\u0436\u043d\u044b\u0445 \u043e\u0431\u043b\u0430\u0441\u0442\u044f\u0445, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u043e\u043b\u0443\u0447\u0448\u0435, \u043d\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u0440\u0430\u0432\u0438\u043d\u043e\u043a \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442: 15-20\u043a). \u041d\u043e \u0432\u043e\u0442 fps \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043f\u043e\u0434\u0432\u043e\u0434\u0438\u0442. \u0417\u043d\u0430\u0447\u0438\u0442 \u043c\u043e\u0436\u043d\u043e \u0434\u0443\u043c\u0430\u0442\u044c \u043e\u0431 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<h2>GPU Instancing<\/h2>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u044f <a href=\"https:\/\/docs.unity3d.com\/2021.2\/Documentation\/Manual\/GPUInstancing.html\" rel=\"noopener noreferrer nofollow\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a> \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u044d\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0438\u043c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p>\u0412 \u0438\u043d\u0441\u043f\u0435\u043a\u0442\u043e\u0440\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u043d\u0430\u0448\u0435\u0439 \u0442\u0440\u0430\u0432\u044b \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0433\u0430\u043b\u043e\u0447\u043a\u0443 &#171;Enable GPU Instancing&#187; \u0438 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0435\u0435. \u041d\u043e, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, <a href=\"https:\/\/forum.unity.com\/threads\/srp-batcher-and-gpu-instancing.833362\/\" rel=\"noopener noreferrer nofollow\">\u0432\u0441\u0435 \u043d\u0435 \u0442\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u043e<\/a>. \u0415\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0441\u0446\u0435\u043d\u0443 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 Frame Debugger, \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 SRP Batcher, \u043d\u043e \u043d\u0435 GPU Instancing. \u0412\u0441\u0435 \u0434\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u0438 \u0434\u0432\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u043a\u0430\u043a-\u0442\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c SRP Batcher. \u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e.<\/p>\n<h4>1. \u0412\u044b\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u0445 URP<\/h4>\n<p>\u042d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u0432\u0440\u044f\u0434 \u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u043c. \u041d\u0435 \u0437\u0440\u044f \u0432 \u0441\u0432\u0435\u0436\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 Unity \u044d\u0442\u0443 \u0433\u0430\u043b\u043e\u0447\u043a\u0443 \u0443\u0431\u0440\u0430\u043b\u0438 \u0438\u0437 \u0438\u043d\u0441\u043f\u0435\u043a\u0442\u043e\u0440\u0430. \u041d\u043e \u043d\u0430\u0439\u0442\u0438 \u0435\u0435 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u0447\u0435\u0440\u0435\u0437 Debug \u0440\u0435\u0436\u0438\u043c \u0438\u043d\u0441\u043f\u0435\u043a\u0442\u043e\u0440\u0430 \u0432\u0430\u0448\u0435\u0433\u043e URP \u0430\u0441\u0441\u0435\u0442\u0430. \u041d\u0430\u043c \u044d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043a\u0440\u043e\u043c\u0435 \u0442\u0440\u0430\u0432\u044b \u0432 \u0438\u0433\u0440\u0435 \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0434\u0440\u0443\u0433\u0438\u0445 \u0432\u0435\u0449\u0435\u0439, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 SRP Batcher \u043d\u0430\u0441 \u0443\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442.<\/p>\n<h4>2. \u0421\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u043c \u0448\u0435\u0439\u0434\u0435\u0440<\/h4>\n<p>\u0421\u043f\u043e\u0441\u043e\u0431 \u043d\u0435 \u0441\u0430\u043c\u044b\u0439 \u0443\u0434\u043e\u0431\u043d\u044b\u0439, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e <a href=\"https:\/\/docs.unity3d.com\/Manual\/SRPBatcher.html#intentionally-removing-compatibility\" rel=\"noopener noreferrer nofollow\">\u043e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0430\u043c \u0448\u0435\u0439\u0434\u0435\u0440<\/a>. \u0410 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 Shader Graph \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0435\u0449\u0435 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0448\u0435\u0439\u0434\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0442\u043e\u043c \u043e\u0442\u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0418 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0433\u0440\u0430\u0444\u0430 \u044d\u0442\u0443 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c. \u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438: &#171;<em>Add a new\u00a0<\/em><a href=\"https:\/\/docs.unity3d.com\/Manual\/SL-Properties.html\" rel=\"noopener noreferrer nofollow\"><em>material property<\/em><\/a><em>\u00a0declaration into the shader\u2019s\u00a0<\/em><code>Properties<\/code>\u00a0block. Don\u2019t declare the new material property in the\u00a0<code>UnityPerMaterial<\/code>\u00a0constant buffer&#187;. \u041f\u043e\u0447\u0435\u043c\u0443-\u0442\u043e \u0432 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u0438 \u0448\u0435\u0439\u0434\u0435\u0440 \u043e\u0441\u0442\u0430\u0432\u0430\u043b\u0441\u044f SRP compatible, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0431\u0443\u0444\u0435\u0440\u0430:<\/p>\n<pre><code>\/\/CBUFFER_START(UnityPerMaterial) float4 _MainTexture_TexelSize; half _WindShiftStrength; half _WindSpeed; half _WindStrength; \/\/CBUFFER_END<\/code><\/pre>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u043d\u0435\u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u044d\u0442\u043e\u0433\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u0430, \u044f \u0432\u044b\u0431\u0440\u0430\u043b \u0438\u043c\u0435\u043d\u043d\u043e \u0435\u0433\u043e. \u041f\u0440\u043e\u0441\u0442\u043e \u0447\u0442\u043e\u0431\u044b \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0441\u0430\u043c\u0438 \u043f\u0440\u0435\u0444\u0430\u0431\u044b \u043e\u0441\u0442\u0430\u0432\u0430\u043b\u0438\u0441\u044c \u0442\u0435\u043c\u0438 \u0436\u0435, \u0447\u0442\u043e \u0438 \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0435.\u00a0<\/p>\n<h4>3. \u0421\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u043c \u0440\u0435\u043d\u0434\u0435\u0440\u0435\u0440<\/h4>\n<p>\u041f\u043e\u0436\u0430\u043b\u0443\u0439, \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435 \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0448\u0435\u0439\u0434\u0435\u0440 \u0441 SRP Batcher \u0438 \u0441 GPU Instancing. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0438\u0442\u044c \u0440\u0435\u043d\u0434\u0435\u0440\u0435\u0440\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/MaterialPropertyBlock.html\" rel=\"noopener noreferrer nofollow\">MaterialPropertyBlock<\/a>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d <a href=\"https:\/\/forum.unity.com\/threads\/materialpropertyblock-and-srp-batcher.815499\/\" rel=\"noopener noreferrer nofollow\">\u043d\u0435 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c \u0441 SRP Batcher<\/a>. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435 MaterialPropertyBlock \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043f\u043e\u043b\u044c\u0437\u0443. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u044b\u0445\u0430\u043d\u0438\u0435 \u0442\u0440\u0430\u0432\u044b \u043d\u0435 \u0447\u0435\u0440\u0435\u0437 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u0448\u0443\u043c, \u0430 \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0441\u0432\u043e\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c. \u041b\u0438\u0431\u043e \u0440\u0430\u0441\u043a\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u0442\u0440\u0430\u0432\u0443 \u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u043d\u0435\u0435.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043b\u044e\u0431\u043e\u0439 \u0438\u0437 \u044d\u0442\u0438\u0445 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0439, \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0438\u043d\u0433 \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u043c\u0435\u0440\u044b:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h2>Graphics API<\/h2>\n<p>\u041e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0448 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c GPU Instancing \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0447\u0435\u0440\u0435\u0437 Graphics API, \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f GameObject. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 3 \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<p><strong>1. <\/strong><a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/Graphics.DrawMeshInstanced.html\" rel=\"noopener noreferrer nofollow\"><strong>Graphics.DrawMeshInstanced<\/strong><\/a><\/p>\n<p>\u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431. \u041f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043c\u0435\u0448, \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0438 \u043c\u0430\u0441\u0441\u0438\u0432 \u043c\u0430\u0442\u0440\u0438\u0446. \u041d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0448\u0435\u0439\u0434\u0435\u0440\u0430, \u043d\u043e \u0438\u043c\u0435\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0432 1023 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430 \u0437\u0430 \u043e\u0434\u0438\u043d \u0432\u044b\u0437\u043e\u0432. \u041c\u0430\u043b\u043e\u0432\u0430\u0442\u043e \u0431\u0443\u0434\u0435\u0442.<\/p>\n<p><strong>2. <\/strong><a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/Graphics.DrawMeshInstancedIndirect.html\" rel=\"noopener noreferrer nofollow\"><strong>Graphics.DrawMeshInstancedIndirect<\/strong><\/a><\/p>\n<p>\u041d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0439 \u043d\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 ComputeBuffer. \u041d\u043e \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0443\u0436\u0435 \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u0443\u0444\u0435\u0440\u043e\u043c \u0432 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b. \u0427\u0442\u043e \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0448\u0435\u0439\u0434\u0435\u0440\u0430.<\/p>\n<p><strong>3. <\/strong><a href=\"https:\/\/docs.unity3d.com\/ScriptReference\/Graphics.DrawMeshInstancedProcedural.html\" rel=\"noopener noreferrer nofollow\"><strong>Graphics.DrawMeshInstancedProcedural<\/strong><\/a><\/p>\n<p>\u0421\u0445\u043e\u0436 \u0441 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u043e\u0432 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e \u0438\u0437 \u0441\u043a\u0440\u0438\u043f\u0442\u0430. \u041d\u0430 \u043d\u0435\u043c \u043c\u044b \u0438 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c\u0441\u044f.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u043c \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043d\u0430\u0448\u0438\u0445 \u0442\u0440\u0430\u0432\u0438\u043d\u043e\u043a \u0432 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b:<\/p>\n<pre><code class=\"cs\">_positionsCount = _positions.Count; _positionBuffer?.Release(); if (_positionsCount == 0) return; _positionBuffer = new ComputeBuffer(_positionsCount, 8); _positionBuffer.SetData(_positions); _instanceMaterial.SetBuffer(PositionsShaderProperty, _positionBuffer);<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0441\u0430\u043c\u0430 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u0430\u0434\u0440:<\/p>\n<pre><code class=\"cs\">private void Update() {   if (_positionsCount == 0) return;   Graphics.DrawMeshInstancedProcedural(_instanceMesh, 0, _instanceMaterial,   _grassBounds, _positionsCount,   null, ShadowCastingMode.Off, false); }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u043f\u0440\u0435\u0436\u043d\u0438\u0439 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b, \u0442\u043e \u0432\u0441\u0435 \u0442\u044b\u0441\u044f\u0447\u0438 \u0442\u0440\u0430\u0432\u0438\u043d\u043e\u043a \u0431\u0443\u0434\u0443\u0442 \u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043d\u0430\u0448 \u0448\u0435\u0439\u0434\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u0442\u0435\u043f\u0435\u0440\u044c \u0431\u0440\u0430\u0442\u044c \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u0438\u0437 \u0431\u0443\u0444\u0435\u0440\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c \u0448\u0435\u0439\u0434\u0435\u0440:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0434\u0432\u0435 \u043d\u043e\u0434\u044b \u0441 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438.<\/p>\n<p>\u00a0\u041f\u0435\u0440\u0432\u0430\u044f \u043d\u0443\u0436\u043d\u0430 \u043d\u0430\u043c \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f unity_InstanceID, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430 \u0438\u0437 \u0431\u0443\u0444\u0435\u0440\u0430. \u0421\u0430\u043c\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u043d\u0430\u0439\u0434\u0435\u043d\u043e <a href=\"https:\/\/forum.unity.com\/threads\/using-instanced-or-indirect-properties-in-a-vertex-shader.536542\/\" rel=\"noopener noreferrer nofollow\">\u0433\u0434\u0435-\u0442\u043e \u0432 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430\u0445<\/a> \u0438 \u043f\u043e\u043b\u043d\u043e\u0435 \u0442\u0435\u043e\u0440\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u0431\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0434\u0430\u0442\u044c \u043d\u0435 \u043c\u043e\u0433\u0443. \u0411\u0443\u0434\u0443 \u043f\u0440\u0438\u0437\u043d\u0430\u0442\u0435\u043b\u0435\u043d \u0437\u0430 \u0441\u0441\u044b\u043b\u043a\u0438 \u0441 \u043f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<pre><code>#pragma instancing_options procedural:ConfigureProcedural Out = In;<\/code><\/pre>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f &#8212; \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0438\u0437 \u0431\u0443\u0444\u0435\u0440\u0430.<\/p>\n<pre><code>#if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED) StructuredBuffer&lt;float2> PositionsBuffer; #endif  float2 position;  void ConfigureProcedural () { #if defined(UNITY_PROCEDURAL_INSTANCING_ENABLED) position = PositionsBuffer[unity_InstanceID]; #endif }  void ShaderGraphFunction_float (out float2 PositionOut) { PositionOut = position; }  void ShaderGraphFunction_half (out half2 PositionOut) { PositionOut = position; }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0437\u0430\u043c\u0435\u0440\u044b:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0440\u043e\u043c\u0435 \u043d\u0435\u043f\u043b\u043e\u0445\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Compute Shader \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u0431\u0443\u0444\u0435\u0440\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043b\u0435\u0442\u0430\u044e\u0449\u0435\u0439 \u043f\u043e \u0441\u0446\u0435\u043d\u0435 \u0442\u0440\u0430\u0432\u044b \u0438\u0437 C# \u0432 \u0448\u0435\u0439\u0434\u0435\u0440. <a href=\"https:\/\/www.ronja-tutorials.com\/post\/051-draw-procedural\/\" rel=\"noopener noreferrer nofollow\">\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a<\/a>.<\/p>\n<h2>\u0415\u0449\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438<\/h2>\n<p>\u041a\u0430\u043c\u0435\u0440\u0430 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0438\u0433\u0440\u0435 \u043d\u0435 \u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f, \u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u0432\u0434\u043e\u043b\u044c \u043e\u0441\u0438 Z. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043b\u0435\u0433\u043a\u043e\u0435 \u043f\u043e\u0434\u043e\u0431\u0438\u0435 \u043a\u0443\u043b\u0438\u043d\u0433\u0430. \u0422\u0430\u043a \u043a\u0430\u043a \u0442\u0440\u0430\u0432\u0443 \u043c\u044b \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u043b\u0438 \u043f\u043e \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0439 \u0441\u0435\u0442\u043a\u0435, \u0442\u043e \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u0430\u043a\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0442\u0440\u0430\u0432\u0438\u043d\u043e\u043a \u043d\u0430\u043c \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442.<\/p>\n<p>\u0412 \u043a\u043b\u0430\u0441\u0441\u0435 \u043d\u0430\u0448\u0435\u0439 \u043f\u043e\u043b\u044f\u043d\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u043a\u0430\u043c\u0435\u0440\u043e\u0439 \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u0433\u0440\u0430\u043d\u0438\u0446\u044b.<\/p>\n<pre><code class=\"cs\">private void Update() { if (_camera.transform.hasChanged) { UpdateCameraCells(); } }  private Vector3 Raycast(Vector3 position) { var ray = _camera.ScreenPointToRay(position); _plane.Raycast(ray, out var enter); return ray.GetPoint(enter); }  private void UpdateCameraCells() { if (!PerformCulling) { _abstractGrassDrawer.UpdatePositions(Vector2Int.zero, new Vector2Int(GrassDensity, GrassDensity)); return; } var bottomLeftCameraCorner = Raycast(Vector3.zero); var topLeftCameraCorner = Raycast(new Vector3(0.0f, Screen.height)); var topRightCameraCorner = Raycast(new Vector3(Screen.width, Screen.height)); var bottomLeftCameraCell = new Vector2Int( Mathf.Clamp(Mathf.FloorToInt((topLeftCameraCorner.x - _startPosition.x) \/ _cellSize.x), 0, GrassDensity - 1), Mathf.Clamp(Mathf.FloorToInt((bottomLeftCameraCorner.z - _startPosition.y) \/ _cellSize.y), 0, GrassDensity - 1));  var topRightCameraCell = new Vector2Int( Mathf.Clamp(Mathf.FloorToInt((topRightCameraCorner.x - _startPosition.x) \/ _cellSize.x) + 1, 0, GrassDensity - 1), Mathf.Clamp(Mathf.FloorToInt((topRightCameraCorner.z - _startPosition.y) \/ _cellSize.y) + 1, 0, GrassDensity - 1));<\/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-330877","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/330877","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=330877"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/330877\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=330877"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=330877"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=330877"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}