I decided to finally spend some time rewriting the color code, which involved rewriting basic vector math in Python (because, sure, I've got that stuff written somewhere, but it's easier just to rewrite a cross product than to figure out where the last libraries I used were located).
Calculate the normal of each of the faces, for each vertex, sum the normals, then normalize, then grumble that "normalize" and "normal" seem like such similar words, but the one is an operation on a vector that makes its length 1, and the other is a vector perpendicular to a plane, and really, they could have found different words.
The vertex normals seem about right from the testing I did, so then I did some dot products with a directional light source shining straight down. (I'd do something fancier than that, but I wanted something simple, and this gave me a static light that held up when the tanks rotate.)
So... is it an improvement? Sort of. There are a bunch of artifacts that I don't like - in particular, there are gross streaks running down the gun barrel. I see what's going wrong here - the issue is that I'm averaging across creases in the geometry, which I knew was going to be an issue, but I didn't know how big an issue it was going to be.
Consider the vertices at the end of the gun barrel - each vertex there touches some number of polygons on the end of the barrel, and something like four triangles going the length of the barrel. I'm using the same vertex color for all of those triangles, which would make sense when the geometry was smooth - averaging all the nearby faces gives nice smooth shading. But with a crease, you've got polygons on one side of the crease that shouldn't spill color information over to the polygons on the other side.
So, I could change my model exporter to facet all of the models - not sharing any vertex information anywhere, which is simple, and would give a different look again, maybe a little better.
Or, I could be clever and detect creases in the model (where one triangle meets another triangle at maybe a 45 degree angle or sharper), and break the vertices apart based on that crease. I've done that before, but yeesh, that's been years. That's a lot of work, and I don't think I want to do it right now.
Or, I could poke around inside Blender and maybe find some sort of setting on the exporter I'm using, or some different exporter, that does all this for me. Seems like Blender would have these features already implemented.
Or, I could write my own exporter that sits inside Blender, rather than use their exporter and my conversion script. That'd probably be the best way to go, but again, more work than I want to do.
Or, for the moment, I could say that this is as good as it gets, and let it go. Punt!
Well, for today, anyway, I'm done. Maybe I'll come back and implement the faceted approach, where vertices get duplicated all crazy like, and normals are per-polygon, without averaging, which makes me sad, but I think it'll be the best appearance for the least work.
Top of the TODO:
- Buddy - really, having an ally tank won't be hard. Getting it to play smart and be a balanced part of gameplay will be the hard part. Also, following directions you send it (here, boy!) will be work.
- Mission Menu - selecting missions from the mission menu won't be hard, just writing a menu display and getting keyboard events.
- Main Menu - right now, there's a huge gross "Play" screen. That's an abomination and a placeholder version of a main menu that isn't fully implemented. Play, About, Credits, Sound - all of those belong on that screen. Again, wiring, keyboard input.
- Vector Font Text Rendering - I intend to have dynamic text (a score?), or at least the ability to turn a string of text into something graphical, so that I don't have to do all ingame text as textures. This isn't a big deal, but it'll require writing yet another set of shaders and a custom rendering pipe. Not a big deal, and I see how all the pieces fit together. I haven't done this in WebGL before, but it should be straightforward. If you remember my space golf game: http://www.bigdicegames.com/Woody/ that's the feeling I want to capture. In particular, here's the settings menu: http://www.bigdicegames.com/Woody/Screenshots/07-04-05-09-19-optionsScreen.png
No comments:
Post a Comment