Home | Download | Implementation Notes | Screen Shots | Contact
 

Implementation Notes

In this page, we will describe the issues that we have encountered during the development of our program. We would like to thank everyone in XNA Creators Club Online forum who have helped us to solve some issues. The forum is very active and provide quick responses in all our questions.

Developing in PC and Deploying in both PC and XBOX360
This is the dream that we have when we first encounter XNA. We develop the code in PC and deploy it in PC and XBOX360. However, we need to be aware of the differences between PC and XBOX360. PC supports more feature than XBOX360. The XNA documentation provides clearly which features are supported in XBOX360 and/or Windows.

The most convenient way to develop in PC and deploy in both PC and XBOX360 is by creating a single solution with 2 projects, i.e. Windows game project and XBOX 360 game project. The only glitch is that every time we add a new file to the windows game project, we also need to add it to the XBOX 360 game project. This does not mean that we will have two different files, they will share the same files. Below is step-by-step guide to create single-solution-two-projects which is ready for deployment in PC and XBOX360:
  • Open XNA Game Studio Express
  • Create a new Windows game project, File->New Project->Windows Game, i.e. "GameWin32"
  • Create a new XBOX360 game project, File->New Project->Xbox 360 Game, i.e. "GameXbox360"
  • Assuming they are created in C:\, copy C:\GameXbox360\GameXbox360\GameXbox360.csproj to C:\GameWin32\GameWin32\
  • Delete C:\GameXbox360 folder, as we will not need it anymore
  • Open C:\GameWin32\GameWin32.sln
  • Add existing project "GameXbox360" located in C:\GameWin32\GameWin32\GameXbox360.csproj to this solution
  • If you add a new file to GameWin32 project, you also need to add it to GameXbox360 project (you can do it by dragging the files under GameWin32 to GameXbox360)
  • To compile and deploy in PC, right click on GameWin32 -> Set as a Startup Project, then run it (Ctrl - F5)
  • To compile and deploy in XBOX360, right click on GameXbox360 -> Set as a Startup Project, then run it (Ctrl - F5)

XNA Animation Component Library
XNA natively supports loading .X and .FBX models; however, there are little support to do skeletal animating/skinning. XNA Creators Club Online has released a sample on how to process and render a skinned character model using the XNA Framework Content Pipeline (link). We opt for simpler approach by using XNA Animation Component Library found in CodePlex.

Coordinate System and Polygon Winding Order
If we are using different kinds of Graphics API/Framework, we need to be careful with the coordinate system, polygon winding order and order of vector-matrix multiplication. OpenGL, DirectX and XNA use three different conventions regarding those matter. The table below summarizes the differences between them:

OpenGL DirectX XNA
Coordinate System Right-Handed Left-Handed Right-Handed
Polygon Winding CounterClockwise Clockwise Clockwise
Vector-Matrix Multiplication Right-To-Left Left-To-Right Left-To-Right

Render Target
In order to store the shadow map and occluder information used to generate hard shadow/soft shadow, we wanted to use 32-bit Vector4 RenderTarget2D. However, it turns out that XBOX360 does not support 32-bit Vector4 RenderTarget2D, so we are forced to use 16-bit HalfVector4 RenderTarget2D, this results in some precision problems, thus lower shadow quality.

JFA Cut off
The implementation is based on the algorithm provided from the paper. We use 1+JFA to generate the penumbra map to get slightly better result. 1+JFA is known to be able to reduce the error of JFA. Since our texture has high resolution, 2048x2048, it will require 11 passes of JFA to fully propagate the occluder information. We do not perform full JFA, instead we use only 7 passes of JFA, specifically, the step lengths are 1, 32, 16, 8, 4, 2, 1. We have some artifact which is sudden cut-off of smooth transition of soft shadows. However, generally we get convincing enough soft shadows.

Tree Rendering
Our scene rendering consists of two parts:
  1. Rendering the depth + occluder information (Occluder information is stored in RGB and the depth is stored in Alpha Channel)
  2. Rendering the scene with shadows Most objects can be rendered without any problems.
However, this is not the case with trees. Tree leaves are usually modeled using just a quad and textured with a leaf texture which contains alpha channel. This alpha channel indicates which pixels are visible and which pixels are not. Most common technique to render this is to use alpha blending and set the SourceBlend to be SrcAlpha and DestBlend to be InvSrcAlpha. However, doing this requires us to set the alpha value for each pixel. We could not do this because the alpha channel is used to store the depth. To solve the problem, we set some threshold and discard the pixels which are not visible in the pixel shader. Note that there is no "discard" instruction in XBOX360. The equivalent function which has the same functionality is "clip".

Fog in XNA
In Shader Model 3.0 and XBOX360, there is no dedicated fog hardware at all. So, it is entirely up to the developers to compute and apply whatever kind of fog that you like in the shader. There are two kinds of approach which may work:
  1. Defer Shading
    First, we render the whole scene and save the depth in texture. Subsequently, we render a quad to draw this texture and calculate the fog factor. The rendering passes would be render the depth followed by render the scene with shadows and fog. This requires two passes and is suspected to be slow. So we choose the second technique.
  2. Compute Fog Factor in Pixel Shader
    We modify all our shaders to include the fog computation. In this case, we use exponential fog. This is the easiest way to include Fog into your scene. However, you need to duplicate the fog computation in all the shaders.


 
(C) Copyright 2007 National University of Singapore - Department of Computer Science - School of Computing
Design by Infinite Pixel Studio - Special Thanks to Eddy - Last Update: May, 2007