Skip navigation

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

Leave a Reply