This blog has moved. Visit Groundswell Games for the latest. Remember to update your bookmarks and RSS feeds.
Showing posts with label texturing. Show all posts
Showing posts with label texturing. Show all posts

Thursday, December 6, 2007

An introduction to lightmapping

I've learned a lot in the last few days about lightmapping, the process of "baking" lighting effects into the texture on a 3D object. I've heard it described as a "poor man's lighting effect." For me, that's a true statement. I can't currently afford the pro version of Unity, which includes dynamic, real-time shadows, so the next best option is to map static shadows into my scenes.

Despite being less flashy, lightmapping is considerably less expensive in terms of processing. Ultimately, I think it's a fantastic value. The effect is great, and the cost is minimal.

Lightmapping is a tough concept to get your head around. Wikipedia has a brief article on it, but it's kind of technical. Here's the gist:

  • Generally the best way to control lighting is in your 3D modeling application (the image to the right was rendered in my 3D app). You can build a number of objects, texture them, and light them in whatever way you choose. The trouble is that rendering images with sophisticated lighting is much too slow for a real-time game engine.
  • When applying textures to 3D objects for games, you have to "unwrap" the object onto a flat surface that then gets painted with a texture (a tedious process called UV mapping). The texture is then wrapped back around the object.
  • Most 3D modeling applications now allow objects to have multiple UV sets. In other words, the main texture can use one set of UV coordinates, and another texture can be attached to the second set.
  • The lightmapping process takes advantage of this second UV set by converting lighting information from the 3D application into a flat texture that can be applied to an object on top of the primary texture. The result is an object that looks like it's being lit, even when no lights are present.
  • Since lighting is one of the most processor-intensive tasks in real-time 3D processing, lightmapping is tremendously beneficial from a performance standpoint. The downside is that the "baked" lighting isn't dynamic and won't apply to any moving objects in the scene (well, you could do it, but it would look pretty strange).
These before and after images illustrate the point. The first one is a screenshot of a scene with no lighting and no lightmapping. The second image uses lightmapped textures, but still has no in-game lights. As you can see, the cube that should be lit by the light coming through the window (if this were the real world), is not receiving any light at all, since there are actually no lights in the scene.

Probably the best approach for me is to use some combination of lightmapping and in-game lighting. The result won't be perfect, but it will be close enough until I can spring for the pro version of Unity.

Wednesday, November 7, 2007

Glorious free textures

The bulk of my time this week has been spent texturing one of my models. It's not a very complex model (in fact, it's just a bunch of cylinders and cubes), but I'm trying to get everything perfect. The process has left me a bit numb in the brain. Nevertheless, I keep reminding myself that I am relatively new to the texturing process, and this is pretty much what I expected.

The tedium of this particular texture (which is clawing its way from the pits of mediocrity) compels me to comment on the special place in my heart that is now reserved for anyone who posts a library of free textures to the internet. I stumbled on Mayang's Free Textures today, which has quite a variety of images, though there is a 20-per-day limit on downloads (if that's the only restriction, I'll take it). I expect to be downloading several in the coming days as I start creating new textures for the ground in my forest. It doesn't seem quite right that the floor of a dense pine forest would be covered in lush, green grass.

So, today I would like to harness the power of the internet and suggest that both my readers write a letter to someone (doesn't matter who) requesting that Mayang be immortalized with knighthood, sainthood, statues, songs, honorary degrees and other suitable accolades for contributing his photographs to the greater good. Thank you.

Sunday, October 28, 2007

Modeling a tree, and (r)ambling through the woods

After some fairly tedious work on my pine tree, I have something that doesn't look half bad.

Unity's restrictions for in-game trees require that each tree include a single mesh (for my non-gamer readers, a mesh is just a 3D object composed of triangles) using two textures: one for the bark and one for the foliage. Unfortunately, I didn't know how to place two textures on a single mesh in Cheetah (my 3D modeling program). It is possible, and pretty easy to set up, but it took some time to figure it out.

Create the foliage
Armed with the requisite knowledge of Cheetah's features, I set out in earnest to fill in my tree. The process I settled on ended up being fractal-ish in a way, which seems a fitting way to create a tree:

  • First, I created a small group of six polygons that would act as a small branch and a group of pine needles.
  • Then I duplicated this small branch 10 or 12 times along the bottom-most big branch on the tree. I scaled and rotated each copy so the foliage would feel random.
  • Rather than repeat this process for each of the 20 or so branches, I just did it for the first three. This gave me three distinct sets of small branches (anybody confused yet?).
  • Then I used those three branch sets to fill out the rest of the large branches, copying each set several times and moving/scaling it into position.
Remove (some of) the foliage
Another one of Unity's guidelines for trees is to keep each one below 2,000 polygons. Alas, after my foliage frenzy, I was about 1K over the limit. Time to optimize. My first inclination was to remove some of the small branches that didn't add much to the density of the foliage and wouldn't be very visible from a distance. This activity, sad as it was to remove the pretty pine needles, didn't get me far enough. How could I remove more polygons without thinning out my lush tree?

Finally it occurred to me that the branches near the top of my tree would never be seen up close. What's more, the branch sets up there had been shrunk down to the point that the polygons wouldn't be visible even if you were up close.

The solution, while probably obvious to you (if you've made it this far), seems poetic somehow. At the very top of the tree, the sets of branches aren't much bigger than a single branch at the bottom of the tree, so I just removed four of the branch sets at the top and replaced them with single branches. The difference is nearly indistinguishable, and I eliminated several hundred polygons. Final polygon count: 1,970. Yeah, I'm kind of awesome.

Thursday, October 25, 2007

First the trees, then the forest

I started working yesterday on my first serious tree. I've tried modeling trees before and found them to be quite tricky. Something about the thousands of tiny branches makes them a pain.

Nevertheless, nice trees are yet another a requirement for convincing game worlds, and the first area of my game is going to feature several lovely copses. Unity has some nice tools for creating the forest (there's literally a "make forest" button), but before you can have a forest, you need some trees.

After some brief research I went with a pine tree. One of those tall ones shaped like a cone. For one thing, it will fit well with the atmosphere of the game world. For another, it's shaped like a cone. How hard could it be?

The modeling process went something like this:

  • I started with a cone and manipulated it around until it looked like a decent pine tree trunk.
  • Then I created some smaller cones to use as branches and distributed them along the length of the trunk, making them smaller as I got higher on the tree.
  • Then I was ready to texture the trunk and primary branches. I found a nice, free pine bark texture here and loaded it into the GIMP, the open source graphics editing program. One "make seamless" filter, some rubber stamping, and about 20 minutes later, I had a passable, tiling bark texture. Very exciting.
Unfortunately, this is where it got hard. Foliage, it turns out, is even more detailed a thing than branches. Following Unity's advice for creating trees, I tried to create a simple group of polygons that could serve as small branches and needles. The idea is to duplicate these polygons, tilt them, and scale them until they fill out the entire tree.

As you can see from the picture, I barely got started. First I had to find a suitable texture (the one I found could still use work). Then I had to figure out how to work with alpha channels in GIMP and transfer them to Unity, which is a little tricky (I'm still not sure I could do it again).

Despite the complications, I feel that progress is being made. If I'm happy with the result, maybe I'll post a more detailed tutorial about modeling a cone-shaped pine tree.

Sunday, October 21, 2007

Stone wall textures, a mountain adventure

I went to the North Carolina mountains this weekend with some friends and hit the obligatory Asheville-area attractions: Chimney Rock and the Biltmore House.

Despite suffering much ridicule from my wife, I managed to take a series of texture photos for the game. It's not often that I stand next to massive walls, so I couldn't pass up the opportunity.

Some work will be required to turn these photos into useful, tileable textures. The GIMP has a "make seamless" filter, but I haven't tried it yet. In the event that it doesn't work very well, I will resort to the time-honored tradition of using online tutorials.


Thursday, October 4, 2007

The joy of texturing

As I mentioned in my last post, creating art assets is likely to be the most time consuming aspect of this project. Visuals are, however, quite important, as a fellow blogger points out. While I'm just starting the process of modeling objects, I would like to take a moment to discuss texturing. The reason is simple. Yesterday I turned the crate I had so expertly modeled into a living, textured game object, and I am pleased.

This is premature, of course, since we have yet to come up with a texturing method (more on that in a moment) or even a color scheme for the first area of our game world. Nevertheless, in an effort to see what might be involved in creating a vibrant wooden object, I set out to texture my crate.

Now, there are really two main approaches to texturing:

  • Painting -- this is what the real artists do. Start with a base color in your favorite graphics program and gradually paint in details like highlights, shadows, texture (like wood grain or knots). If you're curious, check out this tutorial on painting, yes, a crate. Painting can yield fantastic results because the possibilities for stylized textures are endless. Case in point, World of Warcraft.
  • Photo-based texturing -- It would be unfair to say this method is any less artistic than painting, but the desired effect is different. Photo texturing aims, as you might guess, at realism. Using this method, you would start with a photograph of your desired texture (a piece of wood or, better yet, the side of a crate) and manipulate it until it fits your desired style. My favorite example here is the Myst series.
Which method did I use? Well, neither. My 3D modeling program has a very nice procedural wood shader (which means it creates a texture from a program instead of an image file). So, instead of finding a crate to photograph or trying my off-hand at painting from scratch, I created a flat plane in Cheetah, added a wood shader, customized it by fiddling with some numbers, rendered it, and then used that rendered image as the starting point for my texture.

The result is certainly not going to change the world, but I was amazed how a couple hours of work could turn a drab gray cube into a crate just realistic enough not to be noticed -- and for a crate in a video game, there is no greater accomplishment.