{"id":82,"date":"2014-12-13T00:35:39","date_gmt":"2014-12-12T22:35:39","guid":{"rendered":"http:\/\/heikkili.kapsi.fi\/blog\/?p=82"},"modified":"2017-01-24T13:09:59","modified_gmt":"2017-01-24T11:09:59","slug":"cg-study-3","status":"publish","type":"post","link":"http:\/\/heikkili.kapsi.fi\/blog\/?p=82","title":{"rendered":"DirectX 11 Book chapter 6"},"content":{"rendered":"<p>I did some Exercises from Directx 11 book chapter 6 Drawing in DirectX.<\/p>\n<p>Some more interesting screenshots and some code snippets from exercises.<\/p>\n<p><strong>ex.4<\/strong><\/p>\n<p><a href=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturech6ex4.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"84\" data-permalink=\"http:\/\/heikkili.kapsi.fi\/blog\/?attachment_id=84\" data-orig-file=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturech6ex4.png?fit=538%2C510\" data-orig-size=\"538,510\" 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=\"Capturech6ex4\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturech6ex4.png?fit=300%2C284\" data-large-file=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturech6ex4.png?fit=538%2C510\" tabindex=\"0\" role=\"button\" class=\"alignnone size-thumbnail wp-image-84\" src=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturech6ex4.png?resize=150%2C150\" alt=\"Capturech6ex4\" width=\"150\" height=\"150\" srcset=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturech6ex4.png?resize=150%2C150 150w, https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturech6ex4.png?zoom=2&amp;resize=150%2C150 300w, https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturech6ex4.png?zoom=3&amp;resize=150%2C150 450w\" sizes=\"(max-width: 150px) 100vw, 150px\" \/><\/a><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n \/\/ The Pyramid\r\n Vertex verticesP&#x5B;] =\r\n\t{\r\n\t\t{ XMFLOAT3(-1.0f, -1.0f, -1.0f), (const float*)&amp;Colors::Green },\r\n\t\t{ XMFLOAT3(-1.0f, -1.0f, 1.0f), (const float*)&amp;Colors::Green },\r\n\t\t{ XMFLOAT3(+1.0f, -1.0f, 1.0f), (const float*)&amp;Colors::Green },\r\n\t\t{ XMFLOAT3(+1.0f, -1.0f, -1.0f), (const float*)&amp;Colors::Green },\r\n\t\t{ XMFLOAT3(0.0f, 1.5f, 0.0f), (const float*)&amp;Colors::Red }\r\n\t};\r\n\r\n\t\/\/ Create the index buffer\r\n\tUINT indicesP&#x5B;] = {\r\n\t\t\/\/ bottom\r\n\t\t2, 1, 0,\r\n\t\t3, 2, 0,\r\n\r\n\t\t\/\/ sides\r\n\t\t0, 1, 4,\r\n\t\t1, 2, 4,\r\n\t\t2, 3, 4,\r\n\t\t3, 0, 4\r\n\t};\r\n<\/pre>\n<p><strong>ex.6<\/strong><br \/>\nSimple cube animation on vertex shader.<br \/>\nAdded code to C++<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\r\n\/\/ member variable for time\r\nID3DX11EffectScalarVariable* mfxTime;\r\n\r\n\/\/ in BuildFX()\r\nmfxTime = mFX-&gt;GetVariableByName(&quot;gTime&quot;)-&gt;AsScalar();\r\n\r\n\/\/...\r\n\r\n\/\/ in Draw()\r\nmfxTime-&gt;SetFloat(mTimer.TotalTime());\r\n\r\n<\/pre>\n<p>shader code:<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\ncbuffer cbPerFrame\r\n{\r\n\tfloat gTime;\r\n};\r\n\r\nVertexOut VS(VertexIn vin)\r\n{\r\n\tVertexOut vout;\r\n\r\n\t\/\/ ch.6 ex.6\r\n\tvin.PosL.xy += 0.5f*sin(vin.PosL.x)*sin(3.0f*gTime);\r\n\tvin.PosL.z *= 0.6f + 0.4f*sin(2.0f*gTime);\r\n\r\n\t\/\/ Transform to homogeneous clip space.\r\n\tvout.PosH = mul(float4(vin.PosL, 1.0f), gWorldViewProj);\r\n\r\n\t\/\/ Just pass vertex color into the pixel shader.\r\n    vout.Color = vin.Color;\r\n\r\n    return vout;\r\n}\r\n\r\n<\/pre>\n<p><strong>ex. 13<\/strong><br \/>\nSetting and using scissor test.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturech6ex13.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"88\" data-permalink=\"http:\/\/heikkili.kapsi.fi\/blog\/?attachment_id=88\" data-orig-file=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturech6ex13.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=\"Capturech6ex13\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturech6ex13.png?fit=300%2C234\" data-large-file=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturech6ex13.png?fit=650%2C509\" tabindex=\"0\" role=\"button\" class=\"alignnone size-medium wp-image-88\" src=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturech6ex13.png?resize=300%2C234\" alt=\"Capturech6ex13\" width=\"300\" height=\"234\" srcset=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturech6ex13.png?resize=300%2C234 300w, https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturech6ex13.png?resize=383%2C300 383w, https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturech6ex13.png?w=816 816w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n  D3D11_RASTERIZER_DESC wireframeDesc;\r\n\tZeroMemory(&amp;wireframeDesc, sizeof(D3D11_RASTERIZER_DESC));\r\n\twireframeDesc.FillMode = D3D11_FILL_WIREFRAME;\r\n\twireframeDesc.CullMode = D3D11_CULL_BACK;\r\n\twireframeDesc.FrontCounterClockwise = false;\r\n\twireframeDesc.DepthClipEnable = true;\r\n\twireframeDesc.ScissorEnable = true;\r\n\r\n\tHR(md3dDevice-&gt;CreateRasterizerState(&amp;wireframeDesc, &amp;mWireframeRS));\r\n\r\n\tD3D11_RECT rects = { 100, 100, 400, 400 };\r\n\tmd3dImmediateContext-&gt;RSSetScissorRects(1, &amp;rects);\r\n<\/pre>\n<p><strong>ex. 14<\/strong><br \/>\nGeoSphere with different subdivision levels. Subdivision levels: 0, 1 and 3.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs0.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"90\" data-permalink=\"http:\/\/heikkili.kapsi.fi\/blog\/?attachment_id=90\" data-orig-file=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs0.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=\"Capturegs0\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs0.png?fit=300%2C234\" data-large-file=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs0.png?fit=650%2C509\" tabindex=\"0\" role=\"button\" class=\"alignleft size-thumbnail wp-image-90\" src=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs0.png?resize=150%2C150\" alt=\"Capturegs0\" width=\"150\" height=\"150\" srcset=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs0.png?resize=150%2C150 150w, https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs0.png?zoom=2&amp;resize=150%2C150 300w, https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs0.png?zoom=3&amp;resize=150%2C150 450w\" sizes=\"(max-width: 150px) 100vw, 150px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs1.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"91\" data-permalink=\"http:\/\/heikkili.kapsi.fi\/blog\/?attachment_id=91\" data-orig-file=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs1.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=\"Capturegs1\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs1.png?fit=300%2C234\" data-large-file=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs1.png?fit=650%2C509\" tabindex=\"0\" role=\"button\" class=\"alignleft size-thumbnail wp-image-91\" src=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs1.png?resize=150%2C150\" alt=\"Capturegs1\" width=\"150\" height=\"150\" srcset=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs1.png?resize=150%2C150 150w, https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs1.png?zoom=2&amp;resize=150%2C150 300w, https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs1.png?zoom=3&amp;resize=150%2C150 450w\" sizes=\"(max-width: 150px) 100vw, 150px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs3.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"92\" data-permalink=\"http:\/\/heikkili.kapsi.fi\/blog\/?attachment_id=92\" data-orig-file=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs3.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=\"Capturegs3\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs3.png?fit=300%2C234\" data-large-file=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs3.png?fit=650%2C509\" tabindex=\"0\" role=\"button\" class=\"alignleft size-thumbnail wp-image-92\" src=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs3.png?resize=150%2C150\" alt=\"Capturegs3\" width=\"150\" height=\"150\" srcset=\"https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs3.png?resize=150%2C150 150w, https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs3.png?zoom=2&amp;resize=150%2C150 300w, https:\/\/i0.wp.com\/heikkili.kapsi.fi\/blog\/wp-content\/uploads\/2014\/12\/Capturegs3.png?zoom=3&amp;resize=150%2C150 450w\" sizes=\"(max-width: 150px) 100vw, 150px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I did some Exercises from Directx 11 book chapter 6 Drawing in DirectX. Some more interesting screenshots and some code snippets from exercises. ex.4 \/\/ The Pyramid Vertex verticesP&#x5B;] = { { XMFLOAT3(-1.0f, -1.0f, -1.0f), (const float*)&amp;Colors::Green }, { XMFLOAT3(-1.0f, -1.0f, 1.0f), (const float*)&amp;Colors::Green }, { XMFLOAT3(+1.0f, -1.0f, 1.0f), (const float*)&amp;Colors::Green }, { XMFLOAT3(+1.0f, -1.0f,&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":[1],"tags":[2],"class_list":["post-82","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-directx11"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p7k3DT-1k","_links":{"self":[{"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=\/wp\/v2\/posts\/82"}],"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=82"}],"version-history":[{"count":15,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=\/wp\/v2\/posts\/82\/revisions"}],"predecessor-version":[{"id":245,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=\/wp\/v2\/posts\/82\/revisions\/245"}],"wp:attachment":[{"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=82"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=82"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=82"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}