Viva Pinãta grass effect, demystified

So we’ve all probably heard of Viva Pinãta for the XBox 360, which was released fall 2006. It has a quite distinctive and remarkable graphics style; very colorful ofcourse, but also very detailed and rich in stuff happening on the screen. It’s a kids game obviously, and the game itself is not primarily aimed at people like myself who enjoy the virtues of brutality in Gears of War. However, the graphical techniques used in Viva Pinãta game are pretty cool; in fact, the game was nominated for an award for outstanding achievement in visual engineering. The pinãtas have a nice paper-mâché-like fur and the grass is done in a similar style.

So, how is it done? The technique used is commonly called shell rendering, and it is used widely in various games on different platforms. Shadow of the Colossus on PS2 uses it for furifying its colossal creatures, and Super Mario Galaxy on Wii uses it for some of the enemies and for example for the queen bee in the bee world. The trick is to have several additional layers of geometry above your mesh, mapped with a texture that contains random or ordered pixel data (See picture). It’s a cheap method if you compare it to instancing geometry for each fur hair, because now you only have to render the model for each layer of fur. Thats obviously still a conciderable amount of extra polygons if you have a detailed model, but not nearly as much as if you would do it with instanced geometry.  Obviously there are some tricks that make it even cheaper. You could for instance take a lower level of detail model to render the fur layers. For grass, you could maybe combine the method with a geometry based LOD technique (like geomipmapping for example) and only render the grass for the terrain that is within certain distance to the viewpoint.

There are also some parameters that you can derive from this method. You can determine:

  • The amount of pixels in the fur texture (The density basically)
  • The distance between layers. Long hair/grass or short, its all possible. You can even have variations in height by storing the height in the fur texture as the value of a color. Since you have RGB you can store up to 256*256*256 values (you will need the alpha for other things, like a lerp between black and the base texture color for example)
  • The displacement of the layers with respect to eachother. You can for example apply gravity or wind making the fur hang or the grass wave. Make the displacement non linear, and the fur/grass will hang in a certain way.
  • The amount of layers used. This is useful if the camera is making a low angle with the furred plane, or when the displacement between two layers is too big (and thus gaps emerge between two layers).
  • The thickness of the fur hairs. This is done by scaling the texture (mapping it differently) or by means of populating (for example, sample a random position and add pixels for the consequtive two pixels to get a nice row)

There are lots of posibilities by combining the different attributes, some which I can’t even imagine at this time. I would be really interested in the way Rare did the pinãta paper-mâchée fur so neat and tidy for one 🙂 Anyway, here is an example of how grass could look (its a bit coarser than in Viva Pinãta but that can easiliy be adjusted by controlling the thickness parameter):

I made this in XNA with help of Catalin Zima’s fur example on Ziggyware.

Shader Programming Resources

For those that are interested in programming shaders up to shader model 3.0, there are some really nice resources available for both starters and the more advanced shader programmers. recently made ShaderX2 by Wolfgang Engel available for download. Wolfgang Engel is one of the senior engine programmers at Rockstar San Diego, and he worked on the engine for GTA IV.  He also keeps a series of books called ShaderX, which if im right now has 6 volumes. The  ShaderX2 book is actually in two parts, first is a tutorial for beginning shader programmers, and theres a second part which is more of a cookbook style book with a whole lot of articles on all kinds of different subjects. The two parts can be found here.

Nvidia have also made some of their older books published on their developer zone, freely accessible. First is the Cg Tutorial which is nice for beginning shader programmers, and second are GPU Gems and GPU Gems 2 which are again a nice collection of articles on different subjects. They can be found here.

The path to more wisdom

Yesterday i noticed that Andy Patrick placed a nice blog on the five books you must own if you are writing XNA games. So i’ve looked over them and found it funny to see Game Coding Complete: Second Edition on there as it was one of my first books as well. I don’t have the other ones except for the game developer magazine, but I ordered Riemer Grootjans’ book XNA Game Programming Recipes right away as it looks like a nice book giving somewhat more in depth information and not the basics. I’ll post a review of  it when I’ve read through it.

So next to his five books, i would propose five others of which I think should be on the shelf as well for you being a game developer.

  • The first is 3D Game Engine Design, Second Edition. This book covers all kinds of topics concerning game engine development and is very in-depth. Unfortunately, the only thing it doesn’t cover well enough is the software engineering process of game engine development.
  • The second is Design patterns : elements of reusable object-oriented software. When writing games, usually you will have to apply several design patterns. Understanding how they work and recognising them when you write games is absolutely a must. This THE book to have on design patterns.
  • The third is Object-oriented Programming in C++. When you want to learn C++ in general, this is the book to have. It thoroughly covers every aspect of the C++ language very clearly, period.
  • The fourth is actually a series of books called AI Programming Wisdom. Each of the books is a collection of articles on all kinds of AI subjects like path finding, neural networks, Bayesian networks and more. All of these articles are either written by industry professionals or academic researchers, but are mostly fairly easy to understand.
  • The fifth is Andrew Rollings and Ernest Adams on Game Design. In my opinion every game developer should have read a book about game design. It might sound obvious, and most of it covered by the book probably is when you’ve played a lot of games, but this is also the kind of stuff you tend to forget when you are creating games.

Ludum Dare

Ludum Dare is upon us once again, as the twelfth edition is going to take place next weekend. Ludum Dare is a regular community driven game development competition. The goal is, given a theme and 48 hours, to develop a game from scratch. Ludum Dare aims to encourage game design experimentation, and provide a platform to develop and practice rapid game prototyping. I’ve not yet competed in a previous edition because of occupance and a bad theme (minimalist), but I might try competing this time. There are some really nice themes like Dimensional Shift, Lose to Win, Procedural and Misdirection.

Gabriel: Have you ever heard of Harry Houdini? Well he wasn’t like today’s magicians who are only interested in television ratings. He was an artist. He could make an elephant disappear in the middle of a theater filled with people, and do you know how he did that? Misdirection.
Stanley: What the fuck are you talking about?
Gabriel: Misdirection. What the eyes see and the ears hear, the mind believes. for more info 😉