Please support our sponsor:
DirectX4VB.Com - All You Need For Multimedia Visual Basic Programming

Main Site Links Resources Tutorials
News VB Gaming Code Downloads DirectX 7
Contact Webmaster VB Programming Product Reviews DirectX 8
  General Multimedia Articles DirectX 9
      Miscellaneous

 

DirectXGraphics: The Final Piece
Author: Jack Hoxley
Written: 29th May 2001
Contact: [EMail]
Download: Graph_18.Zip (3mb) - Patch01.zip (147kb)


Contents of this lesson
1. Introduction
2. What Went Wrong
3. Do as I say, not as I did
4. Conclusion


1. Introduction

So, it's come this far - 17 complete tutorials (from only 8 originally planned) covering pretty much everything you ever needed to know about DirectXGraphics 8. From the incredibly large volume of positive/complementary emails I gather that people have learnt alot from my work - which says it all for me really :) I seriously hope that you read these articles and go on to make some brilliant games and multimedia programs.

Whilst 17 tutorials are down, it does not mean that there will be no more - I have at least 4 more planned, but right now I need to wrap up DirectXGraphics and move onto the other areas of DirectX - otherwise DirectX 9 will appear and I wont have finished with 8..

The last tutorial in this series has been one I've been working on since the 1st of January 2001 - a total of 145 days at the time of writing. Admittedly I haven't been working on it permanently for that duration, but then again - who does spend every moment for 5 months on one project? <cough> This project was intended from square one as a final piece for this series - bringing all the threads together and making a simple playable game. It may well look pretty, but it really isn't that special - something for you to play with, learn from and hopefully adapt and improve upon. The whole project is in excess of 4000 lines of code - far far too big to put into the tutorial, so you'll have to download the code and look at it yourself. Onwards...

Above is an in-game screenshot of 3D-World. It's generated from height maps, and uses a high definition set of unique textures for each level. The player can navigate around the world and look at the tree's, the waves or just look at the view.


2. What Went Wrong

Probably not the best title for the first section of this article - but what did go wrong? a heck of a lot did! I almost feel embarrased releasing this project to you people - it really is not up to my usual form - but I've been promising it for ages now. The main reason I haven't cleaned it up and made it as good as I could is due to time - when you look at the code you'll see just how much there is to it; all of it was hand written by me - no copy-&-pasting here, hence a complete rewrite would have been foolish - if it was a game I wanted to try and get published I would of, but it's only a sample project... There are a lot of thing that went wrong, I've summarised a short list below:

  • Planning. There was none - In my opinion this was the biggest possible mistake, I shot myself in the foot from the beginning by not planning it. Learn from my mistake here... 3D-World was only supposed to be a simple game like world, ask anyone who recieved one of the very first drafts back in january - it looks absolutely nothing like the screenshot above. Over the course of the first 2-3 months it changed at least 3 or 4 times, I found out about some clever new tricks and stuck them in, and I then decided to play with compressed texture support - found that it worked very nicely indeed; so the worlds now have massive unique textures - which looks excellent, but slowed things down considerably.
  • Time. I was writing this project in my spare time, and at the same time as doing *proper* work and writing new content for this page - as you'll see from the log file, there were entire weeks where I didn't even touch the thing. This may not sound like a problem, but it is now - It suddenly reached the point where I needed it finished within 2 weeks; it was no where near as complete as I'd of liked it to be - all I had time left to do was tie up the loose ends and fix any of the larger bugs that I could.
  • The Engine. The engine has the same problem as with the general planning of the project, it wasn't designed to shift 10,000+ triangles per frame - and wasn't designed to handle the intensive calculations required by the project. It's class based - which is fairly slow, the graphics class is one massive 3200 line monster - splitting it up into 4 or 5 modules with well structured communication routes and data structures would have been much better; but by the time that requirement was apparent it was too late to go back - I was stuck with it as it was. There are also many features that I've talked about in these articles that I've told you to use, but haven't used myself - features and techniques that would have been much faster (Hardware Vertex Buffers for example). When running the game, hold down the "W" key to view the world as a wireframe mesh - notice the extremely high tesselation level; It would have looked much much better if it had been 1/4 of the density (4x scale), instead, to get even a reasonable draw depth you have to have an insanely powerful 3D card (even my GeForce feels the strain!).
  • Bugs. There are plenty of them; most of the critical ones I've managed to get rid of - but dont take this to be completely bug free. Due to the sudden rush for completion at the end I didn't get a chance to do any proper testing - therefore, I know it works on my computer, but I dont know if it will on every computer (It SHOULD do though).
  • umm, there is no game. You cant really call this a game - there is no objective, no missions, no points, no other characters - nothing. just you and a world! I would have implemented even a simple game if I'd had the time - but I didn't...

I'm very sure you'll be able to dig up some other stuff, but the points above are the important ones - you should take notice of them if they haven't come across before... Learn from this projects mistakes.


3. Do as I say, not as I do.

Now that I've outlined the things that went wrong - I want to explain what I wanted it to look like. Granted I just said I changed the design 3 or 4 times, this is what the final thing would of looked like if I'd of had time.

1. Rendering - currently it is just far far too slow, on a system I consider to be "average/good" it only just handles 25fps - more like 5-10fps when running through the VB IDE. This problem stems from the fact that the rendering system was never designed to render such a complex world, and I never had the time to upgrade it (apart from the fact it would of taken an almost complete rewrite). In general there are 4 main things I'd like to have changed:
a: Vertex Buffers, all of the geometry is stored in system memory arrays - this is about as slow as it gets, whilst fine for simple things it just cannot handle the huge number of vertices the landscape is made up of.
b: Index Buffers, these go hand-in-hand with the vertex buffers; there is an awful lot of replicated geometry, particularly due to the unique set of textures there are many vertices that could of been made into one single vertex (but 4 indices). A vertex buffer and an index buffer for each of the texture areas (16x16 in total) would have worked quite nicely.
c: Quadtree's, the view culling algorithm is very efficient and very accurate, but using a quadtree would have increased efficiency greatly, particularly if it reduced rendering down to blocks rather than individual tiles. Currently the engine checks the visibility of a set of tiles, and renders them if visible - checking the bounding box of a larger area and rendering 100 tiles at once would have been much faster.
d: LOD algorithm, even a simplistic Level Of Detail algorithm would have improved things - at the moment, the landscape 50m away has the same density texture and the same density geometry, this is inefficient and wasteful, having a low-res texture and a much less detailed landscape would have been better. LOD algorithms can be very complex, but I think it would have been worth the effort.

2. General Rendering arrangement - There are quite a few situations where entire areas could have been simplified away to 4-5 triangles, rather than having 40-50 triangles; and the overall density of the geometry is far too high - even 1/4 of the density would of looked good - yet either allowed for a much faster engine OR for the same triangle count a much larger draw depth. Further more, about 90% of the available triangle count is used up rendering the landscape - making it almost imposssible to render large numbers of objects at a reasonable speed. Trees are prohibitively expensive to render, so opting for the semi-billboard method for rendering would have been better - being able to populate 3D-World with a forest would be something special indeed. Finally, texturing - the textures are very pretty (in my opinion), but they require hardware support for DirectX Texture Compression Level 1 (D3DFMT_DXT1), uncompressed there is almost 48mb of textures per level - this dissolves down to 8mb when compressed. Doing something about this would be beneficial - using a high detail tile set instead would of been worth looking into. Alternatively, the current texture is 8 pixels to every meter in the game world (8:1 ratio), cutting this down to 4:1 and applying a detail texture (using the texture cascade) would have been a good option.

3. The Editor, and the files - Each level is almost 50mb, if it were being distributed on a CD then this is of no problem, but understandably it isn't ideal. Even using compression it's still 30+mb. Textures make up 99% of that total, and are currently stored as bitmaps, making the editor save them out as DXT1 format would have made them much much smaller, AND had a speed improvement when loading at runtime - no conversion is necessary.
With regards to the editor - it's not that good! It suffered from the same problem of having bits bolted on as and when I needed them, and there is almost no optimisation at all - generating a texture takes upto 4 minutes a piece, and there is no decent interface. I'm quite happy with the feature set for generating the landscapes - there are quite a few clever techniques in there for you to explore. Having said that, it would of been nice to allow the user to manually edit the landscape in some form, as it stands you can only apply deformations and effects to it.

4. Special Effects and added features - If I'd of gotten time I wanted to add a few special effects and/or cleverer features. None of them are particularly complicated, but combined with the existing engine I think they would have worked quite nicely. Here's a brief list of what I had in mind:
a: Sky dome, instead of the rather simple sky rendering done at the moment, a Sky-Dome would have looked much better and would have allowed me to implement complete all-round vision, where the player could look around the world in the same way they would in a first person shooter.
b: Lens Flares, everyones got one these days! and why not - they look pretty and they're extremely simple to program...
c: Better Lighting, currently all there is is a directional light emulating the sun and some ambient lighting; a more dynamic and artistic approach to the lighting could have produced some stunning results - I was tempted to add some "Northern Lights" into the mix, but decided against it in the end.
d: Wildlife, as well as some trees and bushes it would have been nice to have a few birds flying around in the sky and some animals roaming the landscape; but the only thing that stopped me here was the lack of suitable models - I simply could not find any reasonable models of birds, cows, foxes etc... even something as simple as a tree... Simple flocking and AI could have coordinated the movement of 3D-World animals.
e: Day/Night cycles, whilst simply an extension of the better lighting, it would of been interesting to allow night time visits to 3D-World...


4. Conclusion

So, now I've explained as much as possible about the project, there are a few quick and simple facts that you might benefit from knowing

The Keyboard controls (no mouse of joystick support)
- Up/Down/Left/Right move's you around the world
- Space/Ctrl moves you up/down vertically (you can only go so close/far from the current landscape height)
- S shows the status window
- M shows the map
- W renders the landscape in wireframe mode
- Esc exits back to the main menu.

General Information
- The world is 500x500 units wide
- Absolute minimum system requirements will be a 450mhz processor with a reasonable 16mb video card.
- Recommended requirements will be 800mhz Athlon/Pentium 3 with a 32mb 4th generation video card.

As for the future - Anyone who is interested in this project may do whatever they want with it, if you have a lot of time to spare then you are more than welcome to take my suggestions in section 3 and implement them - or add some completely new things; alternatively, just rip it to pieces and extract the interesting parts - whatever you do is upto you. I'm interested if you make any particularly big improvements to the existing engine, and you never know there may well be a place of honour on this site for someone who substantially improves it...

Finally, with regards to the download - for previously mentioned reasons, there are no worlds included in the download. The editor is complete so feel free to use that and generate a world for you to look around...

DirectX 4 VB © 2000 Jack Hoxley. All rights reserved.
Reproduction of this site and it's contents, in whole or in part, is prohibited,
except where explicitly stated otherwise.
Design by Mateo
Contact Webmaster
This site is hosted by Exhedra Solutions, Inc., the parent company of RentACoder.com and PlanetSourceCode.com