24 Jul 2007

The Nebula3 Render Layer: CoreGraphics

The CoreGraphics subsystem is mainly a compatibility wrapper around the host's 3d rendering API. It's designed to support a Direct3D/OpenGL-style API with programmable shaders without any functionality- or performance-compromises. The general functionality of the CoreGraphics subsystem is roughly the same as the Nebula2 gfx2-subsystem, however CoreGraphics fixes many of the issues that popped up during the lifetime of the Nebula2 graphics system.

At first glance, CoreGraphics looks much more complex then Nebula2 because there are many more classes. The reason for this is simply that CoreGraphics classes are smaller and more specialized. The functionality of most classes can be described in one simple sentence, while Nebula2 had quite a few classes (like nGfxServer2) which were quite big because they tried to do several things.

A typical Nebula3 application won't have to deal very much with the CoreGraphics subsystem, but instead with higher-level subsystems like Graphics (which will be described in a later post).

Some of the more important design goals of CoreGraphics are:
  • allow ports to Direct3D9, Direct3D10 and Xbox360 without ANY compromises:
    • CoreGraphics allows much more freedom when porting to other platforms, instead of Nebula2's porting-through-virtual-functions approach, CoreGraphics uses porting-by-conditional-typedefs (and -subclassing). A port is free do override any single class without any performance compromises (e.g. platform-dependent inline methods are possible)
  • improved resource management:
    • Nebula3 decouples resource usage and resource initialization. Initialization happens through ResourceLoader classes, which keeps the actual resource classes small and tight, and the resource system is much more modular (to see why this is a problem that had to be solved, look at Nebula2's nTexture2 class)
  • less centralized:
    • instead of one big nGfxServer2 class there are now several more specialized singletons:
      • RenderDevice: handles rendering of primitive groups to a render target
      • DisplayDevice: handles display-setup and -management (under Win32: owns the application window, runs the Windows message pump, can be queried about supported fullscreen modes, etc...)
      • TransformDevice: manages the transformation matrices required for rendering, takes View, Projection and Model matrices as input, and provides inverted and concatenated matrices (like ModelViewProjection, InvView, etc...)
      • ShaderServer: the heart of the shader system, see below for details
  • improved offscreen rendering:
    • rendering to an offscreen render target is now treated as the norm, as opposed to Nebula2 which was still designed around the render-to-backbuffer case, with offscreen-rendering being possible but somewhat awkward
  • vastly improved shader system:
    • provides the base to reduce the overhead for switching and updating shaders when rendering typical scenes with many different objects and materials
    • as in Nebula2, a Shader is basically a Direct3D effect (a collection of techniques, which are made of passes, which are collections of render states)
    • ShaderInstances are cloned effects with their own set of shader parameter values
    • setting shader parameters is now much more direct through ShaderVariables (same philosophy as DX10)
    • ShaderVariations and ShaderFeature bits: A shader may offer different specialized variations which are selected through a feature bit mask. For instance a feature may be named "Depth", "Color", "Opaque", "Translucent", "Skinned", "Unlit", "PointLight", and a shader may offer specialized variations for feature combinations like "Depth | Skinned", "Color | Skinned | Unlit", "Color | Skinned | PointLight". The high level rendering code would set feature bits as needed (during the depth pass, the Depth feature would be switched on for instance), and depending on the current feature bit mask, the right specialized shader variation would automatically be selected for rendering. Together with the right asset tools, ShaderVariations and ShaderFeatures should help a lot to fix the various maintenance and runtime problems associated with programmable shaders (think shader-library vs. über-shaders and so on...).
A few other smaller improvement of CoreGraphics vs. gfx2 are:
  • handling DeviceLost/Restored and of WinProc mouse and keyboard messages is now handled through general EventHandlers instead of being hardwired into the graphics system
  • VertexBuffer and IndexBuffer are back as public classes
  • vertex components now support compressed formats like Short2, Short4, UByte4N, etc...
  • DisplayDevice offers several convenience methods to get the list of supported display modes or the current desktop display mode, and to get detailed information about the current display (hardware, vendor and driver version info)
  • one can now actually check whether 3d rendering is supported on the current host by calling the static RenderDevice::CanCreate() method before actually opening the application window
That's pretty much all there is to know, next up are Resource, Models and Graphic subsystems...

23 Jul 2007

Nebula3 SDK - Jul 2007

Here's the new July 2007 Nebula3 SDK release. I had to do some restructuring in the directory structure because of the Xbox360 specific stuff (which is not contained of course). Compiling is much faster now because I switched to precompiled headers. Please keep in mind that everything in the Render Layer is still under construction. The next few posts will mainly describe the various Render Layer subsystems.

Have fun!
-Floh.

7 Jul 2007

Overlord!

What a delicious game! It's one of those rare cases where a great idea (evil Pikmins) actually turns into a great game. There are so many odds against such an "old-school" game-design-centric cross-genre game (most importantly finding a publisher which is willing to take the risk, usually your name has to be Miamoto or Wright if you show up at a publisher with a game concept like this...) that it seems like a little wonder to me that this little gem actually saw Gold. There must be 50 similar projects which didn't make it past the prototype stage. Go out and buy this game, something like this only happens once every 3 years or so :)

PS: I'm trying to get a new Nebula3 source release out the door ASAP. Still no 3d rendering though, there are some delays on the rendering code due to the Xbox360 work and I'm also very busy working on Drakensang at the moment.

24 Jun 2007

Dirt!

MS should feel embarrassed that their platform-exclusive-1st-party-showcase racing sim Forza2 doesn't look half as pretty as the 3rd-party-multi-platform game Dirt (dIRT? DiRT? DIrT? whatever...) I went straight from playing Forza to Dirt and my first reaction was basically the German equivalent of "OMG that looks f*cking AWESOME!". Sure, Forza has another focus, it's a hardcore racing sim for enthusiasts, has a much more realistic driving model, online features and a multiplayer mode which can actually be called "multiplayer". While Dirt isn't an arcade racer by any means, it definitely feels a bit more "arcadey" then Forza2. Still, Forza should at least have tried to come closer to Dirt-level graphics. Compared to Dirt, Forza2 kinda looks like the boring civilian flight simulator with the ultra-realistic flight model and simplistic graphics that only hobby pilots fly.

The graphics in Dirt are truly "next gen", which in comparison can't really be said about Forza. I would go as far and say that Dirt is at the moment the second best looking 360 game after Gears, and the new "other" graphics-showcase on the 360.

PS: Don't judge Dirt's graphics by the demo on Xbox Live. The demo tracks there have hardly any vegetation in them. The European and Japanese tracks in the full version look much much better. And the immersion and sense of speed when racing a wet narrow forest track at 180 km/h in Dirt is simply unbelievable.

23 Jun 2007

Status Update...

Busy...

Working on the Xbox360 is total joy. Unfortunately I can't go into details because of NDA. I did some work on the original Xbox already, so it's not all new to me, but I was once again pleasantly surprised how painless the XDK setup is. All you have to do is plug-in some cables, double-click the installer, and after the installation ends (10..15 minutes) you're ready to compile and remote-debug the samples inside Visual Studio. Very impressive. The APIs basically offer everything a game programmer ever needs (and misses on the PC), the documentation is excellent. There's a wealth of high level APIs, but it's absolutely possible (and relatively painless) to go down to the metal if needed. Both is very important on a console. When the high level APIs are missing, too much time is wasted reinventing wheels (I guess that's one of the reasons why ports from the 360 to PS3 often take so long), and the low level stuff is necessary for optimizing performance-critical code (which is usually not possible or worthwhile on the PC because of all the different hardware configurations).

At the moment I only have 2 or 3 hours daily and the weekends to actually work on Nebula3, but despite that it's coming along nicely.

The Nebula3 Foundation Layer is already up and running on the 360. This is not a quick "just-fix-the-compile-errors" port", but a "proper" port which makes use of the 360's specialties. I had to take 2 things out, and move into a new "Add-On Layer": the HTTP stuff and the Database subsystem. The only other things that needed to be fixed were some data alignment issues and (naturally) byte order issues in the BinaryReader/BinaryWriter classes. I'll add some testing and benchmarking classes next week and then move on to the Render Layer.

Considering the differences between the 2 platforms (different byte order, 32 bit vs. 64 bit, different compiler back ends), everything was completely painless. The usual first experience when bringing code to a new platform is looking at pages of compiler warnings scrolling by. On the 360 SDK most of Nebula3 compiled and ran out of the box on warning level 4 without warnings.

I really wish MS would bring ALL the high level XDK APIs and tools over to Windows! They already started with XACT, XInput and PIX, but there's so much more cool stuff on the 360 that's missing on the PC and which would make a PC game programmer's life so much easier...

PS: Prince Of Persia Classic rocks. Best Arcade game ever :)

13 Jun 2007

It Begins...

CvsMonitor rocks

If you use CVS for version control and don't know CvsMonitor yet you should definitely have a look at it. It provides in-depth stats to cvs repositories and most importantly, provides a changeset view, so you can see immediately who's responsible for breaking the nightly build, hehe...

Here's the link: http://ali.as/devel/cvsmonitor/index.html