top of page

Render a colorful triangle and add Lua to the build process

  • itzvnodm
  • Sep 16, 2014
  • 2 min read

Purpose:

The assignment was to

  • Understand and complete the graphics pipeline to render a triangle of three different colored edges with interpolation.

  • Integrate Lua to the asset builder project and Learn Lua function calls.

  • Modify the Asset Builder to call Lua function to implement the underlying build logic.

Program output:

Triangle Screenshot.PNG

Pipeline:

The vertex coordinates are given to GPU using the DrawPrimitive function call. Vertex shader takes 3 sets of 3D coordinates as input with any other user data (Color in our case) and outputs the 2D screen space positions. GPU interpolates the output color (user data) from vertex shader. Fragment shader computes what color each pixel should be on the screen.

screen-shot-2010-03-09-at-2-13-26-pm.png

PIX Output:

The below screenshot of PIX shows the details of 7th frame that was captured. In Events tab, PIX shows all the DirectX calls in that frame. DrawPrimitive call renders a sequence of nonindexed triangle from the input vertices on the screen using the Vertex shader and the Fragment shader.

Pix Screenshot.PNG

Events tab:

EventsTab.PNG

Details tab:

Mesh->PreVS, shows input vertex values and any other user data (Color in our case) that was passed to Vertex shader by GPU.

PreVS.PNG

PostVS shows the position output by the vertex shader.

PostVS.PNG

Parts that gave me trouble:

The output triangle color did not match with the input color values. Using PIX capture, I could find out what wrong input values were being sent to the GPU.

Fix: Debugging the source of wrong input values, I could find that Offset in D3DVERTEXELEMENT9 was not properly set in case of D3DDECLTYPE_D3DCOLOR.

Integrating Lua and other changes to project:

We had to integrate Lua capability to our project. Lua function is used to build assets, which in turn called the C++ function to implement the underlying build logic. Part of the reason we are doing this is because scripting in Lua is easier and faster to iterate. Lua source code is added as a project that compiles and builds static lib. Asset Builder used this static lib to load a lua script file and call its funcitons.

Parts that gave me trouble:

Understanding the stack push and pop in Lua when Lua calls C++ functions and when C++ calls Lua functions took some time. The sample code from John-Paul was really helpful and I am glad that he chose to write it for us.

Time Spent:

Understanding the process and Rendering the colored triangle: 1hr

Understanding Lua requirement for the assignment: 2hr

Integrating Lua: 1hr

Modifying the Asset Builder to use Lua: 5hr

Writeup: 1.5hr

Total: 10.5hr


 
 
 

Comments


Recent Posts
Archive
Search By Tags
bottom of page