{"id":248755,"date":"2015-01-25T00:43:02","date_gmt":"2015-01-24T20:43:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=248755"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=248755","title":{"rendered":"<span class=\"post_title\">GPU Particles \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Compute \u0438 Geometry \u0448\u0435\u0439\u0434\u0435\u0440\u043e\u0432<\/span>"},"content":{"rendered":"<div class=\"content html_format\">     \t\u041f\u0440\u0438\u0432\u0435\u0442, \u0434\u043e\u0440\u043e\u0433\u043e\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c!<\/p>\n<p>  \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430, \u0438 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0442\u0430\u043a\u0438\u0445 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0432\u0435\u0449\u0430\u0445, \u043a\u0430\u043a <b>Compute Shader<\/b> \u0438 <b>Geometry Shader<\/b> \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0430 <b>1000000+<\/b> \u0447\u0430\u0441\u0442\u0438\u0446, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435 \u0442\u043e\u0447\u043a\u0430\u043c\u0438, \u0430 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0430\u043c\u0438 (<i>billboard quads<\/i>) \u0438 \u0438\u043c\u0435\u044e\u0442 \u0441\u0432\u043e\u044e \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0443. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043c\u044b \u0432\u044b\u0432\u0435\u0434\u0435\u043c <b>2000000+<\/b> \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0442\u0440\u0435\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a\u043e\u0432 \u043f\u0440\u0438 <b>FPS &gt; 100<\/b> (\u043d\u0430 \u0431\u044e\u0434\u0436\u0435\u0442\u043d\u043e\u0439 \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0440\u0442\u0435 <i>GeForce 550 Ti<\/i>).<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/files\/740\/6a1\/afc\/7406a1afcd474664b90678520b39ae41.png\"\/><br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h1>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h1>\n<p>  \u042f \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u043f\u0438\u0441\u0430\u043b \u043e \u0448\u0435\u0439\u0434\u0435\u0440\u0430\u0445 \u0441\u0440\u0435\u0434\u0438 \u0441\u0432\u043e\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439, \u043d\u043e \u043e\u043f\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043c\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0432\u0443\u043c\u044f \u0442\u0438\u043f\u0430\u043c\u0438: <b>Vertex Shader<\/b>, <b>Pixel Shader<\/b>. \u041e\u0434\u043d\u0430\u043a\u043e, \u0441 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435\u043c <i>DX10+<\/i> \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u043d\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b \u0448\u0435\u0439\u0434\u0435\u0440\u043e\u0432: <i>Geometry Shader, Domain Shader, Hull Shader, Compute Shader<\/i>. \u041d\u0430 \u0432\u0441\u044f\u043a\u0438\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u043d\u0430\u043f\u043e\u043c\u043d\u044e, \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440 \u0441\u0435\u0439\u0447\u0430\u0441:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/files\/f54\/d16\/0e9\/f54d160e949342b4bf938e41bdf39619.png\"\/><\/p>\n<p>  \u0421\u0440\u0430\u0437\u0443 \u043e\u0433\u043e\u0432\u043e\u0440\u044e\u0441\u044c, \u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043d\u0435 \u0437\u0430\u0442\u0440\u043e\u043d\u0435\u043c <i>Domain Shader<\/i> \u0438 <i>Hull Shader<\/i>, \u043f\u0440\u043e \u0442\u0435\u0441\u0441\u0435\u043b\u044f\u0446\u0438\u044e \u044f \u043d\u0430\u043f\u0438\u0448\u0443 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445.<\/p>\n<p>  \u041d\u0435\u0438\u0437\u0443\u0447\u0435\u043d\u043d\u044b\u043c \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e <i>Geometry Shader<\/i>. \u0427\u0442\u043e \u0436\u0435 \u0442\u0430\u043a\u043e\u0435 <i>Geometry Shader<\/i>?<\/p>\n<h1>\u0413\u043b\u0430\u0432\u0430 1: Geometry Shader<\/h1>\n<p>  <i>Vertex Shader<\/i> \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0432\u0435\u0440\u0442\u0435\u043a\u0441\u043e\u0432, <i>Pixel Shader<\/i> \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439, \u0438 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0433\u0430\u0434\u0430\u0442\u044c\u0441\u044f \u2013 <i>Geometry Shader<\/i> \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432.<\/p>\n<p>  \u042d\u0442\u043e\u0442 \u0448\u0435\u0439\u0434\u0435\u0440 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430, \u0442.\u0435. \u0435\u0433\u043e \u0432\u043e\u0432\u0441\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438 \u043d\u0435 \u0431\u044b\u0442\u044c: \u0432\u0435\u0440\u0442\u0435\u043a\u0441\u044b \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u0432 <i>Primitive Assembly Stage<\/i> \u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u0438\u0434\u0435\u0442 \u0440\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u0430.<br \/>  Geometry Shader \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 <i>Primitive Assembly Stage<\/i> \u0438 <i>Rasterizer Stage<\/i>.<\/p>\n<p>  \u041d\u0430 \u0432\u0445\u043e\u0434 \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043a\u0430\u043a \u043e \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u0435, \u0442\u0430\u043a \u0438 \u043e \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0445 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u0430\u0445:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/f2b\/c7f\/3c3\/f2bc7f3c370f3786da4a62fbf4484cf8.png\" alt=\"image\"\/><\/p>\n<p>  \u041d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u043e\u0442\u043e\u043a \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432, \u043a\u0443\u0434\u0430 \u043c\u044b \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432. \u041f\u0440\u0438\u0447\u0435\u043c \u0442\u0438\u043f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u0430 \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u2013 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <b>Point<\/b>, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c <b>Line<\/b>. \u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0433\u0435\u043e\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0448\u0435\u0439\u0434\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0432\u0445\u043e\u0434 \u0441 \u0432\u044b\u0445\u043e\u0434\u043e\u043c:<\/p>\n<pre><code>struct PixelInput { \tfloat4 Position : SV_POSITION; \/\/ \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 System-Value \u0434\u043b\u044f \u0432\u0435\u0440\u0442\u0435\u043a\u0441\u0430 };  [maxvertexcount(1)] \/\/ \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b-\u0432\u043e \u0432\u0435\u0440\u0442\u0435\u043a\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c void SimpleGS( point PixelInput input[1], inout PointStream&lt;PixelInput&gt; stream ) { \tPixelInput pointOut = input[0]; \/\/ \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0432\u0435\u0440\u0442\u0435\u043a\u0441\u0430 \t \tstream.Append(pointOut); \/\/ \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432\u0435\u0440\u0442\u0435\u043a\u0441\u0430 \tstream.RestartStrip(); \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432 (\u0434\u043b\u044f Point \u2013 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0432\u0435\u0440\u0442\u0435\u043a\u0441) }<\/code><\/pre>\n<p>  <\/p>\n<h1>\u0413\u043b\u0430\u0432\u0430 2: StructuredBuffer<\/h1>\n<p>  \u0412 <i>DirectX10+<\/i> \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0442\u0430\u043a\u043e\u0439 \u0442\u0438\u043f \u0431\u0443\u0444\u0435\u0440\u043e\u0432 \u043a\u0430\u043a <i>Structured Buffer<\/i>, \u0442\u0430\u043a\u043e\u0439 \u0431\u0443\u0444\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0438\u0441\u0430\u043d \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u043e\u043c \u043a\u0430\u043a \u0435\u043c\u0443 \u0443\u0433\u043e\u0434\u043d\u043e, \u0442.\u0435. \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0438 \u2013 \u044d\u0442\u043e \u043e\u0434\u043d\u043e\u0440\u043e\u0434\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 <i>GPU<\/i>.<\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u0431\u0443\u0444\u0435\u0440 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0447\u0430\u0441\u0442\u0438\u0446. \u041e\u043f\u0438\u0448\u0435\u043c \u043a\u0430\u043a\u0438\u043c\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c\u0438 \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u0447\u0430\u0441\u0442\u0438\u0446\u0430 (<i>\u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 C#<\/i>):<\/p>\n<pre><code>public struct GPUParticleData {      public Vector3 Position;      public Vector3 Velocity; };<\/code><\/pre>\n<p>  \u0418 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0430\u043c \u0431\u0443\u0444\u0435\u0440 (<i>\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0445\u0435\u043b\u043f\u0435\u0440\u0430 SharpDX.Toolkit<\/i>):<\/p>\n<pre><code>_particlesBuffer = Buffer.Structured.New&lt;GPUParticleData&gt;(graphics, initialParticles, true);<\/code><\/pre>\n<p>  \u0413\u0434\u0435 <b>initialParticles<\/b> \u2013 \u043c\u0430\u0441\u0441\u0438\u0432 <b>GPUParticleData<\/b> \u0441 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0432 \u043d\u0443\u0436\u043d\u043e\u0435 \u043a\u043e\u043b-\u0432\u043e \u0447\u0430\u0441\u0442\u0438\u0446.<\/p>\n<p>  \u0421\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0444\u043b\u0430\u0433\u0438 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0431\u0443\u0444\u0435\u0440\u0430 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435:<\/p>\n<p>  <i>BufferFlags.ShaderResource<\/i> \u2013 \u0434\u043b\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043a \u0431\u0443\u0444\u0435\u0440\u0443 \u0438\u0437 \u0448\u0435\u0439\u0434\u0435\u0440\u0430<br \/>  <i>BufferFlags.StructuredBuffer<\/i> \u2013 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u0431\u0443\u0444\u0435\u0440\u0430<br \/>  <i>BufferFlags.UnorderedAccess<\/i> \u2013 \u0434\u043b\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0431\u0443\u0444\u0435\u0440\u0430 \u0438\u0437 \u0448\u0435\u0439\u0434\u0435\u0440\u0430<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0431\u0443\u0444\u0435\u0440 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0432 <b>1 000 000<\/b> \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u0435\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438:<\/p>\n<pre><code>GPUParticleData[] initialParticles = new GPUParticleData[PARTICLES_COUNT]; for (int i = 0; i &lt; PARTICLES_COUNT; i++) { \tinitialParticles[i].Position = random.NextVector3(new Vector3(-30f, -30f, -30f), new Vector3(30f, 30f, 30f)); }<\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0443 \u043d\u0430\u0441 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 <i>GPU<\/i> \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0431\u0443\u0444\u0435\u0440 \u0438\u0437 <b>1 000 000<\/b> \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438.<\/p>\n<h1>\u0413\u043b\u0430\u0432\u0430 3. \u0420\u0435\u043d\u0434\u0435\u0440 Point-\u0447\u0430\u0441\u0442\u0438\u0446<\/h1>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c, \u043a\u0430\u043a \u0436\u0435 \u043d\u0430\u043c \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0431\u0443\u0444\u0435\u0440? \u0412\u0435\u0434\u044c \u0443 \u043d\u0430\u0441 \u0434\u0430\u0436\u0435 \u043d\u0435\u0442 \u0432\u0435\u0440\u0442\u0435\u043a\u0441\u043e\u0432! \u0412\u0435\u0440\u0442\u0435\u043a\u0441\u044b \u043c\u044b \u0431\u0443\u0434\u0435\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u0445\u043e\u0434\u0443, \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u043e\u0433\u043e \u0431\u0443\u0444\u0435\u0440\u0430. <\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0432\u0430 \u0448\u0435\u0439\u0434\u0435\u0440\u0430 \u2013 <i>Vertex Shader<\/i> \u0438 <i>Pixel Shader<\/i>.<br \/>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u043e\u043f\u0438\u0448\u0435\u043c \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0448\u0435\u0439\u0434\u0435\u0440\u043e\u0432:<\/p>\n<pre><code>struct Particle \/\/ \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043d\u0430 GPU {     float3 Position;     float3 Velocity; };  StructuredBuffer&lt;Particle&gt; Particles : register(t0); \/\/ \u0431\u0443\u0444\u0435\u0440 \u0447\u0430\u0441\u0442\u0438\u0446 cbuffer Params : register(b0) \/\/ \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0432\u0438\u0434\u0430 \u0438 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438 { \tfloat4x4 View; \tfloat4x4 Projection; };  \/\/ \u0442.\u043a. \u0432\u0435\u0440\u0442\u0435\u043a\u0441\u043e\u0432 \u0443 \u043d\u0430\u0441 \u043d\u0435\u0442, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0439 ID \u0432\u0435\u0440\u0442\u0435\u043a\u0441\u0430 \u043f\u0440\u0438 \u0440\u0438\u0441\u043e\u0432\u0430\u043d\u0438\u0438 \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Vertex Buffer struct VertexInput {  \tuint VertexID : SV_VertexID; };  struct PixelInput \/\/ \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0432\u0435\u0440\u0442\u0435\u043a\u0441 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0438\u0437 Vertex Shader { \tfloat4 Position : SV_POSITION;  };  struct PixelOutput \/\/ \u0446\u0432\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0438\u043a\u0441\u0435\u043b\u044f {     float4 Color : SV_TARGET0; };<\/code><\/pre>\n<p>  \u041d\u0443 \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0448\u0435\u0439\u0434\u0435\u0440\u044b, \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u0432\u0435\u0440\u0442\u0435\u043a\u0441\u043d\u044b\u0439:<\/p>\n<pre><code>PixelInput DefaultVS(VertexInput input) { \tPixelInput output = (PixelInput)0;  \tParticle particle = Particles[input.VertexID];  \tfloat4 worldPosition = float4(particle.Position, 1); \tfloat4 viewPosition = mul(worldPosition, View); \toutput.Position = mul(viewPosition, Projection); \treturn output; }<\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0435 \u043c\u0430\u0433\u0438\u0438 \u2013 \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0447\u0438\u0442\u0430\u0435\u043c \u0438\u0437 \u0431\u0443\u0444\u0435\u0440\u0430 \u0447\u0430\u0441\u0442\u0438\u0446 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u0438\u0446\u0443 \u043f\u043e \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 <i>VertexID<\/i> (\u0430 \u043e\u043d \u0443 \u043d\u0430\u0441 \u043b\u0435\u0436\u0438\u0442 \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043e\u0442 0 \u0434\u043e 999999) \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0447\u0430\u0441\u0442\u0438\u0446\u044b \u2013 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u0432 \u044d\u043a\u0440\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e.<\/p>\n<p>  \u041d\u0443 \u0430 \u0441 <i>Pixel Shader<\/i> \u043f\u0440\u043e\u0449\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e:<\/p>\n<pre><code>PixelOutput DefaultPS(PixelInput input) { \tPixelOutput output = (PixelOutput)0;  \toutput.Color = float4((float3)0.1, 1); \t \treturn output; }<\/code><\/pre>\n<p>  \u0417\u0430\u0434\u0430\u0435\u043c \u0446\u0432\u0435\u0442 \u0447\u0430\u0441\u0442\u0438\u0446\u044b \u043a\u0430\u043a <i>float4(0.1, 0.1, 0.1, 1)<\/i>. \u041f\u043e\u0447\u0435\u043c\u0443 <i>0.1<\/i>? \u041f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0447\u0430\u0441\u0442\u0438\u0446 \u0443 \u043d\u0430\u0441 \u043c\u0438\u043b\u043b\u0438\u043e\u043d, \u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <i>Additive Blending<\/i>.<\/p>\n<p>  \u0417\u0430\u0434\u0430\u0434\u0438\u043c \u0431\u0443\u0444\u0435\u0440\u044b \u0438 \u043e\u0442\u0440\u0438\u0441\u0443\u0435\u043c \u0433\u0435\u043e\u043c\u0435\u0442\u0440\u0438\u044e:<\/p>\n<pre><code>graphics.ResetVertexBuffers(); \/\/ \u043d\u0430 \u0432\u0441\u044f\u043a\u0438\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u0441\u0431\u0440\u043e\u0441\u0438\u043c \u0431\u0443\u0444\u0435\u0440\u044b  graphics.SetBlendState(_additiveBlendState); \/\/ \u0432\u043a\u043b\u044e\u0447\u0438\u043c Additive Blend State  \/\/ \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043d\u0430\u0448 \u0431\u0443\u0444\u0435\u0440 \u0447\u0430\u0441\u0442\u0438\u0446 \u043a\u0430\u043a SRV (\u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u0435\u043d\u0438\u0435). _particlesRender.Parameters[&quot;Particles&quot;].SetResource&lt;SharpDX.Direct3D11.ShaderResourceView&gt;(0, _particlesBuffer);   \/\/ \u043c\u0430\u0442\u0440\u0438\u0446\u044b _particlesRender.Parameters[&quot;View&quot;].SetValue(camera.View); _particlesRender.Parameters[&quot;Projection&quot;].SetValue(camera.Projection);  \/\/ \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0448\u0435\u0439\u0434\u0435\u0440 _particlesRender.CurrentTechnique.Passes[0].Apply();  \/\/ \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u043e\u0442\u0440\u0438\u0441\u0432\u043e\u043a\u0443 1000000 \u0447\u0430\u0441\u0442\u0438\u0446 \u0432 \u0432\u0438\u0434\u0435 \u0442\u043e\u0447\u0435\u043a graphics.Draw(PrimitiveType.PointList, PARTICLES_COUNT);<\/code><\/pre>\n<p>  \u041d\u0443 \u0438 \u043f\u043e\u043b\u044e\u0431\u0443\u0435\u043c\u0441\u044f \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u043e\u0431\u0435\u0434\u043e\u0439:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/files\/eeb\/450\/c99\/eeb450c9945c4b74826e330be50799d4.png\"\/><\/p>\n<h1>\u0413\u043b\u0430\u0432\u0430 4: \u0420\u0435\u043d\u0434\u0435\u0440 QuadBillboard-\u0447\u0430\u0441\u0442\u0438\u0446<\/h1>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0437\u0430\u0431\u044b\u043b\u0438 \u043f\u0435\u0440\u0432\u0443\u044e \u0433\u043b\u0430\u0432\u0443, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u0435\u043b\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c \u043d\u0430\u0448 \u043d\u0430\u0431\u043e\u0440 \u0442\u043e\u0447\u0435\u043a \u0432 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0435 <i>Billboard<\/i>-\u044b, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0435 \u0438\u0437 \u0434\u0432\u0443\u0445 \u0442\u0440\u0435\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a\u043e\u0432. <\/p>\n<p>  \u0427\u0443\u0442\u044c-\u0447\u0443\u0442\u044c \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 <i>QuadBillboard<\/i>: \u044d\u0442\u043e \u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0439 \u0438\u0437 \u0434\u0432\u0443\u0445 \u0442\u0440\u0435\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a\u043e\u0432 \u0438 \u044d\u0442\u043e\u0442 \u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u0432\u0435\u0440\u043d\u0443\u0442 \u043a \u043a\u0430\u043c\u0435\u0440\u0435.<\/p>\n<p>  \u041a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u0432\u0430\u0434\u0440\u0430\u0442? \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0431\u044b\u0441\u0442\u0440\u043e\u0439 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043a\u043e\u0435-\u0447\u0442\u043e \u0432 <i>Vertex Shader<\/i>. \u0422\u0430\u043c \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0440\u0438 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u043f\u0440\u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0438 <i>SV_Position<\/i>:<\/p>\n<ol>\n<li><i>World Space<\/i> \u2013 \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0432\u0435\u0440\u0442\u0435\u043a\u0441\u0430 \u0432 \u043c\u0438\u0440\u043e\u0432\u044b\u0445 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u0445<\/li>\n<li><i>View Space<\/i> \u2013 \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0432\u0435\u0440\u0442\u0435\u043a\u0441\u0430 \u0432 \u0432\u0438\u0434\u043e\u0432\u044b\u0445 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u0445<\/li>\n<li><i>Projection Space<\/i> \u2013 \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0432\u0435\u0440\u0442\u0435\u043a\u0441\u0430 \u0432 \u044d\u043a\u0440\u0430\u043d\u043d\u044b\u0445 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u0445<\/li>\n<\/ol>\n<p>  <i>View Space<\/i> \u043a\u0430\u043a \u0440\u0430\u0437 \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e, \u0432\u0435\u0434\u044c \u044d\u0442\u0438 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043a\u0430\u043a \u0440\u0430\u0437 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u0430\u043c\u0435\u0440\u044b \u0438 \u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u044c (-1 + p.x, -1 + p.y, p.z) -&gt; (1 + p.x, 1 + p.y, p.z) \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0430\u044f \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u043e\u0440\u043c\u0430\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0430 \u043a\u0430\u043c\u0435\u0440\u0443. <\/p>\n<p>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u043a\u043e\u0435-\u0447\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0432 \u0448\u0435\u0439\u0434\u0435\u0440\u0435:<\/p>\n<pre><code>PixelInput TriangleVS(VertexInput input) { \tPixelInput output = (PixelInput)0;  \tParticle particle = Particles[input.VertexID];  \tfloat4 worldPosition = float4(particle.Position, 1); \tfloat4 viewPosition = mul(worldPosition, View); \toutput.Position = viewPosition; \toutput.UV = 0;  \treturn output; }<\/code><\/pre>\n<p>  \u041d\u0430 \u0432\u044b\u0445\u043e\u0434 <i>SV_Position<\/i> \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0435 <i>ProjectionSpace-position<\/i>, \u0430 <i>ViewSpace-position<\/i>, \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u044b \u0432 <i>Geometry Shader<\/i> \u0432 <i>ViewSpace<\/i>.<\/p>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u0443\u044e \u0441\u0442\u0430\u0434\u0438\u044e:<\/p>\n<pre><code>\/\/ \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432\u0435\u0440\u0442\u0435\u043a\u0441\u0430 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044f \u0435\u0433\u043e \u0432 Projection Space PixelInput _offsetNprojected(PixelInput data, float2 offset, float2 uv) { \tdata.Position.xy += offset; \tdata.Position = mul(data.Position, Projection); \tdata.UV = uv;  \treturn data; }  [maxvertexcount(4)] \/\/ \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b GS \u2013 4 \u0432\u0435\u0440\u0442\u0435\u043a\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442 TriangleStrip void TriangleGS( point PixelInput input[1], inout TriangleStream&lt;PixelInput&gt; stream ) { \tPixelInput pointOut = input[0]; \t \tconst float size = 0.1f; \/\/ \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u043e\u043d\u0447\u0435\u043d\u043e\u0433\u043e \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0430  \t\/\/ \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0430 \tstream.Append( _offsetNprojected(pointOut, float2(-1,-1) * size, float2(0, 0)) ); \tstream.Append( _offsetNprojected(pointOut, float2(-1, 1) * size, float2(0, 1)) ); \tstream.Append( _offsetNprojected(pointOut, float2( 1,-1) * size, float2(1, 0)) ); \tstream.Append( _offsetNprojected(pointOut, float2( 1, 1) * size, float2(1, 1)) );  \t\/\/ \u0441\u043e\u0437\u0434\u0430\u0442\u044c TriangleStrip \tstream.RestartStrip(); }<\/code><\/pre>\n<p>  \u041d\u0443 \u0438 \u0442\u0430\u043a, \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0442\u0435\u043f\u0435\u0440\u044c <i>UV<\/i> \u2013 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0443 \u0432 \u043f\u0438\u043a\u0441\u0435\u043b\u044c\u043d\u043e\u043c \u0448\u0435\u0439\u0434\u0435\u0440\u0435:  <\/p>\n<pre><code>PixelOutput TrianglePS(PixelInput input) { \tPixelOutput output = (PixelOutput)0; \tfloat particle = ParticleTexture.Sample(ParticleSampler, input.UV).x * 0.3;\t         output.Color = float4((float3)particle, 1); \t \treturn output; }<\/code><\/pre>\n<p>  \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0441\u044d\u043c\u043f\u043b\u0435\u0440 \u0438 \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0443 \u0447\u0430\u0441\u0442\u0438\u0446\u044b \u0434\u043b\u044f \u0440\u0435\u043d\u0434\u0435\u0440\u0430:<\/p>\n<pre><code>_particlesRender.Parameters[&quot;ParticleSampler&quot;].SetResource&lt;SamplerState&gt;(_particleSampler); _particlesRender.Parameters[&quot;ParticleTexture&quot;].SetResource&lt;Texture2D&gt;(_particleTexture);<\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/files\/1d5\/768\/f7a\/1d5768f7aa734f84a114375fa01b7f4e.png\"\/><\/p>\n<h1>\u0413\u043b\u0430\u0432\u0430 5: \u0414\u0432\u0438\u0436\u0435\u043d\u0438\u0435 \u0447\u0430\u0441\u0442\u0438\u0446<\/h1>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u0432\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u0441\u043e\u0431\u044b\u0439 \u0431\u0443\u0444\u0435\u0440 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 <i>GPU<\/i> \u0438 \u0435\u0441\u0442\u044c \u0440\u0435\u043d\u0434\u0435\u0440 \u0447\u0430\u0441\u0442\u0438\u0446, \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <i>Geometry Shader<\/i>, \u043d\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u2014 \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u0430. \u041c\u043e\u0436\u043d\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u0435\u043d\u044f\u0442\u044c \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u043d\u0430 <i>CPU<\/i>, \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0447\u0438\u0442\u0430\u0442\u044c \u0441 <i>GPU<\/i> \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u0443\u0444\u0435\u0440\u0430, \u043c\u0435\u043d\u044f\u0442\u044c \u0438\u0445, \u0430 \u043f\u043e\u0442\u043e\u043c \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u043e, \u043d\u043e \u043e \u043a\u0430\u043a\u043e\u0439 GPU Power \u043c\u043e\u0436\u0435\u0442 \u0438\u0434\u0442\u0438 \u0440\u0435\u0447\u044c? \u0422\u0430\u043a\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043d\u0435 \u0432\u044b\u0434\u0435\u0440\u0436\u0438\u0442 \u0438 100 000 \u0447\u0430\u0441\u0442\u0438\u0446.<\/p>\n<p>  \u0418 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430 <i>GPU<\/i> \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u0431\u0443\u0444\u0435\u0440\u0430\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0441\u043e\u0431\u044b\u0439 \u0448\u0435\u0439\u0434\u0435\u0440 \u2014 <b>Compute Shader<\/b>. \u041e\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432\u043d\u0435 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e <i>render-pipeline<\/i> \u0438 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e. <\/p>\n<p>  \u0427\u0442\u043e \u0436\u0435 \u0442\u0430\u043a\u043e\u0435 <i>Compute Shader<\/i>?<\/p>\n<p>  \u0421\u0432\u043e\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0448\u0435\u0439\u0434\u0435\u0440 (<i>Compute Shader<\/i>) \u2014 \u044d\u0442\u043e \u043e\u0441\u043e\u0431\u0430\u044f \u0441\u0442\u0430\u0434\u0438\u044f \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u0432\u0441\u0435 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0435 (\u043e\u0434\u043d\u0430\u043a\u043e \u0432\u0441\u0435 \u0435\u0449\u0435 \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043d\u0438\u043c), \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c <i>GPU<\/i>, \u0447\u0438\u0442\u0430\u0442\u044c\/\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0431\u0443\u0444\u0435\u0440\u044b (\u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u043d\u044b\u0435). \u041f\u0440\u0438\u0447\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0442\u0430\u043a \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e, \u043a\u0430\u043a \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a. <\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430:<\/p>\n<pre><code>[numthreads(1, 1, 1)] void DefaultCS( uint3 DTiD: SV_DispatchThreadID ) { \t\/\/ DTiD.xyz - \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043f\u043e\u0442\u043e\u043a \t\/\/ ... \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434 }  technique ComputeShader { \tpass DefaultPass \t{ \t\tProfile = 10.0; \t\tComputeShader = DefaultCS; \t} }<\/code><\/pre>\n<p>  \u0412 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u043a\u043e\u0434\u0430 \u0435\u0441\u0442\u044c \u043f\u043e\u043b\u0435 <b>numthreads<\/b>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043b-\u0432\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0432 \u0433\u0440\u0443\u043f\u043f\u0435. \u041f\u043e\u043a\u0430 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u0440\u0443\u043f\u043f\u043e\u0432\u044b\u0435 \u043f\u043e\u0442\u043e\u043a\u0438 \u0438 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043d\u0430 \u043e\u0434\u043d\u0443 \u0433\u0440\u0443\u043f\u043f\u0443 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u0441\u044f \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a.<br \/>  <i>uint3 DTiD.xyz<\/i> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043f\u043e\u0442\u043e\u043a.<\/p>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u044d\u0442\u0430\u043f \u2014 \u044d\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a \u0442\u0430\u043a\u043e\u0433\u043e \u0448\u0435\u0439\u0434\u0435\u0440\u0430, \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code>_effect.CurrentTechnique.Passes[0].Apply(); graphics.Dispatch(1, 1, 1);<\/code><\/pre>\n<p>  \u0412 \u043c\u0435\u0442\u043e\u0434\u0435 <i>Dispatch<\/i> \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u2014 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0433\u0440\u0443\u043f\u043f \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0443 \u043d\u0430\u0441 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c, \u043f\u0440\u0438\u0447\u0435\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b-\u0432\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e <u>65536<\/u>. \u0418 \u0435\u0441\u043b\u0438 \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434, \u0442\u043e \u043a\u043e\u0434 \u0448\u0435\u0439\u0434\u0435\u0440\u0430 \u043d\u0430 GPU \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u0442.\u043a. \u0443 \u043d\u0430\u0441 1 \u0433\u0440\u0443\u043f\u043f\u0430 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u0435 1 \u043f\u043e\u0442\u043e\u043a. \u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <i>Dispatch(5, 1, 1)<\/i> \u2014 \u043a\u043e\u0434 \u0448\u0435\u0439\u0434\u0435\u0440\u0430 \u043d\u0430 <i>GPU<\/i> \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u043f\u044f\u0442\u044c \u0440\u0430\u0437, 5 \u0433\u0440\u0443\u043f\u043f \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u0435 1 \u043f\u043e\u0442\u043e\u043a. \u0415\u0441\u043b\u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0435\u0449\u0435 \u0438 <i>numthreads -&gt; (5, 1, 1)<\/i>, \u0442\u043e \u043a\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f 25 \u0440\u0430\u0437, \u043f\u0440\u0438\u0447\u0435\u043c \u0432 5 \u0433\u0440\u0443\u043f\u043f \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u0433\u0440\u0443\u043f\u043f\u0435 5 \u043f\u043e\u0442\u043e\u043a\u043e\u0432. \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u0435\u0441\u043b\u0438 \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443:<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/files\/bc9\/dab\/3b9\/bc9dab3b953e4ff49f74f7f47975e0ec.png\"\/><\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u0432\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u043a \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0447\u0430\u0441\u0442\u0438\u0446, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c? \u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0437 1 000 000 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u2014 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0447\u0430\u0441\u0442\u0438\u0446. \u0422.\u043a. \u0447\u0430\u0441\u0442\u0438\u0446\u044b \u0434\u0432\u0438\u0436\u0443\u0442\u0441\u044f \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e \u0434\u0440\u0443\u0433 \u043e\u0442 \u0434\u0440\u0443\u0433\u0430, \u0442\u043e \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443 \u043c\u043e\u0436\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0442\u044c.<\/p>\n<p>  \u0412 <i>DX10<\/i> (\u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u0443 \u0432\u0435\u0440\u0441\u0438\u044e <i>CS<\/i> \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c, \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 <i>DX10<\/i> \u043a\u0430\u0440\u0442) \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b-\u0432\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043d\u0430 \u0433\u0440\u0443\u043f\u043f\u0443 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u2014 <u>768<\/u>, \u043f\u0440\u0438\u0447\u0435\u043c \u0432\u043e \u0432\u0441\u0435\u0445 \u0442\u0440\u0435\u0445 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f\u0445. \u042f \u0441\u043e\u0437\u0434\u0430\u044e <i>32 * 24 * 1 = 768<\/i> \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0432 \u0441\u0443\u043c\u043c\u0435 \u043d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u0433\u0440\u0443\u043f\u043f\u0443 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0442.\u0435. \u043d\u0430\u0448\u0430 \u043e\u0434\u043d\u0430 \u0433\u0440\u0443\u043f\u043f\u0430 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c <i>768<\/i> \u0447\u0430\u0441\u0442\u0438\u0446 (1 \u043f\u043e\u0442\u043e\u043a \u2014 1 \u0447\u0430\u0441\u0442\u0438\u0446\u0430). \u0414\u0430\u043b\u0435\u0435, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e \u0433\u0440\u0443\u043f\u043f \u043f\u043e\u0442\u043e\u043a\u043e\u0432 (\u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043e\u0434\u043d\u0430 \u0433\u0440\u0443\u043f\u043f\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 768 \u0447\u0430\u0441\u0442\u0438\u0446) \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c <i>N<\/i>-\u043e\u0435 \u043a\u043e\u043b-\u0432\u043e \u0447\u0430\u0441\u0442\u0438\u0446.<br \/>  \u041f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0435:<\/p>\n<pre><code>int numGroups = (PARTICLES_COUNT % 768 != 0) ? ((PARTICLES_COUNT \/ 768) + 1) : (PARTICLES_COUNT \/ 768); double secondRoot= System.Math.Pow((double)numGroups, (double)(1.0 \/ 2.0)); secondRoot= System.Math.Ceiling(secondRoot); _groupSizeX = _groupSizeY = (int)secondRoot;<\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u2014 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0437\u0432\u0430\u0442\u044c <b>Dispatch(_groupSizeX, _groupSizeY, 1)<\/b>, \u0438 \u0448\u0435\u0439\u0434\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431\u0435\u043d \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c N-\u043e\u0435 \u043a\u043e\u043b-\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>  \u0414\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0444\u043e\u0440\u043c\u0443\u043b\u0443:  <\/p>\n<pre><code>uint index = groupID.x * THREAD_IN_GROUP_TOTAL + groupID.y * GROUP_COUNT_Y * THREAD_IN_GROUP_TOTAL + groupIndex; <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0448\u0435\u0439\u0434\u0435\u0440\u0430:<\/p>\n<pre><code>struct Particle {     float3 Position;     float3 Velocity; };  cbuffer Handler : register(c0) { \tint GroupDim; \tuint MaxParticles; \tfloat DeltaTime; };  RWStructuredBuffer&lt;Particle&gt; Particles : register(u0);  #define THREAD_GROUP_X 32 #define THREAD_GROUP_Y 24 #define THREAD_GROUP_TOTAL 768  [numthreads(THREAD_GROUP_X, THREAD_GROUP_Y, 1)] void DefaultCS( uint3 groupID : SV_GroupID, uint groupIndex : SV_GroupIndex ) { \tuint index = groupID.x * THREAD_GROUP_TOTAL + groupID.y * GroupDim * THREAD_GROUP_TOTAL + groupIndex;  \t \t[flatten] \tif(index &gt;= MaxParticles) \t\treturn;  \tParticle particle = Particles[index];  \tfloat3 position = particle.Position; \tfloat3 velocity = particle.Velocity;          \/\/ payload  \tparticle.Position = position + velocity * DeltaTime; \tparticle.Velocity = velocity;  \tParticles[index] = particle; }  technique ParticleSolver { \tpass DefaultPass \t{ \t\tProfile = 10.0; \t\tComputeShader = DefaultCS; \t} }<\/code><\/pre>\n<p>  \u0422\u0443\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u043c\u0430\u0433\u0438\u044f, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043d\u0430\u0448 \u0431\u0443\u0444\u0435\u0440 \u0447\u0430\u0441\u0442\u0438\u0446 \u043a\u0430\u043a \u043e\u0441\u043e\u0431\u044b\u0439 \u0440\u0435\u0441\u0443\u0440\u0441: <i>RWStructuredBuffer<\/i>, \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u044d\u0442\u043e\u0442 \u0431\u0443\u0444\u0435\u0440.<br \/>  <b>(!)<\/b> \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u2014 \u044d\u0442\u043e\u0442 \u0431\u0443\u0444\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043f\u043e\u043c\u0435\u0447\u0435\u043d \u0444\u043b\u0430\u0433\u043e\u043c <i>UnorderedAccess<\/i>.<\/p>\n<p>  \u041d\u0443 \u0438 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u044d\u0442\u0430\u043f, \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0440\u0435\u0441\u0443\u0440\u0441 \u0434\u043b\u044f \u0448\u0435\u0439\u0434\u0435\u0440\u0430 \u043a\u0430\u043a <i>UnorderedAccessView<\/i> \u043d\u0430\u0448 \u0431\u0443\u0444\u0435\u0440 \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c <i>Dispatch<\/i>:<\/p>\n<pre><code>\/* SOLVE PARTICLES *\/ _particlesSolver.Parameters[&quot;GroupDim&quot;].SetValue(_threadGroupSize); _particlesSolver.Parameters[&quot;MaxParticles&quot;].SetValue(PARTICLES_COUNT); _particlesSolver.Parameters[&quot;DeltaTime&quot;].SetValue(deltaTime);  _particlesSolver.Parameters[&quot;Particles&quot;].SetResource&lt;SharpDX.Direct3D11.UnorderedAccessView&gt;(0, _particlesBuffer);  _particlesSolver.CurrentTechnique.Passes[0].Apply();  graphics.Dispatch( \t_threadSize, \t_threadSize, \t1);  _particlesSolver.CurrentTechnique.Passes[0].UnApply(false);<\/code><\/pre>\n<p>  <u>\u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0431\u0440\u0430\u0442\u044c <i>UnorderedAccessView<\/i> \u0441 \u0448\u0435\u0439\u0434\u0435\u0440\u0430, \u0438\u043d\u0430\u0447\u0435 \u043c\u044b \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u043c \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c!<\/u><\/p>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0441 \u0447\u0430\u0441\u0442\u0438\u0446\u0430\u043c\u0438, \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0441\u043e\u043b\u0432\u0435\u0440:<\/p>\n<pre><code>float3 _calculate(float3 anchor, float3 position) { \tfloat3 direction = anchor - position; \tfloat distance = length(direction); \tdirection \/= distance;  \treturn direction * max(0.01, (1 \/ (distance*distance))); }  \/\/ main { ... velocity += _calculate(Attractor, position); velocity += _calculate(-Attractor, position); ... }<\/code><\/pre>\n<p>  <i>Attractor<\/i> \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u0432 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u043e\u043c \u0431\u0443\u0444\u0435\u0440\u0435.<\/p>\n<p>  \u041a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0438 \u043b\u044e\u0431\u0443\u0435\u043c\u0441\u044f:<br \/>  <iframe loading=\"lazy\" width=\"560\" height=\"349\" src=\"\/\/www.youtube.com\/embed\/S-2HoaLT1E8?wmode=opaque\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<h1>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 1<\/h1>\n<p>  \u0415\u0441\u043b\u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u0447\u0430\u0441\u0442\u0438\u0446\u0430\u0445, \u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043c\u0435\u0448\u0430\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u0443\u044e \u0438 \u043c\u043e\u0449\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0447\u0430\u0441\u0442\u0438\u0446: \u0442\u043e\u0447\u043a\u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c (\u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0441\u0442\u0438), \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0442\u0435\u0445\u043d\u0438\u043a\u0443 <i>soft particles<\/i> \u043f\u0440\u0438 \u0440\u0438\u0441\u043e\u0432\u0430\u043d\u0438\u0438, \u0430 \u0442\u0430\u043a \u0436\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0441\u0432\u0435\u0449\u0435\u043d\u0438\u0435 \u00ab\u043d\u0435 \u0441\u0432\u0435\u0442\u044f\u0449\u0438\u0445\u0441\u044f\u00bb \u0447\u0430\u0441\u0442\u0438\u0446. \u0412\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0448\u0435\u0439\u0434\u0435\u0440\u044b \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0430 <b>Bokeh Blur<\/b> (\u0442\u0443\u0442 \u043d\u0443\u0436\u043d\u044b \u0435\u0449\u0435 \u0433\u0435\u043e\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0435), \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f <b>Tiled Deferred Renderer<\/b>, etc. \u0413\u0435\u043e\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0448\u0435\u0439\u0434\u0435\u0440\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0433\u0435\u043e\u043c\u0435\u0442\u0440\u0438\u0438. \u0421\u0430\u043c\u044b\u0439 \u044f\u0440\u043a\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u2014 \u0442\u0440\u0430\u0432\u0430 \u0438 \u0447\u0430\u0441\u0442\u0438\u0446\u044b. \u041a \u0441\u043b\u043e\u0432\u0443, \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 <i>GS<\/i> \u0438 <i>CS<\/i> \u0431\u0435\u0437\u0433\u0440\u0430\u043d\u0438\u0447\u043d\u044b \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u0444\u0430\u043d\u0442\u0430\u0437\u0438\u0435\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430.<\/p>\n<h1>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 2<\/h1>\n<p>  \u0422\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u043e \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u044f\u044e \u043a \u043f\u043e\u0441\u0442\u0443 \u043f\u043e\u043b\u043d\u044b\u0439 <a href=\"https:\/\/yadi.sk\/d\/avC_NGujeDMhr\">\u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434<\/a> \u0438 <a href=\"https:\/\/yadi.sk\/d\/oP3PPrOveDMgm\">\u0434\u0435\u043c\u043e<\/a>.<\/p>\n<h1>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 3<\/h1>\n<p>  <i>\u041c\u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u0438\u044f\u0442\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u043b\u044e\u0434\u0438 \u043f\u0440\u043e\u044f\u0432\u043b\u044f\u044e\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441 \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u044f \u043f\u0438\u0448\u0443. \u0418 \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u0430 \u0440\u0435\u0430\u043a\u0446\u0438\u044f \u043d\u0430 \u0441\u0442\u0430\u0442\u044c\u044e, \u0431\u0443\u0434\u044c \u043e\u043d\u0430 \u0432 \u0432\u0438\u0434\u0435 \u043f\u043b\u044e\u0441\u0430 \u0438\u043b\u0438 \u043c\u0438\u043d\u0443\u0441\u0430 \u0441 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u043c. \u0422\u0430\u043a \u044f \u0441\u043c\u043e\u0433\u0443 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u2014 \u043a\u0430\u043a\u0438\u0435 \u0442\u0435\u043c\u044b \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b \u0445\u0430\u0431\u0440\u0430\u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0443, \u0430 \u043a\u0430\u043a\u0438\u0435 \u043d\u0435\u0442.<\/i>      \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/248755\/\"> http:\/\/habrahabr.ru\/post\/248755\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">     \t\u041f\u0440\u0438\u0432\u0435\u0442, \u0434\u043e\u0440\u043e\u0433\u043e\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c!<\/p>\n<p>  \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440\u0430, \u0438 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0442\u0430\u043a\u0438\u0445 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0432\u0435\u0449\u0430\u0445, \u043a\u0430\u043a <b>Compute Shader<\/b> \u0438 <b>Geometry Shader<\/b> \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0430 <b>1000000+<\/b> \u0447\u0430\u0441\u0442\u0438\u0446, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435 \u0442\u043e\u0447\u043a\u0430\u043c\u0438, \u0430 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0430\u043c\u0438 (<i>billboard quads<\/i>) \u0438 \u0438\u043c\u0435\u044e\u0442 \u0441\u0432\u043e\u044e \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0443. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043c\u044b \u0432\u044b\u0432\u0435\u0434\u0435\u043c <b>2000000+<\/b> \u0442\u0435\u043a\u0441\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0442\u0440\u0435\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a\u043e\u0432 \u043f\u0440\u0438 <b>FPS &gt; 100<\/b> (\u043d\u0430 \u0431\u044e\u0434\u0436\u0435\u0442\u043d\u043e\u0439 \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0440\u0442\u0435 <i>GeForce 550 Ti<\/i>).<\/p>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/files\/740\/6a1\/afc\/7406a1afcd474664b90678520b39ae41.png\"\/>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-248755","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/248755","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=248755"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/248755\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=248755"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=248755"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=248755"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}