Lit

Hoo, boy, that was annoying. I’ve been trying to get lighting working for a little while and kept shooting myself in the foot multiple times by not going back and carefully checking what I wrote. To begin with, I was transforming the normals I had by the world matrix for the purposes of debugging and stored them in a separate debug normals array. Unfortunately, I didn’t double-check that I was modifying the actual normals… This led to the normals behaving strangely, to say the least. From the first screenshot, you can see the result of this. In the second one, I made things a bunch worse by calculating the position of the normals with the World*View matrix. A few hours after trying to fix what I thought was broken, I stopped.

Normals aren't quite right Normals definitely aren't quite right

The next day, it took about an hour to figure out what I was doing wrong. In conjunction with inverting the directional light’s world rotation matrix to get it into the same object space as the cube, I was also transforming the normals in the previous stage of getting the normals to render for debugging purposes. The normals were also a little off in Maya. I averaged them with Maya, but they seemed ever so slightly off. As it’s just a cube, I adjusted the normals manually and got the result I was looking for. Below are a few screenshots of the directional lighting along with one screenshot of the normals behaving… normally (sorry, I couldn’t resist).

Cube with a light at the top Cube with a light at the top-left Cube with a light at the bottom-right Lit cube with the normals showing

The lighting code only supports directional lighting. I’m going to clean up what I have, define a better interface for lighting (such as having one function to apply the light, instead of one for directional, point, and spot lights), and get more than one mesh in a model file. After that, I’ll hop back to the networking code, though I may take a diversion over to the backup storage and allow for saving/loading player data.