Sunday, 3 January 2010

Dynamic Cube Mapping Video

Dynamic Cube Mapping in XNA

RenderTargetCube RefCubeMap;
TextureCube EnvironmentMap;

...

protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);

// TODO: perform AI and physics etc...
// TODO: draw sky
// TODO: draw all solids (except PLAYER) with FAKE envCubeMap
// TODO: draw all transparencies (except PLAYER) with FAKE envCubeMap
// TODO: draw all shadows (except PLAYER) with FAKE envCubeMap

DrawEnvironmentMap();

// TODO: draw everything (including PLAYER) solids ONLY with REAL envCubeMap
DrawSky();
DrawObjectsInWorld();
DrawPlayer();
// TODO: draw everything (including PLAYER) transparencies ONLY with REAL envCubeMap
// TODO: draw everything (including PLAYER) shadows ONLY with REAL envCubeMap
}


//dynamic cubemap routine
public void DrawEnvironmentMap()
{
graphics.GraphicsDevice.SetRenderTarget(0, null);

viewMatrix = Matrix.CreateLookAt(Vector3.Zero, Vector3.Left, Vector3.Up);
effect.Parameters["matWorldViewProj"].SetValue(worldMatrix * viewMatrix * projMatrix);
this.GraphicsDevice.SetRenderTarget(0, RefCubeMap, CubeMapFace.NegativeX);
this.GraphicsDevice.Clear(Color.White);

// draw sky
// draw everything solids (except PLAYER) with a FAKE/static envCubeMap
// draw everything transparencies (except PLAYER) with a FAKE/static envCubeMap
// draw everything shadows (except PLAYER) with a FAKE/static envCubeMap
DrawSky();
DrawObjectsInWorld();
graphics.GraphicsDevice.SetRenderTarget(0, null);

viewMatrix = Matrix.CreateLookAt(Vector3.Zero, Vector3.Down, Vector3.Forward);
effect.Parameters["matWorldViewProj"].SetValue(worldMatrix * viewMatrix * projMatrix);
this.GraphicsDevice.SetRenderTarget(0, RefCubeMap, CubeMapFace.NegativeY);
this.GraphicsDevice.Clear(Color.White);

// draw sky
// draw everything solids (except PLAYER) with a FAKE/static envCubeMap
// draw everything transparencies (except PLAYER) with a FAKE/static envCubeMap
// draw everything shadows (except PLAYER) with a FAKE/static envCubeMap
DrawSky();
DrawObjectsInWorld();
graphics.GraphicsDevice.SetRenderTarget(0, null);

viewMatrix = Matrix.CreateLookAt(Vector3.Zero, Vector3.Backward, Vector3.Up);
effect.Parameters["matWorldViewProj"].SetValue(worldMatrix * viewMatrix * projMatrix);
this.GraphicsDevice.SetRenderTarget(0, RefCubeMap, CubeMapFace.NegativeZ);
this.GraphicsDevice.Clear(Color.White);

// draw sky
// draw everything solids (except PLAYER) with a FAKE/static envCubeMap
// draw everything transparencies (except PLAYER) with a FAKE/static envCubeMap
// draw everything shadows (except PLAYER) with a FAKE/static envCubeMap
DrawSky();
DrawObjectsInWorld();
graphics.GraphicsDevice.SetRenderTarget(0, null);

viewMatrix = Matrix.CreateLookAt(Vector3.Zero, Vector3.Right, Vector3.Up);
effect.Parameters["matWorldViewProj"].SetValue(worldMatrix * viewMatrix * projMatrix);
this.GraphicsDevice.SetRenderTarget(0, RefCubeMap, CubeMapFace.PositiveX);
this.GraphicsDevice.Clear(Color.White);

// draw sky
// draw everything solids (except PLAYER) with a FAKE/static envCubeMap
// draw everything transparencies (except PLAYER) with a FAKE/static envCubeMap
// draw everything shadows (except PLAYER) with a FAKE/static envCubeMap
DrawSky();
DrawObjectsInWorld();
graphics.GraphicsDevice.SetRenderTarget(0, null);

viewMatrix = Matrix.CreateLookAt(Vector3.Zero, Vector3.Up, Vector3.Backward);
effect.Parameters["matWorldViewProj"].SetValue(worldMatrix * viewMatrix * projMatrix);
this.GraphicsDevice.SetRenderTarget(0, RefCubeMap, CubeMapFace.PositiveY);
this.GraphicsDevice.Clear(Color.White);

// draw sky
// draw everything solids (except PLAYER) with a FAKE/static envCubeMap
// draw everything transparencies (except PLAYER) with a FAKE/static envCubeMap
// draw everything shadows (except PLAYER) with a FAKE/static envCubeMap
DrawSky();
DrawObjectsInWorld();
graphics.GraphicsDevice.SetRenderTarget(0, null);

viewMatrix = Matrix.CreateLookAt(Vector3.Zero, Vector3.Forward, Vector3.Up);
effect.Parameters["matWorldViewProj"].SetValue(worldMatrix * viewMatrix * projMatrix);
this.GraphicsDevice.SetRenderTarget(0, RefCubeMap, CubeMapFace.PositiveZ);
this.GraphicsDevice.Clear(Color.White);

// draw sky
// draw everything solids (except PLAYER) with a FAKE/static envCubeMap
// draw everything transparencies (except PLAYER) with a FAKE/static envCubeMap
// draw everything shadows (except PLAYER) with a FAKE/static envCubeMap
DrawSky();
DrawObjectsInWorld();
graphics.GraphicsDevice.SetRenderTarget(0, null);

this.EnvironmentMap = RefCubeMap.GetTexture();

// restore our matrix after changing during the cube map rendering
viewMatrix = Matrix.CreateLookAt(new Vector3(x, y, 80), Vector3.Zero, Vector3.Up);
effect.Parameters["matWorldViewProj"].SetValue(worldMatrix * viewMatrix * projMatrix);

// reset buffer
graphics.GraphicsDevice.RenderState.DepthBufferEnable = true;

}

Monday, 23 February 2009

About this site

This site has been created to answer those questions to many DirectX and OpenGL problems that many developers often come across.

It will also contain snippets, to aid in the learning process of those venturing into NextGen Deveopments for the major consoles (except Wii).

Further to this, this site will be a catalyst for my up-and-coming NextGen games (portable to all DX10+ capable machines). There are several in the pipeline: shootem-ups; FPS's; strategy; sports.... (basically every genre has been covered!).

Prototyping and main game-engine design will be discussed, appraised and demo-ed.

I consider my engine to much better than CryEngine2 and UT4, which runs very smoothly at 60fps at 1080p at 64bpp (A16R16G16B16). If my games sell well, then I may consider licensing it out to the gifted (!)

I am an ax-assesor in the field of CAD and C++ programming, and wrote most of the City & Guilds exam papers.

My fields of expertise are: Rhino, AutoCAD, Catia, Maya, 3DSmax, Cinema4D, XSI, SolidWorks, Modo, Mudbox, and NET/CLI realtime programming.

If you have any questions, please ask.
If I cannot answer them myself, then I will know who can, and forward you to them.

*** THIS SITE IS FOR HARD-CORE GAME DEVELOPERS ONLY ***

*** NO TIME WASTERS ***

I will try to get all your dilemmas put right as soon as I can, but please be patient.