A Flexible Material System in Design by Maxime Beaudoin

 

I was looking for some good Material System designs in teh interwebz and I stumbled upon this one article by Maxime Beaudoin. Quote from ShaderX6 book:

“Maxime Beaudoin
Maxime Beaudoin is a 3D graphics programmer at Ubisoft Quebec studio, Canada. He started to learn real-time 3D graphics by himself in 2001 and received his B.S. degree in computer science in 2003. Since 2005, he has been working for Ubisoft during the day and developing his own next-gen game engine with some friends during his free time.”

 

Unfortunately, I don’t have a copy of ShaderX6 book nor I can download one from the internet. But I found a ppt presentation that he made for GDC 2008.

http://www.coretechniques.info/2008/Material.zip

P.S. Something I found really2x cool.

Back of the Mike (1938)

Back of the Mike is a short film done in 1937 for the Chevrolet Motor Company depicting the behind the scenes look at the making of a Western radio show. This documentary shows the various ways sound effects are created during the broadcast. Rain was created by pouring sand over a spinning potters wheel which sent it down a metal funnel onto a microphone which was covered by a paper bag. Fire was created by wadding up plastic wrap close to the mike.

16.1 MB’s. Video will play in the flash player below.

http://www.oldradioworld.com/Back_of_the_Mike.php

 

Cheers!
– CodeSushi

Advertisements

ResourcePool design.. AND ResourcePoolItem AND StoragePool AND Storage…

Man it’s been a while since the last time I’ve worked on my personal project. Been busy with work lately. Anyway, back to my resource manager.

I’ve been really productive in my project for the past 2 days and I think I have got a lot of things done. But I’m still far from finishing my resource manager. I’ve finished implementing all the base component of my resource manager and what is left is to actually work on THE Resource Manager itself. Although before I present the design, I would like to give credit to this one author who really helped me in designing my manager. I need to give credit where credit is due! His name is Greg Snook. I don’t have direct affiliation with him but I stumbled upon his book in my book collection recently, and his engine presented in his book contains A LOT of invaluable treasures! One of them is the design of the resource manager and while I was in the process of designing mine, I found out that my general design somewhat aligns with his. So I decided to use his as a general guideline instead.

Below I present an insanely tangled UML Class Diagram on how the sub-components are designed. The base storage class that holds the resource is StorageData. This acts like a static vector class. Another class is derived from it called StoragePool where it is composed of a list of StorageData. Thus StoragePool acts as a dynamic container that dynamically extends the list if StoragePool gets pool and vice-versa. Since StoragePool is a generic Storage Pool class, I’ve developed another class the simply extends and formalized the methods for resource handling and using the StoragePool(composite) class.

Ultimately, the StoragePool class will be used the ResourceManager which I haven’t finished working yet. For now I present the UML diagram and the links for the source code.

Enjoy! ResourcePoolClassDiagramRel

StoragePool.h: http://codaset.com/codesushi/pulse-tec/source/master/blob/Source/Engine/Include/StoragePool.h
ResourcePool.h: http://codaset.com/codesushi/pulse-tec/source/master/blob/Source/Engine/Include/ResourcePool.h
ResourcePool.cpp: http://codaset.com/codesushi/pulse-tec/source/master/blob/Source/Engine/Source/ResourcePool.cpp
ResourcePoolItem.h: http://codaset.com/codesushi/pulse-tec/source/master/blob/Source/Engine/Include/ResourcePoolItem.h
ResourcePoolItem.cpp: http://codaset.com/codesushi/pulse-tec/source/master/blob/Source/Engine/Source/ResourcePoolItem.cpp

Bit Flags Class

The more I flesh out my resource manager design the more I realize just how much more work and classes I need still need to add. While I was working on my ResourceItem class, one of the components it needs is to keep track of a bit field to keep track of its state whether it is loaded, ready to use, disabled, etc.  Instead of normally hacking my way through the code implementations i decided to encapsulate that bit field implementation instead. And I created a class that wraps bit manipulation called BitFlags. Here’s a simple UML Class Diagram below.

 

BitFlagsBitFlags member and interface.

Basically, this class handles the low level bitwise manipulation like setting which particular bits on and off. The interface seems self-explanatory so I’ll just let you figure the methods out. Link to the implementation is provided below. As an added bonus, here’s a bunch of bitwise manipulation macros extracted from my Pulse Library project.

  1. // Bit manipulation macros
  2. #define PSX_GetBit(x)                (1<<(x))
  3. #define PSX_TestBit(flag, bit)        (((flag) & PSX_GetBit((bit))) !=0)
  4. #define PSX_TestBitAll(flag, set)    (((flag) & (set)) == (set))
  5. #define PSX_TestBitIfAny(flag, set) (((flag) & (set)) !=0)
  6. #define PSX_SetBit(flag, bit)        ((flag) |= PSX_GetBit((bit)))
  7. #define PSX_SetAll(flag, set)        ((flag) |= (set))
  8. #define PSX_ClearBit(flag, bit)     ((flag) &= ~PSX_GetBit((bit)))
  9. #define PSX_ClearAll(flag, set)     ((flag) &= ~(set))

 

Link to BitFlags class implementation:
http://codaset.com/codesushi/pulse-tec/source/master/blob/Source/Engine/BitFlags.h

Feel fre to ask if you have any question!

– CodeSushi

Resource Manager Design Implementation And A Little Update

It has been a while since my last post. After my little adventures on graphics programming, I’ve been quite busy with work lately so I haven’t been able to continue working on my little Pulse Library. Although, I’ve been thinking on what to move on next with my library for a while now. I have two choices. First, either work on the 2d stuff for now. Basically setting up basic rendering and hand written sprite system. This will also be the foundation for one of the things I’m also planning in the future: GUI or Graphical User Interface system. The second choice is simply to go directly to 3D first. Since DirectX pretty much works on 3D it would be easier for me to start on this direction. BUT WAIT! While I was too busy thinking about which way to go first, I totally forgot one really important thing! A resource manager! I can’t just start  writing all these systems up and use resources like crazy. I need a way to properly manage and dispose resources. I have already started writing about half of the manager last weekend and I’m hoping to finish it by the end of this week so I can finally ACTUALLY start working on my render ( then figure out on which direction to go… 2D or 3D ).

I’ll briefly discuss the manager in here for now and I’ll be posting another blog post discussing how my manager was designed and how it is used in detail. It would be nice if I can display pretty nice UML pictures in here but I’m lazy. So deal with it! I should start using UML next time though… Actually I just forgot how to use it and I need to review my software architecture class regarding on how to use it again. 😛

So here’s how my Resource Manager goes:

The whole manager uses a monolithic management structure that consists of a number of resource management subsystems(we’ll get to this later). This system is designed to have a one and only instance used throughout the time an application is run. That means we’ll be using a singleton design pattern.

When i say monolithic management structure, this system will literally handle ALL resources used by the application. Let it be partial streamed packets for sound and or music, game data objects (game data will be stored in a resource cache), graphics resources like textures, vertex and index buffers, shader effects etc. Yes, ALL TYPES OF RESOURCES.

Okay, so the problem with this approach is that how the hell will we able to do that?! Different types of resources requires radically different types of interfaces and if we merge them all to one, it’ll just result in one huge convoluted type of manager class interface that more than half of its methods doesn’t make any sense. In order to fix this problem, we need to study each resource type and try to derive a number of methods that’s pretty much being used by all of them. So what we need to do is basically build a VERY GENERIC type of resource base type. In my current implementation, I simply call it as a ResourceItem. The ResourceItem class contains abstract methods that derived classes will need to define. Some of its methods will be like Create(), Destroy(), Disable(), Restore(), LoadResource(), SaveResource(), etc…

So while the manager hands out different types of resources  based on our needs, internally, the manager doesn’t care much about what type of resource it is. All it cares is that its handling a ResourceItem and all the basic methods that it needs to create, maintain, and finally destroy are there. Simply as that!

This pretty much lays out the general idea of the manager that we will be using. Now for the resource management subsystem that I mentioned at the start, this is simply a storage pool. A storage pool is a container I specifically designed to store game resources. It behaves like an array that issues handles to new added resources. This storage pool is also a dynamic container that increases its storage size whenever needed. The difference is that, due to the huge performance hit by arrays, it uses a linked-list instead. Now we all know that linked-lists suffers huge cache misses during traversal. So the storage pool that I will be using uses a different trick. Instead of using linked-list per object, we use linked-list to link chunks instead. The keyword here is chunk. We allocate chunks or blocks containing a number of objects and when that chunk is full, we then allocate a new chunk and link the new one at the back of the list. Isn’t it cool? Such a simple design now actually has the best of both worlds(array and linked-list)!

StoragePool
Diagram showing a storage pool creating a new block or chunk then adding a new resource element.

 

Well, that’s all for now. Sorry if most of this doesn’t make much sense as of the moment. My mind is still a little fuzzy with this either. I’ll post an update with more details to come when I finish working on this.

And here’s a random happy music for you!

Have a great day!

– CodeSushi

Toon Shading

This screenshots demonstrates a rendering technique called Toon Shading. Another term for Toon Shading is Toon Lighting or Cartoon Style Lighting. The characteristics of the toon shading technique is the abrupt transition from one color shade to the next. Unlike normal lighting that has a smooth color transition.

 

toon1 toon2

 

– CodeSushi

Let There Be Light!

Here’s the same sample as the last one but with lighting added to it. Notice that depth of the shaded colors now vary in detail depending on what type of light is used. Three types of lights are used in this application. Namely Directional/Parallel light(i.e sun), Point light(i.e. light bulb) and Spot light (i.e. ..err.. spot lights). The main formula that makes these lighting work is “Lambert’s Cosine Law”. The screenshots below also uses Phong Shading. Phong shading provides the most detailed but also the most expensive type of shading. Other types of shading are Lambertian and Garraud shading. These two shading types are less expensive but gives lesser shading quality( lower polygon models have triangles more noticeable(forgot the actual word)). For more info see [ELengyel04] or [FLuna08].

Directional Light Point Light Spot Light
directional point spot

[ELengyel04] : Mathematics for 3D Game Programmers & Computer Graphics 2nd Edition
[FLuna08] : Introduction to 3D Game Programming with DirectX 10

– CodeSushi