Archive

Archive for March, 2009

New ConstantBuffer System

Since the last time I’ve done a lot of changes to my D3D11 Game Framework. I completely reworked my GraphicsSystem. The GraphicsCoreSystem is now gone,  this means not every call to the GraphicsSystem is a virtual method call, any longer.

I had implemented this CoreSystem to make it more platform independent. But I changed my mind, I don’t think that I will use this Framework on any different platform then Windows Vista or Windows 7. These OS both support D3D11 so I will not try to use this framework on XP or any other Platform.

I also switched the SDK Version from November to March, without the need for any changes in code. This also has changed since D3D9, fortunately:)
I also moved my Math Code from D3DX Math to XNA-Math, which was added in the November SDK.

 

But now to the new D3D11 Constant Buffer System, I implemented. The sample way(shown in the Samples of the D3D11 SDK) is to have one struct for each ConstantBuffer. This was also the way I had implemented it. But this doesn’t work when loading shaders dynamically, because at compile time we don’t know anything about the ConstantBuffers the Shaders will be using.

So I started to design a system, which I got working so far. I think it is a good starting point and new features can be implemented on top of it. So lets have a look how it works.

clip_image001

The System now is divided into 3 classes.

  • ConstantBufferBuilder
  • ConstantBuffer
  • ConstantBufferElement

Before we start talking about the system, lets have a look at all the Code involved, as it’s easier to understand having seen the code.

GanbatteEngine::Graphics::ConstantBufferBuilder builder2(L"VSPerPassCB",L"PerPass");
builder2.Add<XMMATRIX>(L"View");
builder2.Add<XMMATRIX>(L"Projection");
 
graphicsDevice->CreateConstantBuffer(builder,&VSPerPassCB);
 
ConstantBufferElement* element = VSPerPassCB->GetElementByName(L"View");
element->SetDataSourcePtr(&view);
 
renderingContext->UpdateConstantBuffer(VSPerPassCB);
 
renderingContext->SetConstantBuffer(0,VSPerPassCB,VertexShaderStageBind | PixelShaderStageBind);

This is all the code necessary to create and use ConstantBuffers.

Firstly we create a ConstantBufferBuilder. Like the name says already it’s only purpose is to build ConstantBuffers. It takes the name of the ConstantBuffer and the frequency of updates for this buffer.

The creation of a ConstantBuffer was moved into the Builder because a ConstantBuffer is not allowed to change after it was created. To make it easier to create the ConstantBuffers at runtime dynamically the Builder was introduced.

To create a ConstantBuffer we just call “CreateConstantBuffer” and pass the builder into it.

After the ConstantBuffer is created we can get access to every element in the buffer by its name.

When we have the “ConstantBufferElement” we can just set the pointer on the data for this element. This currently is just working on void* pointers, so we are not typesafe in this place. Maybe I will change it at someday, to make it typesafe.

Now we have just 2 methods left, the first is “UpdateConstantBuffer” we just call it passing in the ConstantBuffer. This will copy the data of the ConstantBuffer into GPU memory.

And of course “SetConstantBuffer”, this will set the ConstantBuffer on the rendering context. We call the method with the input Slot(it will be set it on this slot), the ConstantBuffer to set and we define on which ShaderStage the ConstantBuffer will be set. Every ShaderShader Stage which is accessing the ConstantBuffer elements, needs the  ConstantBuffer bound to it.

As you can see the system is quite simple but also powerful. I really like it. So lets get on improving the other parts of the EffectFramework.

Categories: D3D11, Ganbatte Engine

DirectX SDK March 2009

March 24, 2009 Jendrik Illner 1 comment

Mirosoft finally released a new DX SDK, the March 2009 version this time.March 2009 DirectX SDK

New stuff for D3D11:

The Multithreaded Rendering sample got an update and now shows something more interesting than the good old “tiny” in 3 mirrors: below you can see the updated sample.

image

SubD11 Sample was updated, the clown is gone as announced at the talk at the gamefest 2008. :)

image

But sadly there is no FX Framework for D3D11 in this release, so I can work on my own system without having to deal with the feeling that I’m reinventing the wheel:)

XNA Math

XNA Math was added to the SDK, this provides a cross-platform math solution for both XBox360 and PC taking advance of the underlying support for SIMD. This is supported for all platforms but also a fallback for platforms not supporting SIMD instruction is in the package.

The sample for XNA Math, contained in the SDK, shows XNAMath being used for Collision detection. It contains a lot of useful function.

XNA Math really looks great, especially it’s implemented in one header(xnamath.h) only and because of that we have full access to the source and it’s heavily inlining the operations. A big advantage over the D3DX math libraries which were closed and compiled into libs.

Samples Content Exporter

The Samples Content Exporter is really a cool tool which is new to this version of the SDK. It has the ability to import .fbx an other file formats, which are supported through the Autodesk FBX SDK, and export the scenes to .xatg(used for the XBox 360 Samples) or to .sdkmesh (used for the windows samples).

But a warning, this tool was developed for internal use, to help with the sample development. But because it could be interesting for other developer as well, it was released to the public. Therefore it’s not officially supported, in terms of new features or fixing of existing bugs.

But I think this is a great move to make it available. Especially using the Autodesk SDK it is using a great technology in the back for importing, this should it make a lot easier to load scenes into D3D. I will have a look at it tomorrow.

 

There are a lot of other changes and improvements I can’t talk about in this post. So have a look at the SDK on your own.

Something more

  • Technical Previews of Direct2D, DirectWrite, and DXGI 1.1
  • Introducing XNA Math
  • Audio Improvements
  • Improvements to PIX
  • Updated Game Explorer Tools, Samples and Documentation
  • New and Updated Samples
Categories: D3D10, D3D11, Math

Small World Prototyping Graphics

Danc, from lostgarden.com has released a new stunning set of free graphics. He called the pack Danc’s Miraculously Flexible Game Prototyping Graphics for Small Worlds.

Screen:

Currently the pack is not available as exported .png files but in .swf, .ai, .fla(CS3 and CS4).

I needed the files in .png so I exported them and I’m making them available for anybody to use, when Danc releases his pack I will change the link to his pack from here.

Download: download

Has anybody an idea of how I could get the files into Expression Design 2? I always failed importing…

UPDATE: updated the file, there was an error with some exported pictures, fixed

This pack is really great work, thanks Danc once again. Lets see if I can make a great game with it. I have some ideas already, stay tuned.

Below you can see some examples of the exported files.

Buildings:

use42193 use42199 use42212 use42355 XMLID_2_ XMLID_39_

Plants:

XMLID_64_ use42294 use42326 use42359 use42390 XMLID_22_ XMLID_63_

There is a lot more in this pack than Buildings(a lot more than shown here) and plants, so have a look on your own.

Categories: 2D Graphics

Ganbatte Engine Progress Report 2

Some more progress in the development of the GanabatteEngine. Since the last post I got Texturing and DepthBuffer support added into the engine.

clip_image001

The Core Layer gets more and more features, now it finally has all the features so I can start working on the next level of functionality. The next feature I will look start implementing is Model support. 

Before I will begin implementing the model class I will have a look at the different available Importers, especially into Assimp.
Assimp is short for Open Asset Import Library and the name describes it really well. It currently contains importers for 26 different Model Formats including Collada. I will especially look at the Collada support because it gets widely adopted by a lot of tools and I know how hard it is to write an importer for it :) (I’ve written one for use with an XNA application…).

So lets see how well it will play out.

Stay tuned.

Categories: D3D11, Ganbatte Engine