1. Implement diffuse lighting.
2. Learn how to debug fragment shader.
Add Normals to Meshes
My Maya plug-in can export normal information of each vertex, so all I need to do is to add this information when I write the binary mesh file and change my D3DVERTEXELEMENT9 struct.
Ambient and Diffuse Lighting Models
In an ambient lighting model, all light beams fall uniformly from all directions onto an object. This leads to:
color = original_color * ambient_intensity * ambient_color
In a diffuse lighting model, the direction of the light is considered but the reflections are independent of the observer’s position.
Diffuse lighting model follows Lambert’s law and this leads to:
color = original_color * diffuse_intensity * diffuse_color * cos alpha
To use this formula the normal vectors of the object and the direction vector of diffuse light needs to be normalized.
Here is a screenshot of my program:
Use I, K, J, L to move the light.
To modify the ambient light and the diffuse light, change the values in Asserts/demo.scene.
Use PIX To Debug Fragment Shader
To debug a fragment shader:
1) Select the drawcall you’d like to debug
2) In “Render” tab right-click the pixel and choose “Debug This Pixel”
3) Click the “Debug Pixel (x, y)” link
- Reading – 1 hours
- Coding – 2 hours
- Write up – 1 hours
- Total – 4 hours