{"id":152,"date":"2015-01-08T21:51:29","date_gmt":"2015-01-08T19:51:29","guid":{"rendered":"http:\/\/heikkili.kapsi.fi\/blog\/?p=152"},"modified":"2024-09-15T14:15:58","modified_gmt":"2024-09-15T12:15:58","slug":"cg-study-9","status":"publish","type":"post","link":"http:\/\/heikkili.kapsi.fi\/blog\/?p=152","title":{"rendered":"CG study #9"},"content":{"rendered":"<p>I am back to this small project of doing exercises from the dx11 book. This time chapter 12 The Compute Shader. First three exercises asked to count length of 3d vectors from a structured buffers and from buffers of data etc.<\/p>\n<p>Exercise 4 asked to study Bilateral blur and redo the blur demo with it.<\/p>\n<p>I am not sure if I got it right but here is a screen shot:<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2015\/01\/CaptureCh12ex4.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"155\" data-permalink=\"http:\/\/heikkili.kapsi.fi\/blog\/?attachment_id=155\" data-orig-file=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2015\/01\/CaptureCh12ex4.png?fit=816%2C639\" data-orig-size=\"816,639\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"CaptureCh12ex4\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2015\/01\/CaptureCh12ex4.png?fit=300%2C235\" data-large-file=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2015\/01\/CaptureCh12ex4.png?fit=650%2C509\" tabindex=\"0\" role=\"button\" class=\"alignleft size-thumbnail wp-image-155\" src=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2015\/01\/CaptureCh12ex4.png?resize=150%2C150\" alt=\"CaptureCh12ex4\" width=\"150\" height=\"150\" srcset=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2015\/01\/CaptureCh12ex4.png?resize=150%2C150 150w, https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2015\/01\/CaptureCh12ex4.png?zoom=2&amp;resize=150%2C150 300w, https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2015\/01\/CaptureCh12ex4.png?zoom=3&amp;resize=150%2C150 450w\" sizes=\"(max-width: 150px) 100vw, 150px\" \/><\/a><\/p>\n<p>ex 5 was about implementing previous wave simulation on gpu. Hints where given about textures to store solutions and about two computations first to update the wave and second to disturb the waves. Also the code to render the wave was given.<\/p>\n<p>It was easy to create two shaders to update and disturb wave by looking the original cpu code<\/p>\n<p>wave updated on cpu:<\/p>\n<pre><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nfor(UINT i = 1; i &amp;amp;lt; mNumRows-1; ++i)\n\t{\n\t\tfor(UINT j = 1; j &amp;amp;lt; mNumCols-1; ++j)\n\t\t{\n\n\t\t\tmPrevSolution&#x5B;i*mNumCols+j].y =\n\t\t\t\tmK1*mPrevSolution&#x5B;i*mNumCols+j].y +\n\t\t\t\tmK2*mCurrSolution&#x5B;i*mNumCols+j].y +\n\t\t\t\tmK3*(mCurrSolution&#x5B;(i+1)*mNumCols+j].y +\n\t\t\t\t     mCurrSolution&#x5B;(i-1)*mNumCols+j].y +\n\t\t\t\t     mCurrSolution&#x5B;i*mNumCols+j+1].y +\n\t\t\t\t\t mCurrSolution&#x5B;i*mNumCols+j-1].y);\n\t\t}\n\t}\n<\/pre>\n<p>This on GPU:<\/p>\n<pre><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n\/\/ mK1,2,3 in waveConst\nint x = dispatchThreadID.x;\nint y = dispatchThreadID.y;\n\ngNextSolOutput&#x5B;int2(x,y)] =\n\tgWaveConst&#x5B;0]* gPrevSolInput&#x5B;int2(x,y)].r +\n\tgWaveConst&#x5B;1]* gCurrSolInput&#x5B;int2(x,y)].r +\n\tgWaveConst&#x5B;2]*(\n\t\tgCurrSolInput&#x5B;int2(x,y+1)].r +\n\t\tgCurrSolInput&#x5B;int2(x,y-1)].r +\n\t\tgCurrSolInput&#x5B;int2(x+1,y)].r +\n\t\tgCurrSolInput&#x5B;int2(x-1,y)].r);\n<\/pre>\n<p>disturb the wave from cpu solution:<\/p>\n<pre><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nfloat halfMag = 0.5f*magnitude;\n\n\/\/ Disturb the ijth vertex height and its neighbors.\nmCurrSolution&#x5B;i*mNumCols+j].y     += magnitude;\nmCurrSolution&#x5B;i*mNumCols+j+1].y   += halfMag;\nmCurrSolution&#x5B;i*mNumCols+j-1].y   += halfMag;\nmCurrSolution&#x5B;(i+1)*mNumCols+j].y += halfMag;\nmCurrSolution&#x5B;(i-1)*mNumCols+j].y += halfMag;\n<\/pre>\n<p>On GPU:<\/p>\n<pre><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\nint x = gIndex.x;\nint y = gIndex.y;\n\nfloat halfMag = 0.5f*gMagnitude;\n\ngCurrSolOutput&#x5B;int2(x,y)]   += gMagnitude;\ngCurrSolOutput&#x5B;int2(x+1,y)] += halfMag;\ngCurrSolOutput&#x5B;int2(x-1,y)] += halfMag;\ngCurrSolOutput&#x5B;int2(x,y+1)] += halfMag;\ngCurrSolOutput&#x5B;int2(x,y-1)] += halfMag;\n<\/pre>\n<p>FPS with gpu solution went from 70 to ~700fps .<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am back to this small project of doing exercises from the dx11 book. This time chapter 12 The Compute Shader. First three exercises asked to count length of 3d vectors from a structured buffers and from buffers of data etc. Exercise 4 asked to study Bilateral blur and redo the blur demo with it.&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6],"tags":[4,2],"class_list":["post-152","post","type-post","status-publish","format-standard","hentry","category-computer-graphics","tag-c","tag-directx11"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p7k3DT-2s","_links":{"self":[{"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=\/wp\/v2\/posts\/152"}],"collection":[{"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=152"}],"version-history":[{"count":10,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=\/wp\/v2\/posts\/152\/revisions"}],"predecessor-version":[{"id":641,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=\/wp\/v2\/posts\/152\/revisions\/641"}],"wp:attachment":[{"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}