Skip navigation

Monthly Archives: November 2014

File Link(.exe)

Click Me


In this assignment, I leaned how the lighting works in video game rendering as well as implemented a diffuse light demo.

Lighting and Normals

My step of lighting the model:

1. I added lines of code to make my Maya exporter plug-in export the normal data, and changed code of my MeshBuilder so it will load my human-readable mesh.lua file to binary mesh file with normal data.

2. I expended space of my vertex structure to include the normal information, which is actually 3 float (12 bytes). then register the new vertex format to DirectX 3D.

3. My vertex shader now changed to calculate and output the local normal data  world space.

4. My pixel shader now has constants to pass 3 values: the color of ambient light, the color of direction light and the direction of the direction light. I use those them and the world space normal data to calculate the final light color.


5. And at last in my pixel shader I combine the light color with the texture pixel to get and output the final color.

This is what my demo looks like:

left: no lighting

right: with lighting




Debug the fragment shader

Steps to debug a pixel

1. enter a draw call in PIX

2. In the render tag of Details window, right click a pixel to debug

3. In the Debugger, click the link of the pixel to view the source code.


Time estimation

Reading and searching — 0.5 h
Coding / Debugging — 1 h
Writing blog — 1 h
Total — 2.5 h

File Link(.exe)

Click Me


In this assignment,I learned:

1. how to create a maya plug-in to export the mesh data from maya to my custom lua format.

2. Using setting file to configure the game.

3. How to use PIX instrumentation

Export Model from Maya

I made a maya export plug-in to export meshes to my custom mesh format:

1. I coded the export plug-in based on Maya API. The Maya API can automatically collect mesh data from Maya for me. So I just call its functions to get the data and output them as my own file format, which is actually a lua file that return a table to indicate the mesh.I configured it to build a x64 version in Build->Configuration Manager since I’m using the x64 version Maya.

2. I made Visual Studio to put my plug-in to the Maya plug-in folder after building. And enable my plug-in in Window->Settings/Preferences->Plug-in Manager in Maya to make sure my plug-in is running.

3. I downloaded a free licence model, import it into Maya and export it to my custom format with my Maya. Then I build it with my mesh builder and load it to show in the scene in the game.The model in my game looks like this:




Maya’s coordinate system is different to default D3D, There are some changes I made while exporting

1. Position : x,y, -z

2. Normal: nx,ny,-nz

3.Texture Coord : u, 1.0 – v

PIX instrumentation

I added my custom “event” to make the PIX show the information more organized. I used  D3DPERF_BeginEvent() and D3DPERF_EndEvent() to wrap my material setting and draw function. that’s what they look like in PIX:


User Settings


I added a user settings file to my project which will be copy to the root folder of my final game and will be loaded when the game is initializing. The user settings file provided information about some options to initialize the game, such as window size and full screen mode option.

Time estimation

Reading and searching — 2.5 h
Coding / Debugging — 6 h
Writing blog — 1 h
Total — 9.5 h

File Link(.exe)

Click Me


The assignment 07 wants me to custom my own mesh format as a lua file and to make the project to generate binary version of mesh data in the building process. Then, we should be able to read the binary mesh file in run-time and display it as before.

The assignment 08 basically asked me to add texture to the mesh in run-time. We need to build the images to the target file format(“.dds”) with texture builder, load them in game and add the textures to the mesh according to the texcoords of vertices of the mesh.

My Mesh File Format  

I have customed my personal mesh file format, which looks like this:


The comments explain the details about this format. the format has three main parts: First one is the metadata, which can tell some basic information about this file such as name and numbers of vertex and triangle. The second parts is vertices, which contains the list of all vertices of this mesh. The last part is triangles, which has the triangle list of this mesh.

Add Texture to the game world!


In order to add texture on the mesh, there are several steps I did. First of all, I make the engine convert all of the image files to dds file during the building process with TextureBuilder, then I add lines in the material to indicate the texture file path and the name of the sampler. The next step is to add texture coordinates for each vertex of the mesh, which will tell the shader how the texture “pin” on the mesh. At last I ask DirectX to pass the texcoords and textures to the GPU and add  codes to fragment shader to render the texture on the mesh.

This is what the game looks like now and the screenshot in PIX.


screen game

scrren pix

Time estimation

Reading and searching — 3 h
Coding / Debugging — 6 h
Writing blog — 0.5 h
Total — 9.5 h