Wednesday, April 25, 2012

Love Is a Many-Headed Thing, Part VIII


Finally, I bring you what this entire series of blog posts has been promising all along – many heads. Below is the five-headed hydra, composed of 5,576 triangles. It isn’t far from my earlier estimate of how many triangles would make it up, and it’s still less than the number of triangles that went into the blue dragon.



Still, if two heads are better than one, then surely seven heads are better than five.



The seven-headed hydra pictured above is composed of 7,644 triangles, much more than what the blue dragon comprises. Nevertheless, the hydra looks so much more intimidating with an extra pair of fanged mouths that surely two thousand more polygons would be a small price to pay for a boss creature like this.

I won’t go beyond seven heads, though. Anything more would have a good view of its own butt.

By the way, regarding what I said about this hydra not growing any new heads – I may change my mind about that. We’ll see how it goes.

Saturday, April 21, 2012

Sorry, But the Snake Must Die

Take a good look at the picture below.


Take a good look at it because this is the last that anyone will ever see of this snake. Even before I give it the gift of life, it will die stillborn.

When I wrote my last blog post, I thought I was ready to transform the snake I’ve been working on into a hydra. I was wrong. I made a shocking discovery, one that I should have realized before I started texturing the snake. I found out that my model comprised 5,628 triangles, 82% of which comes from the head and neck. If I had made a five-headed hydra out of it, the creature would have weighed in at 24,180 triangles. Just to put things into perspective, the creature with the most number of triangles in NWN2 is probably the blue dragon, which is made up of only 5,810 triangles. Any creature that goes way over this number will be a resource hog that may slow down the game.

Clearly, this situation is untenable. I’m sorry, but the snake must die.

Ironically, only a few weeks ago, I advised Eguintir Eligard to reduce the polygon count of his model before he textures or rigs it. Sometimes, the person who most quickly dispenses advice is the last to take it.

As with real snakes, the biggest offender in my model is the mouth. The teeth alone comprise over 32% of the snake’s polygons. Even with the teeth gone, the inside of the snake’s mouth is still a complex piece of topography, with far too many polygons dedicated to accurately depicting its hills and ridges. Despite that, players are unlikely to look closely at its mouth, especially if they play with the camera zoomed out. All those polygons would have been for nothing.

I spent an entire day reducing my model to its bare essentials until I was left with 1,432 triangles. Making a hydra out of the new snake would have brought its polygon count to 5,368. Good enough.

With all the trimming I did, my UV map was practically useless. I had to retexture the snake from scratch. It is said that there are two kinds of outcomes: successes and learning experiences. Mine was definitely in the latter category. The good thing about having so many learning experiences is that they enable one to work faster than before. I spent three days on the normal map and one day on the diffuse map. Within five days of my startling realization, I was done.

Meet the new snake. Same as the old snake… minus a few thousand polygons.

Monday, April 16, 2012

Love Is a Many-Headed Thing, Part VII

On a trip to Australia some time last year, I went to a dry night market that catered mostly to the tourist trade. There, I came upon a stall where a man had a few small snakes for people to touch. Seeing other passersby petting some of the reptiles, I approached the stall and ran my fingers over one snake. I smiled with delight as I felt the smooth, bumpy texture of its scales under my fingers. It felt no different from a snakeskin wallet, I thought to myself. I turned to my colleague, who had accompanied me to the night market, and I asked him if he wanted to give it a go. He shook his head with such vigor that if some snakes were to land on him at that very moment, they would immediately have been flung several feet away. When I turned back to the snakes, I then espied a small sign on the stall that said, “Suggested donation: 20 dollars.” I had felt no fear while touching the snake, but the sign filled me with such apprehension that I slinked away and never went back.

The hydra model that I am making will only be seen and never touched, of course, but if the sight of it can evoke a feel of smooth, bumpy snakeskin, then I’ll know that I’ve created a good model. In that regard, I believe I’ve succeeded, as evidenced by the picture below.



When NWN2 players see this snake in game, they aren’t likely to say, “Ooh, look at those scales, so detailed and realistic.” No, they’ll say, “Holy crap! A huge, effin’ snake,” and they will proceed to kill my lovely creation.

Saturday, April 14, 2012

Photoshop Tutorial: Balancing Contrast in Grayscale Images

I just spent the better part of the day trying to figure out how to reduce the contrast in the red channel of my snake’s normal map. The problem was that some scales were darker than others, but I wanted them to be shaded more or less the same. Here's how the red channel of my normal map originally looked.



The picture below shows what happens when the scales are not uniformly shaded. Notice that the neck is darker than the rest of the body and that there are some vertical patches of dark scales going from the neck to the middle of the snake. In addition, the lower part of the body is plunged abruptly, not gradually, into shadow. All this can be corrected by balancing the contrast among the scales.



I’m sure there is more than one way to do this in Photoshop, but the method I came across is fast and reasonably effective. If I had known how to do this from the get go, I would have saved myself several hours of frustration. Before I forget my hard-earned knowledge, I’ve documented the procedure here.
  1. Duplicate your original image as a new layer on top of it. If this layer isn’t a grayscale image, convert it to grayscale by clicking the Image menu and selecting Adjustments/Black & White. Press [Ctrl]+I to invert the duplicated image. Let’s call this layer Inverted.



  2. For the this step, you can do one of two options. I recommend changing the Opacity of the Inverted layer to 50% without changing its blending mode, as shown below.  This will completely neutralize the two layers, forming a uniform gray.


    Alternatively, in the Layers palette, you may change the blending mode of the Inverted layer to Overlay. I tried doing this option initially, but the results were not particularly good. Nevertheless, it may work better with some images, so I included this alternative approach here.



  3. Click the Filter menu, and select Blur/Gaussian Blur. Make sure that the Preview checkbox is checked. Adjust the Radius until you can’t improve the contrast any better this way.




  4. You can adjust the contrast further if you aren’t fully satisfied with the outcome. With your Inverted layer still selected, click the Image menu and select Adjustments/Curves. Tweak the curve a little bit until your contrast is as balanced as you can make it.



  5. Merge all layers so that only the Background layer is left.

That’s it. As can be seen from the picture in step 4, the scales are now toned more evenly than before. Simple if you know how. From here, you can enhance your image further through proper use of layers. In my case, I adjusted the contrast further with the Curves tool to enhance the image. I also made sure that only the scales were affected by the whole procedure and that all other parts of the image retained their original appearance. The final result can be seen below.



I then copied the above image to the red channel of my normal map. Below can be seen the result of this simple correction. Notice that the scales are now shaded more uniformly and that the lower part of the body blends more naturally into shadow.



Edited on 23 April 2012 to illustrate the application of this procedure and to incorporate two alternative options in step 2.

Thursday, April 12, 2012

Love Is a Many-Headed Thing, Part VI

Imagine you are a tattoo artist, and a lovely magician’s assistant has asked you to do a very intricate tattoo all over her body. The problem is that the magician had cut up his lovely assistant into several pieces, but before he could put her back together, a time-traveling doctor pulled him away to help save the known universe. Despite the state of her body, the magician’s assistant is alive and well, thanks to the power of magic. Her boss will be back soon, but in the meantime, his lovely assistant insists that you tattoo her while he is away, or she’ll be too busy practicing and performing stage magic to ever have another opportunity like this.

As implausible as this scenario may be, I’m faced with basically the same underlying problem in trying to texture my snake model. To accommodate the entire snake in a 1024 × 1024 texture map, I had to lay out the snake as if it had been sliced into pieces. If I were to map the surface of the snake as shown below, I’d be wasting space on the texture map.



By cutting up the snake on the texture map, I can make greater use of available pixels.



Now the challenge with this kind of layout is to align the textures on each part of the snake perfectly with each other. It would be like trying to tattoo a lady who had been sawn to pieces. Actually, it would be more difficult than that. As can be seen in the UV map above, the head looks like it has grown much too big for the neck, which in turn, is much too big for the rest of the body. I did the UV map like this so that the head and neck can receive proportionately more texture detail than the rest of the snake. Good luck trying to align all the textures manually. If I had an entire snake model with scales, I could simply bake the normal map and let the software take care of aligning the textures perfectly. Making a snake model complete with 3D scales would require more time and effort than I’m willing to spend, however, so that approach is out of the question.

The solution that I eventually settled on was to first abandon my previous efforts at sculpting in ZBrush, which I blogged about last time. Upon taking a closer look at my reference pictures, I realized that I did not sculpt the scales correctly. Besides, my model was ugly. In the close-up picture below, it is obvious that the edges of the scales are not crisp. I can’t seem to emboss scales with crisp edges in ZBrush. I was hoping that these imperfections would magically disappear in the normal map, but that was not the case. As they say, garbage in, garbage out, and my high-poly mesh was garbage.



My next step was to build some snake scales in 3DS Max. Below is one of the scales that I made. It comprises over 400 polygons, far more than would be practicable to cover a snake with. Nevertheless, I liked its smooth surface and extra crispy edges so much that I couldn’t bear to simplify it. The scale turned out to be far thicker than it should have been, but that didn’t cause me any problem.



With these scales, I covered strategic areas of my low poly snake. Although it is nowhere near as difficult as covering the whole snake with scales, it is still mind-numbing work. Each scale had to be resized, moved into position, and rotated so as to overlap the scale behind it. I made sure to completely cover the areas that had UV seams. This solves the problem of how to align the textures across different UV segments. Below is how the snake looks with the scales that I placed on it. Kind of makes me think of a luchador in a bikini, which isn’t a thought I’d like to hold for very long.



I then baked my normal map and edited it with Photoshop to cover the parts of the skin with no scales. I’m not finished with the normal map yet, but I’ve done enough to prove that this approach to texturing the snake will work. Below are two scanline renders of the snake. The first picture shows the snake with a freshly baked normal map, and the second picture shows how it looks after I had added more scales with Photoshop.




Looks like I’m finally on the right track. It won’t be long before we’ll be seeing how this baby looks in NWN2.

Thursday, April 5, 2012

Love Is a Many-Headed Thing, Part V

I hate snakes. They look like they might be easy to model, but actually, they are not. The external form of a snake is simple enough, but the inside of its mouth has enough hills and ridges to rival the Sierra Nevada. The worst part about modeling snakes, however, is texturing them. A snake’s body is covered with scales of such precise shape and arrangement that 3D artists will notice if the texture is shoddy.

Having finalized the snake’s mesh and mapped its UV, I began to make its normal map. Basically, there are two ways to do normal mapping:


  • You can create a high-poly version of your low-poly mesh and use both to bake a normal map in your 3D modeling software. I’ve discussed how to do this in 3ds Max elsewhere in my blog. You can also bake normal maps in the latest version of ZBrush, but if any part of your low-poly mesh protrudes from the high-poly model, that area won’t be baked. In 3ds Max, you can overcome this problem by adjusting the cage in the Projection modifier.

  • You can also make normal maps out of 2D images. This is usually done by using image editing software to convert a black-and-white height map to a normal map. I’ve tried using the nVidia normal map filter for Photoshop to do this, but frankly, the results are awful. Alternatively, with photography and some clever lighting, you can shoot images and convert them into a normal map, but in the case of my snake model, this is not a viable option for me.


When it comes to sculpting organic models, ZBrush and Mudbox are the software of choice. I didn’t want to fashion scales all over the entire snake, however, as this would be a monumental effort. Instead, I cut off the snake’s head and a section of its body and sculpted each separately. Because the model has mirrored UVs, I only need to sculpt the right half of each segment. My plan is to bake the normal map in 3ds Max and use Photoshop to replicate the baked texture in all other parts of the snake’s body. It won’t be easy to align each segment, but it still beats having to sculpt everything.

Here's what I have so far. The scales on a snake's head are roughly hexagonal and occasionally pentagonal, but as you move down the neck, the scales change to an interlocking set of diamond shapes. These models aren’t perfect, but I believe they will do.




I made so many mistakes while making the above sculpts that I had to backtrack too many times for me to recount. If I were any kind of sane person, I’d have gone mad by now from sheer frustration. As it is, I lost my mind a long, long time ago, and I haven’t missed it since.