Warlocks - Day 5 and 6Day 5 was a low point, which is why I didn't add a diary entry. I felt that the thing missing from our day 4 screenshots was light. The spells look strangely false, disconnected from the world. So I decided to play around with GLSL shaders to do per-pixel lighting. The reason it was a low point is though I managed to set up a light accumulation buffer system with a sizeable amount of help from internet research, I hit a wall trying to get the lights to appear in the right positions in space.
I salvaged one screenshot of the light accumulation buffer even with the wrong light positions:
This buffer contains the contributions of a red light and a green light. By adding more passes I can sum an arbitrary number of lights. Then there is a pass to draw the textures multiplied by the light buffer, then a pass to draw in the particles, unshaded.
After about 4 hours of banging my head against the wall, I cracked getting the lights to appear in the right places, with the help of pencil-and-paper sketches, a lot of thinking, a lot of trial and error, and finally some nosetests. The nosetests are what broke the back of it, but the thinking and sketches were vital too, and I implemented camera movement and various other things to help get a handle on the problem. There were a succession of breakthroughs:
- To use normals in shaders they have to be transformed with gl_NormalMatrix. Duh.
- Shaders are all about converting to eye space. Don't try to convert backwards to world space. Duh.
- Euclid's Vector3 instances aren't multiplied correctly by a Matrix4. You need to use Point3. Fuuuu...
- The documentation for gluLookAt() contains at least one mistake - two if I understand the modelview matrix system correctly. Fuuu...
Anyway, with the satisfaction of having cracked the lighting problem, I rebuilt the spell effects with light:
These are per-pixel effects so in principle they could be modified with normal maps. I've thrown away the specular component in the original shaders, it didn't suit the subject matter.
So we're behind on writing a game, but with one big day left we might get something playable. I've learned a lot, in any case.