Friday, December 18, 2009
Scripting a simple Game in UDK
First create a directory in your \Development\Src\ and give it the same name i.e. SGGame. In it, create a directory called Classes.
Next, let’s create a file in the Classes directory and call it SGGame.uc. Open the file in your favorite text editor and type in the code below.
class SGGame extends UTGame
config(Game);
defaultproperties
{
}
This basically defines a class called SGGame that extends the UTGame class. Generally, your game will extend a subclass of the GameInfo class. By extending the UTGame (also a subclass of GameInfo) class we gain a lot of functionality that we would require for an FPS game.
Now let’s compile our game just to make sure everything is fine so far. To do this, we want to run the UDK executable with a special command line argument – make. To make this easier as we will be using it a lot, we will make a shortcut on the desktop for this.
Go into the \Binaries\Win32 directory and copy the UDK.exe file. Right click on your desktop and click on Paste Shortcut. Rename the shortcut to Compile UDK Scripts. Right click on the shortcut and go to its properties. In the target section, add make.
Mine looks like this - X:\UDK-2009-12\Binaries\Win32\UDK.exe make
Running this right now will not compile your new game’s scripts because UDK does not yet know about our new game. To do this, we need to modify one of the .ini files. Go to \UTGame\Config and open DefaultEngine.ini in your text editor.
NOTE: By default, the file is read only; you need to make it writable from its properties to make these changes.
Scroll down to the [UnrealEd.EditorEngine] section and add the following line.
+EditPackages=SGGame
The UnrealEd.EditorEnginesection is used by the compiler to determine which packages exist and need to be compiled when they change.
The + (plus) basically tells the engine to add the line in the generated UTEngine.ini file.
NOTE: Whenever you make a change to the DefaultEngine.ini the engine will generate a new UTEngine.ini file on the next run. More information on this can be found in the Configuration File section of UDN.
Double click on the compiler shortcut to compile our game’s scripts. If there are any syntax errors in the file, you will get the warnings/errors in the compilation window. It should however compile without any problems.
It’s time to see what we’ve done so far. We will load up the examplemap map for this. We’ll use another shortcut and command line argument to run the map with our game. Copy and paste a UDK shortcut like we did before. Call this Simple Game(or whatever else your prefer). Open its properties and add ExampleMap?Game=SGGame.SGGame
This basically tells UDK to load the map called ExampleMap and run the game called SGGame in the SGGame package.
There you go; you have a basic game up and running.
The UDK bandwagon
I've been using it since early November and its a hell of a steep learning curve but at the end of the day, its Unreal. I've joined a small indie team as an Unreal Scripter to work on a project called Nothern Island 1983.
The feature list is very impressive, including speed tree, face fx, the unreal editor in all its glory, documentation via the UDN and recently released video tutorials. Christmas really did come early this year and the Indie(read me) has to stop making excuses.
Tuesday, April 8, 2008
Brute Terrain texture splatting
Using nebula's fixed function render path, I need a pass for each detail texture plus an additional pass for the base texture and the performance is not too bad with 3 detail textures and a base texture. Since I was developing using the fixed function render path, it didn't occur to me that on shader model 2.0 hardware, I only need 1 pass to blend all my detail textures (4 so far) plus my base texture. Since the whole idea was to improve the look of distant geometry it really doesn't make sense anymore (see below). Plus I can use a single image to store alpha maps for 4 detail textures in each of its 4 channels.
About my splatting implementation; Initially, I wanted to blend the base texture based on the camera's distance from the particular point being rendered. As a first step to that, I tried a fixed blend value of 0.5 which looked really good. I then used the camera's distance method and distant geometry didn't look as good as with a fixed value. So I decided to go with the fixed value version.
See for yourself


I'm pretty happy with the results but any criticism/comments are welcome
Monday, March 31, 2008
Brute force chunk NO-LOD terrain
Distant primitives look very obviously tiled. So I had a bright idea (I think). I want to split the terrain mesh into chunks. I believe the beauty of brute terrains is that the entire terrain is uploaded once into the graphics hardware, now I want to split the beauty of it?
With Splatting
Without Splatting
The whole point of chunking it is so that distant chunks will be rendered using the large diffuse texture and a single pass. Chunks closer to the current view will be rendered using a splatting shader and a number of detail textures. I’m not trying to gain any speed improvements but rather to get rid of the tiling in distant geometry. I’m thinking I should get a trade of by gaining some speed for reducing the number of passes in distant geometry and loosing some speed for sending more batches of geometry so I’m hoping for pretty much the same frame rate as I’m getting now with splatting.
Wish me luck.
Brute … not so bad
When I initially developed an interest in making games, I never thought I would have to do a terrain, I remember skipping the terrain chapter in a DirectX book I was reading back then. Needless to say I went back to said chapter over the weekend.
I now have a brute force terrain renderer which uses nebula’s default standard shader with a diffuse texture stretched over the terrain. You can imagine that the texture up close is anything but pretty.
Here is how it works. The terrain object requires an input heightmap with 8 bits per pixel. You may also provide a tile size parameter which is used to determine the number of vertices required plus to control the resolution of the terrain. A higher tile size means less vertices and a less smooth terrain.
Say we provide a heightmap of 1024 x 1024 pixels, a terrain of 1024 x 1024 units will be generated. If we had set the tile size to 32, we will end up with a vertex every 32 pixels/units. Therefore we will end up with 33 x 33 vertices for a 1024 x 1024 unit terrain which is pretty decent but what I’m most impressed about is the frame rate. I’m getting a frame rate of about 120 on a laptop with an intel chip though its still needs work on the texturing.
My plan was to get a basic brute force implementation rendering then immediately move on to a chunk lod implementation. Right now, I’m actually thinking I can get away with brute force so I’m looking at whether I can add texture splatting to it and see how far I can get with it.
A question for anyone who can provide some insight on using triangle strip primitives. According to the direct sdk docs, every 2nd triangles should be oriented reversed for it to work properly. I can’t get the terrain to render properly using triangle strips. Looking at the bottom of the terrain, I see holes on every 2nd triangles and from the top it seems fine but I can see hanging meshes on some parts of the terrain.
Choosing an engine … again
As far as game engines go, I’ve been around the block and back a couple of times. I have tried my hand at every engine I could get my hands on. I don’t know if it’s just me but every once in a while I question my choice of a particular engine and retry engines that I had already decided against. We’ll, it’s that time again. If you’ve read my previous posts you might have figured that I’m totally sold on the nebula device.
Lately while laying out the ground work for project samurai, I have had doubts about using nebula for it. Almost the entire game is set out doors with vast landscapes, a lot of vegetation (grasslands and sparse trees). In its current state, nebula has no functioning terrain renderer. There is a multilayer scene node that I think is basically a brute force terrain implementation and in my view doesn’t look very pretty.
Some time last year while on one of my engine quests, I came across S2 Engine. Back then it was in version 1.4 and had no terrain implementation. Something else that put me off is that they didn’t/don’t provide a demo. Its videos and screenshots looked very impressive but I decide against it mostly since I couldn’t try it myself. Now version 1.5 has just come out with a lot of improvements including terrain rendering, vegetation painting and mesh instancing. Again the videos and screenshots look impressive. Being part of a really small team it looks like an ideal solution for project samurai.
The only disadvantage of using S2 is that for a 135 euro version, I can only use the engines script interface and I’ve always been one who likes to look under the hood. There is an option to upgrade to a license that provides a C++ SDK and another pricier option that provides full source access.
I’ve been looking at the available terrain renderers with the aim of picking one to fix. The two available ones are both based on Thatcher Ulrich’s work on chunk LOD terrain. The first one, nclodterrain has some pretty nice tools for generating terrain meshes and textures but on running it, my terrain seems to be tilted 90 degrees around the X axis. The other one, ncterrain2 just displays a box; I’m still trying to figure that one out.
I have no intention of abandoning nebula but I think using S2 will speed up our development. In the mean time, I’m planning on working on a terrain implementation for nebula but I don’t want project samurai’s development to be tied to this.
Wednesday, February 20, 2008
Blender exporter re-write
I wrote a few stand alone scripts over the weekend just to test the python API and see how I can integrate it with nebula. Initially I didn't know much about nebula's animation files and I had to figure it out the hard way, by looking at existing code, specifically the 3DS Max exporter which was a lot of help. Nebula's documentation also offered some help.
By yesterday, I could export animations but my script still has a problem exporting the initial skeleton's pose. I posted my problem on blender's forum and went on with re-writing the rest of the exporter.
The mesh exporter is pretty much done and I just started working on adding animations yesterday. I've already run into a problem with transform animations though, I cant figure out how to get key frames from a blender object IPO yet but I'm looking into it. In the mean time, I will work on skin animation support, getting key frames for this is pretty straight forward, I wish it was as straight forward for object animations.



