🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Untitled

posted in DruinkJournal
Published September 07, 2007
Advertisement
Well, I've been off work this week (You might have noticed me posting slightly less o the forums [lol]). But for a change, I actually got some coding done. Hooray!

Firstly, my engine can now use vertex shaders quite happily. Only models use them at the moment, not sprites - but I'll get around to that fairly soon. I was actually quite surprised at how easy vertex shaders are to use, and it also got me thinking that I really need a way to precompile shaders instead of compiling them at load time, although I don't know if that's likely to cause any problems; or rather if D3DX does any optimisation for the card when it's compiling. But I'll burn that bridge when I come to it.

I've also got MD2 model loading working, and animaion, and a helper class to handle animation sequences. Some example code:
// Load modelEModel::SP pModel = new EModel(L"gladiator.mdl");ESceneMgr::Get().Add(pModel);EGraphics::Get().Touch(pModel);m_pModelAnim = new EModelAnimator(pModel, 1000.0f / 15.0f); // Animate at 15 FPSm_pModelAnim->SetSequence("walk");// Main loop:EInput& input = EInput::Get();if(input.WasKeyTapped('A'))   m_pModelAnim->SetSequence("attack");else if(input.WasKeyTapped('B'))   m_pModelAnim->SetSequence("walk");else if(input.WasKeyTapped('C'))   m_pModelAnim->SetSequence("run");m_pModelAnim->Tick(ETimer::Get().GetFrameTime());

Touching a model will create the context for the model, which will load it from the resource pack, get the shader (load and compile it if needed), and set up the VB and IB for the model. The SetSequence() function has an optional parameter that lets you specify if you want to blend to the new sequence, or just snap to it, defaulting to "blend".

And yes, yes, I know I've got singletonitus. I've been doing a bit of tidying up in the engine code, E.g. passing a PGraphics reference to PVertexBuffer::Create() instead of using the singleton Get() function, but there's still quite a few singletons that I think fit perfectly well with the singleton pattern. Those are:

  • EInput - Keyboard and mouse input

  • EResourceManager - Unpacks, caches and returns resources from the pack file

  • EGraphics - Graphics system

  • EAudio - Audio manager


I know someone's going to have something to say about my "manager" classes, particularly graphics and input. But my reasoning is there will only ever be one output device. There will only ever be one input and audio system, and they need to be referenced from all over the app (Primarily for convenience, the game class could store them internally I suppose).

Anyway, I still heart singletons. And they haven't shat on me (yet).
Previous Entry Untitled
Next Entry Untitled
0 likes 3 comments

Comments

Demirug
Quote: Original post by Evil Steve
I really need a way to precompile shaders instead of compiling them at load time, although I don't know if that's likely to cause any problems; or rather if D3DX does any optimisation for the card when it's compiling.


It is the recommend way to precompile shaders. The shader compiler doesn’t care about the hardware in your system.
September 07, 2007 02:36 PM
LachlanL
Maybe I'm being naive here, but does precompiling shaders really save you that much time?
September 07, 2007 09:23 PM
Evil Steve
Quote: Original post by LachlanL
Maybe I'm being naive here, but does precompiling shaders really save you that much time?
Stepping over the D3DXCompileShader() call in the debugger, it takes a noticible time (maybe 250ms - 500ms). So I'd assume that it does, yes.

And that's only to compile this shader:

//============================================================================
// Basic.vsh - Basic vertex shader. Performs basic transform of vertices
//============================================================================

float4x4 mWorldViewProj;	// World * View * Projection transformation
float4 Diffuse;				// Diffuse colour for vertices

//============================================================================

struct VS_OUTPUT
{
	float4 Position : POSITION;	// Vertex position
	float4 Diffuse : COLOR0;	// Vertex diffuse color
	float2 Tex0 : TEXCOORD0;	// Texture coordinates
};

//============================================================================
// Shader entry point
//============================================================================
VS_OUTPUT Main(	float4 Position : POSITION0,
				float3 Normal : NORMAL0,
				float2 Tex0 : TEXCOORD0)
{
	VS_OUTPUT Output;

	Output.Position = mul(Position, mWorldViewProj);
	Output.Diffuse = Diffuse;
	Output.Tex0 = Tex0;

	return Output;
}

//============================================================================


(Yes, I know it's ignoring normals [smile])
September 08, 2007 07:06 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement