Friday, 29 January 2010

Dynamic Cube Mapping - Part 3

In this example we will take the processes and clean them up.

Most math is now handled by the GPU, and a few extras have been added, which include HDR, Blur and Tone-Mapping.



XNA3.1 PROJECT DOWNLOAD

Saturday, 16 January 2010

Dynamic Cube Mapping in XNA - Part 2

okay guys. Here goes...

I thought I would save everyone some hassle and deliver you the WHOLE code needed to create Dynamic Environment Maps. The code produces a result as below:




The FX file used is a simple Reflection.fx effect. The secret is the manipulation of the 6 reflections rendered to RenderTargetCube.faces.

Cubemaps are generated from inside the virtual cube, so looking at these images from the outside of the cube-mesh creates unwanted results, as the UV's and normals are flipped.

It is just like turning your socks inside out !


XNA3.1 PROJECT DOWNLOAD

The regenerated cube-maps will work with any shader.

It would also be very easy to use these 'corrected' maps and blur/filter them to create ambience maps with very little overheads.

Included in the archive are various other shaders that you are free to use.

An XboxPC controller is required to rotate the scene objects. L_Stick for orbiters and R_Stick for the BMW car.

Enjoy!

Any questions?

Monday, 4 January 2010

Uber Shader

Here is my Uber Shader that i wrote, and promised to share with the XNA/Sunburn Community.

Capabilities:

  • Blinn

  • Phong

  • Oren-Nayar (Blinn + Phong)

  • Anisotropic

  • Single BDRF

  • Dual BDRF

  • Translusency/Sub-Surface Diffuse

  • Fresnel Reflection

  • Fresnel Color

  • Simple Reflection

  • Glow/Self Illumination

  • Offset Mapping

  • Parallax Occlusion Mapping

  • Micro-Normal Texturing


  • Techniques:

  • OneLight

  • OneLightAlpha2Sided


  • allInOne_FX_Shader

    Enjoy

    All I ask is, if you use it in a commercial game, please tell me and give me a mention in your credits. Thanks

    :-)

    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.