Since it was GDC time again, I ended up thinking about the water demo I created with my fellow grad student Ada. It was our first foray into shaders, and I think it turned out pretty well for a 10 week project. We had gone into the project thinking we might buy a book and follow a few tutorials. Instead, we were given the task of creating an impressive-looking scrolling water system that combined deep ocean & shallow water wave systems.
As is always the case, the more I look at the water demo the more problems and mistakes I find. I’ve been thinking about creating a new version for a few years now, if only to appease the constant requests for a boat. Since this project is comprised of the first real shaders I wrote, digging through the code makes me want to rewrite it even more. I’ve learned (and done) so much since we first toyed around with shaders.
It was originally written in XNA 1.0 Refresh, and upgraded to XNA 3.1 recently (before 4.0 arrived). Since I’ve been using XNA so much lately (mostly working on the Darkwind Media game Blocks), it might be nice to start over in C++ & DirectX 10. I’ve been itching to do something in that area again, and I think it’d be fun to improve upon the project that got me into graphics programming.
I was pretty sick last weekend, and sticking to my odd “get sick, code something” habit, I decided to finally try to make a fur rendering demo. I read a few articles about it years ago, so I knew the general concept behind it: render lots of “shells” around the model with an appropriate fur texture. The fur texture is basically a transparent texture with dots on it, and as the shells get layered on top of each other, the dots are essentially extruded into individual furs (without having to render each fur individually).
I’ve seen fur effects used in a few games, notably Star Fox Adventures for the GameCube, and the more recent Super Mario Galaxy for the Wii. I have no idea if they are using the same technique, but the Super Mario Galaxy queen bee looks similar.
What really got me thinking about finally starting this demo was an article I found on reddit. The article is from xbdev.net, and is (appropriately) called Generating Fur in DirectX or OpenGL Easily. While it’s not the most well-written article I’ve ever read (especially the comments in the provided code), it has some nice diagrams and screenshots of the technique in progress. If you’re interested in learning more about fur rendering, I’d suggest starting there.
After reading that article, I decided to go for it. I got the basics up and running pretty quickly. I added some camera controls and the ability to change a few things on the fly (like the fur length), mostly for testing purposes. One of the first things you notice with basic fur rendering is that everything is the same color, so you only notice the “fur” aspect of it around the edges. I added some basic N dot L lighting and I modified the fur by the model’s texture so it wasn’t all the exactly the same. This helped a bit, but the hairs were still bleeding into each other and not looking very fur-like. Clearly some sort of individual fur shading was needed.
I went back to the fur article linked above to check out their shadowing technique. To be honest, I’m not 100% sure I even implemented it the way they explained it (which I would have to describe as “poorly”). The gist of it is to re-render each shell, offsetting the texture a bit and making it look like a shadow. I didn’t like it from the start. Double the number of shells that need to be rendered? No thanks. I didn’t need to render an actual shadow of each fur. I just wanted the fur to get darker the “deeper” it was, so that’s what I did. The shells closer to the model are rendered a bit darker, and they get brighter as they get further away. The last piece of this puzzle was to make sure the model itself was rendered slightly darker, giving the illusion that the fur is shading the scalp.
One thing I did implement from the article was the concept of gravity affecting the fur. Each shell is offset a tiny bit in the negative Y direction (based on a power function) to give the impression that the fur is bending due to gravity. It’s a very nice effect, and it was easy to implement. I decided to take it a step further and make the fur react as you drag the model around. When you drag it, the fur gets stretched in the opposite direction and slowly interpolates back to its normal “bent” position. It’s fake physics, but it looks neat.
I’ve got some plans to continue this the next time I’m bored. A few features off the top of my head would be: multiple models & swapping at run time, more controls for different settings (gravity, fur density, etc) and adding a fur length map, so certain sections of the model can have different lengths of fur (or be bald).
UPDATE: I created a newer version of my fur demo using Luster. This one uses a fur map to mask out non-fur areas.
I finally got around to putting together a video of the old portal tech test I did for Dimension Break. It’s nothing fancy, but I’ve wanted to be able to show it for a while now. I’d really like to go back and polish it up a bit. Maybe finally implement the more Portal-esque portals for fun.