CS488 Project Log
Jeremy Sharpe (ja3sharp, 20250138) - ďSaxophone HeroĒ
Wednesday Nov 17, 3:34 PM
I am starting a bit later than I would have liked, but Iíve finally begun work on my final project for CS 488.
The initial plan is to take my Assignment 3 and enhance it to be drawn in a cel shaded style as a proof of concept.
Successfully converted from GLUT spheres to spheres drawn with triangle strips. This is important so that I have control over every drawn vertex (and hence on the texture coordinates used for each vertex), which apparently the GLUT sphere does not really provide.
Next, going to attempt to apply black borders.
After much gnashing of teeth, cel shading has been achieved on the A3 puppet:
A lot of stuff is unfortunately done in software (all lighting calculations are done with Matrix4x4s and Vector3Ds, for instance) and itís kind of slow. Need to figure out how to effectively offload work to display lists. Obviously the exact parameters of the shading could be tweaked as well. Also the nose is surrounded by this weird artifact.
It may be a little weird to get this to interact nicely with shadows.
Thursday November 18, 2:12 PM
Iíve been playing with tricks to make rendering faster without having to resort to vertex shaders. I would try to use those, but only a small subset of the lab computers support them, and Iíd like to avoid using them if possible.
The first obvious trick was to use a display list for the outline drawing - the fact that I wasnít already doing this shows why itís a good idea to sleep on things. It's worth noting now that when drawing for the purpose of shadow mapping, we can also use display lists since shading is unnecessary. (As I actually implement shadow mapping, this is an area that may turn out to be more complicated.)
The second trick is to notice that with a fixed light source, we donít really need to rerender the lighting all the time, and in fact we only need to rerender the lighting for the primitives that move. This means that for anything not moving in the scene, we can use display lists to cache their lighting calculations. Each primitive is assigned its own unique display list to achieve this. (Note a potential tricky interaction with reflections however, as this effectively adds a second light source.)
Taken together, these mean that in my final scene I wonít be doing too many dynamic lighting calculations and staying in software for the cel shading computations should be feasible. Phew.
(Bonus performance tip: the ď-O3Ē compilation flag improves performance by about 3x. Iíll keep that one in my back pocket.)
Friday November 19, 7:23 PM
Iíve spent quite a bit of time trying to get lighting right and make outlines appear consistently. Ported meshes from the ray tracer into this project (with the eventual goal of modelling a saxophone and various other objects), but outlines are working poorly.
Finished a cool Python script that allows me to generate arbitrary bendy pipes with varying width (for eventual use for the saxophone). As a side effect it allowed me to generate this sweet torus:
Unfortunately I donít have a good solution (yet) for the horrible aliasing that the cel shading is experiencing. Hereís another badass creation:
Now to actually model something useful with this thing...
Going for a snack, but protosax is achieved!
This uses Bťzier curves to achieve the approximate shape of a sax, and uses my curvy pipe generator to draw it.
Saturday November 20, 2:55 PM
Getting closer (with 6 cubic Bťzier sections):
So far this just linearly increases the radius of the sax as it goes from the mouthpiece to the end. The next step is to flare the end and make the middle a bit thicker, without altering the radius of the mouthpiece area.
Got sidetracked into fixing my mesh aliasing problem, which turned out to be caused by the fact that I wasnít average face normals for each vertex. Instead, every time I drew the vertex (a total of 4 times, usually) I would use a different face normal, which caused discontinuity in shading for obvious reasons. Unfortunately this adds a second or so to the startup time (as it computes each vertex normal - this would be horrific to do at every render), but itís not too bad.
The results are gorgeous:
And the final (for now) saxophone, with flaring:
And I side-benefit of the aliasing work I did. Even though I now have to do (roughly) 4 times the work per vertex (to transform the vertex normal into world coordinates using the current matrix), I can drastically reduce the poly count of my models without them looking terrible, producing a net win for performance.
Monday November 22, 6:41 PM
Did a bunch of work to prettify my musician, and add the saxophone to the puppet model:
I also fixed picking, which I somehow got away with being incredibly broken on assignment 3 (without realizing it - at first glance it seemed fine). Itís necessary to figure out animations and how to make him correctly hold the saxophone.
Tuesday November 23, 9:49 PM
Wow, shadow mapping is a pain in the ass. Itís difficult to debug the transformation from light coordinates to camera coordinates, it suffers from extensive precision errors without careful parameter caressing, and even once it is set up fairly nicely, it is still disgustingly aliased for all but the narrowest light sources. Took around two days to implement to a reasonable state, a lot of which was spent frustrated and trying to figure out debugging techniques.
Although my implementation is based on previous work by others, I had to add make the enhancement of using multiple textures to support cel shading and shadows at the same time.
Here is a simple scene with no shadows:
Here is the same scene with shadow mapping and the light having a wide field of view (but not ridiculously so):
Notice how the shadow of the saxophone plays across the rounded figure of the player (on the chest, leg and arm). Notice also how terrible the aliasing and artifacting is everywhere, especially on the chest and ground.
This is a visualization of the depth map (from the point of view of the light) used to achieve the above effect:
You can see that the player covers a very small section of the depth map, hence why the aliasing is bad. (Notice also that the orientation of this texture is of no consequence, since itís compensated by the lightís viewing matrix.)
Here is the scene with a significantly narrower (and kind of impractical for actual use) field of view:
Notice the artifaces and aliasing are significantly reduced. The lightís depth map, and the relative size of the player in it, shows why this is true:
A trivial solution to this aliasing problem would of course to use multiple, small depth maps from the light source. Unfortunately, this is not computationally feasible in my model. Iím already pushing it adding shadows at all, given that my cel shading is done in software.
Wednesday November 24, 4:26 PM
Iím working on efficiency today since Iím getting kind of worried about my 50 - 70 ms render times with shadows enabled and still very simple models. I was having trouble a while ago getting cel shading to work inside display lists, but I finally figured out that it was because I was requesting the MODELVIEW matrix (with which to do manual transformations) after performing a rotation inside the display list. Since none of the transformations are applied to the actual matrices when compiling display lists, this resulted in the wrong matrix being retrieved.
Preliminary results show that display list use for my spheres drops render time by 20 ms with shadows on. Because of the nature of my lighting, Iíll have to recalculate the display lists when spheres are rotated or moved, but this should greatly improve my render times assuming most objects are static.
That was a surprisingly quick refactor, and actually made the code for both the spheres and the meshes much simpler. When not moving a ridiculous number of things at once, render time is now significantly faster.
Iíve been reading up on vertex shaders, and decided that it wouldnít be too difficult to create a vertex shader to replicate the work Iím currently doing in software to compute the 1D texture coordinates of the lighting.
In the course of trying this, I had to log on to one of the machines that supports shaders. Wow! This machine is so much faster than the other I was using. Iím literally getting < 0, 1 and 2 ms render times for most renders, and > 70 fps even for frames with heavy in-software lighting calculations. I think Iíll reprioritize the shader work behind some of the more directly objective-based work since I donít think I need the speed as much as I thought I did.
Just spent half an hour solving a really stupid bug that ended up being caused by me binding a texture 10 lines too late. Sigh.
Thursday November 25, 3:15 PM
Just got texture mapping working. Made a lot of little stupid mistakes that made this take longer than it should have, mainly because I am now dealing with three textures simultaneously (one for shadows, one for lighting, and now one actual texture for texture mapping), and keeping them all straight is a bit complicated. If I had realized how much texturing there would be from the start, I could probably have kept things much more organized.
For example, for multitexturing you have to keep switching between the various different texture modes, and it would have made my life much easier if I had required that every block of code dealing with a particular texture mode needed to explicitly switch into that mode (with a single texture, you can just assume youíre always in the right mode, so it seemed okay not to be explicit about this at first).
In any case, the result is cool:
(This is just some crappy texture I drew for demonstration purposes.)
Friday November 26, 8:53 PM
Sweet. I got sound working (with SDL_Mixer, which I (and the internet) highly, highly recommend over OpenAL, especially since the sample code provided for it actually almost compiles, unlike the OpenAL code - protip, try changing audio_rate from 22050 to 44100 if you get audio artifacts).
I now have the intro to Giant Steps by John Coltrane playing in the background. Iím going to get so sick of it soon, but for now itís just awesome.
Now to make the game playable.
Saturday November 27, 4:53 PM
Iíve been working on game logic and the gameís note board. Got something pretty cool I think:
It even scrolls as time goes by!
Now I canít decide if this note board is horrible programmer art, or actually in the style of the game.
This is how Iím supplying the notes to the game. I opened up Goldwave and looked at the waveform to find where each note occurs to millisecond level, and then put that in a note chart file:
It was tedious, but if I did it well enough, I should be done with charting forever. (In this picture Iíve only assigned the notes for the first few.)
I now have a board with notes, although they are not yet playable. They are surprisingly fairly well synced with the music, although they do drift out of alignment slowly (I may be able to combat this by restarting the music once in a while).
Did some work with the sync and got it to resync itself every loop through the song, which is nice. I also figured out why I wasnít getting outlines, and put alpha on the notes as they come in at the back. Itís much prettier now:
Now the tricky part: interactivity.
Friday December 3, 3:53 PM
Iíve been furiously working away on this and other assignments.
The game is now fully playable. Sound turns off when notes are missed and back on when notes are hit, there is a miss sound effect, notes explode when hit, and notes float out of the end of the sax:
And now Iím working on the last purely graphical component: reflections. After that comes animations (both of characters and the camera).
I have fully functional reflections! Albeit without use of the stencil buffer, since it is unnecessary for my purpose.
I even have tricky behaviour so that the sprite particles show up properly in the reflection, which was non-trivial.
Now to build a wall to contain the window.
Iíve added walls (and changed the window colour from its previous, hideous green):
Saturday December 4, 1:40 PM
Iíve now attained camera animations using quaternion interpolation (I have code that translates my rotation matrix to a quaternion and back). Itís still hard-coded in, so I need to make a way for the camera animations to be scripted from the Lua specification. To aid myself in actually developing the script for the camera, Iíve added a command that prints the current rotation as a quaternion and the current translation.
I also still need to add easing of these animations so they donít look jerky. It might even be a good idea to use Bezier curves to model the cameraís animation so it follows smooth arcs, but this might take a while, so I'll hold off. May want to just special case things like circular motion.
Well that was easy. I tried to find something on the internet to explain the basics of non-linear interpolation (for camera easing), but couldnít find anything. So I just made it up myself and about the second thing I tried was exactly perfect (for my purposes anyway). In hindsight itís kind of obvious, given that itís called non-linear interpolation.
Scripted camera animations now work. They are specified in a file like this:
where the first line is the length of the script in milliseconds, and each subsequent line represents a smooth motion of the camera between two different rotations (expressed in quaternions) and two different positions. This could be extended a bit to allow for selection of start and end easing functions for each motion (this would allow for nice circular motion, for example).
Just completed the addition of translational animations, specified in the Lua file. They were straightforward if tedious to add, due to a new parameter of time needing to be pushed through all walk_gl and shoot_particle calls (since the position of models is now a function of time). I had an issue where I forgot to all translate the origins of particle emitters when particles were created, but this was easy to fix.
As a proof of concept, my character is now levitating up and down constantly.
And now, the part that really matter (itís possible I wonít even use translation animations in my final product unless I attempt walking): joint animations. Hopefully not too much more difficult, although I may run into problems since Iím going to be interpolating Euler rotations, which can get nasty.
Completed implementing joint rotation animations. Itís not difficult to do, the only question will be if the Euler rotations are expressive (and predictable) enough to accomplish the animations I want. Most of my animations I anticipate being one dimensional joint rotations, so I should be more or less fine. So far I have my model raising and lowering his arms, and raising and lowering his head.
I mentioned somewhere earlier that recalculating the cel shaded lighting was expensive, and that it would have to be done whenever objects rotated or moved in the scene. It turns out that I can choose to only recalculate the lighting every 20 or so frames, and it still looks fine. This is a huge increase in speed.
Sunday December 5, 2:56 PM
Iím making a piano:
The band begins to emerge:
Question is, do I have time now to add a drum and/or a bass? The first is probably not too bad with a bunch of cylinders (although orienting them in a believable way seems tricky). The second would probably require a fairly complicated script to generate, so I may skip it.
Monday December 6, 3:06 PM
Iíve been working feverishly since about 10 this morning (after leaving the lab last night at 11!), breaking to go to class and have lunch. There is one new character in the scene, the one person who isnít allowed to abandon the concert because itís a 25 second perpetual loop - the bartender:
Soon heíll have smoke coming from his cigarette.
The club has become much more complete with the addition of furniture of various types (and a texture mapped liquor cabinet with my beautifully drawn texture):
The floor has also been changed to look less like sand.
The end is in sight (and thank god, because look at those frame rates!). Now the final touches - cigarette smoke and animations that respond to how well the player is doing (by going slower as the player gets worse). Although now that I think about it, I want to redo the camera script so that it is less stomach churning - also I forgot quaternion normalization in my implementation. Augh details!
Smoke is now happening. Cel shaded circular smoke to be precise. The bartender bops his head around with the music, making the smoke take on a nice pattern:
Fixed normalization of quaternions. Hopefully this should fix the egregious perspective distortion that occurs on some extreme camera motions.
The final technological hurdle: animations that respond to how well the player is doing.
The player and the bartenderís animation now grow slower as the player misses notes, and stop if the playerís ďscoreĒ (a number than ranges from 0 to 20) reaches 0. Start playing again, and the scene comes back to life.
As one of my final acts, I finally stamped out a bug that seemingly occurred randomly, and manifested itself as an OpenGL error 0x502 (invalid operation). Forgot to initialize an int representing a texture to 0. Oops! Moral of the story - check for OpenGL errors (not that they make it easy - in the end, instead of manually checking for errors after every operation, I just sprinkled checks semi-randomly throughout my code, and tracked down problems more precisely as they occurred).
And with that, Iím done! The game is now in a presentable form. Obviously some tweaks could still be made, but as of right now Iíve basically fulfilled the vision that I set out to create 3 weeks ago.
Now to practice the demo tomorrow and do the real demo on Wednesday. (Also still need to write documentation!)
Tuesday, December 7, 3:56 PM
Spent the day writing documentation (and to my shame doing some last minute code reorganization and fixes) and handed in the project. Demo tomorrow.
Thursday, December 9
Iíve uploaded a couple of videos of the completed project:
Short gameplay demonstration with sound: http://www.youtube.com/watch?v=Hjp3t6JTIAs
Smooth, but with no sound: http://www.youtube.com/watch?v=qC5WhZ96OI8
Choppy, but with sound: http://www.youtube.com/watch?v=6SqFjKlxQyw