Sunday, March 25, 2007

Color macro in DirectX

Quick post but I ran into a macro that is defined in d3d9types.h that accepts 4 float values and returns and a single DWORD. This came up when I was working with the lighting pipeline in DirectX 9. Specifically, there is a fundamental difference in the way vertex diffuse/specular colors are stored (DWORDs) and the way DirectX materials are stored (D3DCOLORVALUEs aka. 4 floats).

definition:

#define D3DCOLOR_COLORVALUE(r, g, b, a)
D3DCOLOR_RGBA((DWORD)((r)*255.f), (DWORD)((g)*255.f), (DWORD)((b)*255.f), (DWORD)((a)*255.f))

Friday, March 23, 2007

DirectX Fixed Function Lighting - Part 1

So I have been studying the lighting module included with DirectX (fixed-function pipeline) and I created this as a summary of these effects.

There are three main types of illumination models.

  1. Emissive - The object "emits" its own light (ie. neon sign)
  2. Ambient - A an object is lit by an outside source, based on the material properties of the object, it will reflect this light, which will subsequently be reflected by other objects, until eventually all objects are lit.
  3. Direct Lighting - This is further broken into two subcategories (positional and directional). Positional is where the light is coming from one defined point in space. Directional is where the light comes from a source that is infinately far away (ie. sun).

We can set emissive at the object level, on frame advance, and we can also set the ambient level at the device level. So we are really focusing on direct lighting. With direct lighting two other illumination types are introduced, diffuse light and specular light.

  1. Diffuse Light - the full intensity of the light, scaled by the cosine of the angle between the normals of the light source and the object face. Lambert's Law dictates this.
  2. Specular Light - used to highlight an object to give the illusion of shiny and smooth surface.

This leads to the basic lighting equation used by DirectX.

I = A + D + S + E

A = Ambient Light
D = Diffuse Light
S = Specular Light
E = Emissive Light

Friday, March 16, 2007

Great article on importance of not building garbage!

This shows the importance of being careful to not build up garbage that the GC has to collect, especially on XNA as the GC is not as efficient.

GDC 2007 Slide Online!

The following are the slides from GDC. I have been unable to find any audio or notes to accompany these, but I have touched based with Dave Weller via the xna forums and he did not have these available.


UPDATE: The slide audio is availabe here for a fee!

Tuesday, March 6, 2007

XNA Creators Club Site Live!!

Its finally here. We all got the opportunity to join the XNA creators club a while back, but now the creators club web site has been released (actually was released Monday, first day of GDC). Apparantly, the msdn forums for XNA and DirectX will be moving over here. The new forums are great, much more rich experience. Kudos to Microsoft and the XNA Team!!!

UPDATE from GDC! From theZman

Monday, March 5, 2007

STL Vectors Unplugged - Part 2

Another update to the disection of the stl vector continues!! This time we are looking closer at how much overhead is added for this "auto-grow" array. There is no free lunch and this proves this point. Link to vector size discussion.

Sunday, March 4, 2007

STL Vectors Unplugged - Part 1

I came upon this article on STL vectors and how the instantiation of new ones (of different types) can effect the output binary size. Check it out! Interesting reading.

Friday, March 2, 2007

Performance Optimization Tips for XNA

A big issue that is getting some press has resulting from new products like XNA Game Studio and the questions are arising about how to make things like the garbage collector deterministic in managed code. If code in a critical game loop is stalled, for garbage collection, the results would seem to be very bad (stutter, dropped frames, oh my!). Luckily, the CF team that worked on the XNA Framework has taken this into account (they got our backs sometimes ;)). Listed below are 2 articles detailing some of these optimizations. Good Stuff!!!!

Managed Code Performance Part 1

Managed Code Performance Part 2