Przeglądaj źródła

Fixed the draw lines of Dynamic Draw sample and updated the sceenshot. (#126)

Qing Tao 4 lat temu
rodzic
commit
fd354e2632

+ 33 - 16
Gem/Code/Source/DynamicDrawExampleComponent.cpp

@@ -138,22 +138,32 @@ namespace AtomSampleViewer
         const uint32_t TetrahedronIndexCount = 12;
         const uint32_t TetrahedronWireframeIndexCount = 6;
 
+        float positions[4][3] =
+        {
+            { 0.2, 0.2f, 0.2f },
+            { 0.2, -0.2f, -0.2f },
+            { -0.2, 0.2f, -0.2f },
+            { -0.2, -0.2f, 0.2f }
+        };
+
+        float colors[4][4] = { { 1, 0, 0, 0.5f }, { 0, 1, 0, 0.5f }, { 0, 0, 1, 0.5f }, {1, 1, 0, 0.5f}};
+
         ExampleVertex tetrahedronVerts[TetrahedronVertexCount] = {
-            {0.2, 0.2f, 0.2f,       1, 0, 0, 0.5f}, // 0
-            {-0.2, -0.2f, 0.2f,     1, 0, 0, 0.5f}, // 3
-            {0.2, -0.2f, -0.2f,     1, 0, 0, 0.5f}, // 1
+            ExampleVertex{positions[0], colors[0]}, // 0
+            ExampleVertex{positions[3], colors[0]}, // 3
+            ExampleVertex{positions[1], colors[0]}, // 1
 
-            {0.2, 0.2f, 0.2f,       0, 1, 0, 0.5f}, // 0
-            {0.2, -0.2f, -0.2f,     0, 1, 0, 0.5f}, // 1
-            {-0.2, 0.2f, -0.2f,     0, 1, 0, 0.5f}, // 2
+            ExampleVertex{positions[0], colors[1]}, // 0
+            ExampleVertex{positions[1], colors[1]}, // 1
+            ExampleVertex{positions[2], colors[1]}, // 2
 
-            {0.2, 0.2f, 0.2f,       0, 0, 1, 0.5f}, // 0
-            {-0.2, 0.2f, -0.2f,     0, 0, 1, 0.5f}, // 2
-            {-0.2, -0.2f, 0.2f,     0, 0, 1, 0.5f}, // 3
+            ExampleVertex{positions[0], colors[2]}, // 0
+            ExampleVertex{positions[2], colors[2]}, // 2
+            ExampleVertex{positions[3], colors[2]}, // 3
 
-            {0.2, -0.2f, -0.2f,     1, 1, 0, 0.5f}, // 1
-            {-0.2, -0.2f, 0.2f,     1, 1, 0, 0.5f}, // 3
-            {-0.2, 0.2f, -0.2f,     1, 1, 0, 0.5f}  // 2
+            ExampleVertex{positions[1], colors[3]}, // 1
+            ExampleVertex{positions[3], colors[3]}, // 3
+            ExampleVertex{positions[2], colors[3]} // 2
         };
         u16 tetrahedronIndices[TetrahedronIndexCount] = {
             0, 1, 2,
@@ -162,14 +172,21 @@ namespace AtomSampleViewer
             9, 10, 11
         };
 
+        ExampleVertex tetrahedronWireFrameVerts[4] = {
+            ExampleVertex{ positions[0], colors[0] },
+            ExampleVertex{ positions[1], colors[1] }, 
+            ExampleVertex{ positions[2], colors[2] }, 
+            ExampleVertex{ positions[3], colors[3] }
+        };
+
         u16 tetrahedronWireframeIndices[TetrahedronIndexCount] =
         {
             0, 1,
             0, 2,
-            0, 4,
+            0, 3,
             1, 2,
-            2, 4,
-            4, 1
+            2, 3,
+            3, 1
         };
 
         // Enable depth test and write
@@ -228,7 +245,7 @@ namespace AtomSampleViewer
             drawSrg->SetConstant(index, Vector3(xPos, 0, 0));
             drawSrg->Compile();
             m_dynamicDraw->SetPrimitiveType(RHI::PrimitiveTopology::LineList);
-            m_dynamicDraw->DrawIndexed(tetrahedronVerts, TetrahedronVertexCount, tetrahedronWireframeIndices, TetrahedronIndexCount, RHI::IndexFormat::Uint16, drawSrg);
+            m_dynamicDraw->DrawIndexed(tetrahedronWireFrameVerts, 4, tetrahedronWireframeIndices, TetrahedronIndexCount, RHI::IndexFormat::Uint16, drawSrg);
             m_dynamicDraw->SetPrimitiveType(RHI::PrimitiveTopology::TriangleList);
         }
 

+ 7 - 2
Gem/Code/Source/DynamicDrawExampleComponent.h

@@ -51,8 +51,13 @@ namespace AtomSampleViewer
     private:
         struct ExampleVertex
         {
-            float x, y, z;
-            float r, g, b, a;
+            ExampleVertex(float position[3], float color[4])
+            {
+                memcpy(m_position, position, sizeof(float)*3);
+                memcpy(m_color, color, sizeof(float)*4);
+            }
+            float m_position[3];
+            float m_color[4];
         };
 
         AZ::RHI::Ptr<AZ::RPI::DynamicDrawContext> m_dynamicDraw;

+ 2 - 2
Scripts/ExpectedScreenshots/DynamicDraw/screenshot_1.png

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:5a0c651a0404f21efd33f3e690c7dc913d3a33c8488d9228a64447596d7d2b61
-size 13328
+oid sha256:03c1e2f08023c1cf5169c3e72807afda57d4e92d679690b20fd73f64a112323b
+size 14358