PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

a basic 3d engine

this is a very basic 3d engine. it uses the pockethal win32 libs.

http://www.mousepeople.com/my3d.zip

this is the first engine i built myself. these are what i learned and implemented, so far:

texture mapping
vertex shading
uvn camera system
matrix stack (for model coordinates)
z-buffer
polygon clipping (z-plane only)
and also some sort of vertex caching

i used two books for reference: OpenGL Game Prog. and Tricks of the 3d...

the pocketpc version is still very slow.
the next thing to learn is optimization.
Impressive work Izeman. It is not often I see people code 3D stuff in software these days!

Looking forward to see the thing running on a PPC!
very nice work!

if you need some help on the optimization you might want to have a look at our Klimt library. it's open source and has (not totally, but still) optimized texturing, shading and blending routines...

or you simply ask here in the forum. there are lots of people who really know at lot about optimization.

DANIEL
i saw your announcement of softgl at flipcode. it intrigued me when i read it was running very well on pockethal. and this got me started experimenting with writing an engine. (i ended up buying a reference book).

i downloaded your library. i like the way the scanline function was handled - only one page of code that produces 300+ types of functions.

i only have one scanline renderer. it has many if-else and unreadable macros. i think i'll apply your technique when i clean up my code.
well, in fact i got rid of this ugly scanline renderer just this week (the new code is available in version 0.5). the problem is that a full feature set of OpenGL|ES would result in something like 100k functions.

instead i now have a completely other way of combining all the possible features (shading, texturing, blending, fog, etc...), which is per scanline instead of per pixel as done before.
this way i produce only very little code and it works at more or less the same speed as the old scanline function (this is very similiar to the way mesa does its scanline rendering).

bye,
DANIEL
Jadam wrote:
Check out this book

http://www.gamedev.net/columns/books/bo ... ductid=101


Would definitely recommend this book as well. One of the primary texts I'm using for my thesis.
I'm having a little 3d engine too... :)

<IMG SRC="http://www.home.fh-karlsruhe.de/~bape0016/shot1.jpg"></IMG>

A little demonstration can be downloaded here: http://www.home.fh-karlsruhe.de/~bape0016/download.html
Cool, looks like one of those Farb-rausch demos.
peter that was stunnin :D nice work!
xPeterx wrote:
I'm having a little 3d engine too... :)

<IMG SRC="http://www.home.fh-karlsruhe.de/~bape0016/shot1.jpg"></IMG>

A little demonstration can be downloaded here: http://www.home.fh-karlsruhe.de/~bape0016/download.html


Hi Peter,

Is it possible to create a 3D engine for mobile devices too? I havent tried mobiles yet.

DenthorQ
the demo look gorgeous!
good work...

DANIEL
denthorq wrote:
Hi Peter,

Is it possible to create a 3D engine for mobile devices too? I havent tried mobiles yet.

DenthorQ


Are you talking about Smartphones?
I guess it depends on what you're aiming at! What kind of a 3d engine do you want to develop?

Peter
izeman: I presume your engine is fixed point?
Peter: I'm talking about cellphones like nokia, motorola, samsung etc? ;-)
I direct you towards these articles by our very own phantom

http://www.flipcode.com/articles/articl ... fx01.shtml
Thanks ;-) Happy Holidays !
Jim wrote:
izeman: I presume your engine is fixed point?


yup. i'm used fixed point. i also have a lookup table for reciprocals and a division table.

the slow code seems to be in clearing the screen and z-buffer
Exocet":ktonkyef]


I was wondering since I dont actually have that book, The book says it uses OpenGL, What for? Does it use OpenGL for rendering? or just for blitting.

Also does the book teach you how to write a 3D engine and a software rasterizer?
i did not read that book but from the list of topics it covers i'd say that the software rendering part is not really covered there in large depth.

for writing a 3d engine with a software rasterizer i suggest you have a look at "Tricks of the 3D Game Programming Gurus-Advanced 3D Graphics and Rasterization".

although the book wastes lots of pages for code (instead of providing a good, final version of an implementation the author develops everything step by step) it's the best book i know about this topic. (anybody any other suggestions?)

besides this you can find lots of really good articles in the net...

i already thought about writing an article for one of the major game developer sites on how to start PocketPC game programming, which tools and libs to use, current bottlenecks, etc...

bye,
DANIEL
Are there any sites/books around that discuss perspective correct texturing in fixed point? Everything I've found has been rather PC-oriented, using the FPU...

I had a go at it a while back, without a whole lot of success (precision/range problems)
the conversion from floating point to fixed point would be VERY slow - even on CPUs with floating point support. for this reason it makes no sense to use floating point texturing (except for high precision) in a software rasterizer.

i can recommend the texturing code at
http://www.gamedev.net/reference/articl ... cle338.asp

it does use floating point, but it's quite easy to convert it to fixed point (well, the gradients calculation can be problematic) and to use piecewise interpolation. i use a heavily modified version of this code in Klimt since i wanted to start from robust and clean code...

DANIEL
<img src="http://www.mousepeople.com/3d/shot031229b.bmp">

i've finished adding an md2 model viewer.
the engine now sacrifices quality (interlaced both horizontally and vertically). hence, i'm able to clear only 1/4 the z-buffer :P

but the output was a little too crisp and pixelated.
so, i applied a simple dither right before swapping the buffers.
Cool, what kind of framerates are you getting with that model? And the amount of polies?
i get around 14fps on my device. (the orgo has 670 faces)

you can check on yourself. warning! i've only tested on ipaq 3600. and i'm not quite confident if i accessed frame buffer the proper way

http://www.mousepeople.com/3d/
drgoldie wrote:
the conversion from floating point to fixed point would be VERY slow - even on CPUs with floating point support. for this reason it makes no sense to use floating point texturing (except for high precision) in a software rasterizer.


I thought Quake (original PC version) used the FPU in it's texture mapper (executing floating point instructions in parallel with fixed point instructions???)

Could be completely wrong, though...
hm · 28 Dec 2003, 19:54 UTC — (NOT) clearing the z-buffer
izeman wrote:
i've finished adding an md2 model viewer.
the engine now sacrifices quality (interlaced both horizontally and vertically). hence, i'm able to clear only 1/4 the z-buffer :P



Actually you can even do *without* clearing the z-buffer (it's a pretty old trick, and several of the gaming books mention it as well): For even frames, you store positive values in the z-buffer, for odd frames, you use negative values. You write z-values such that |z_1| > |z_2| means z_1 is closer. Initially, the z-buffer is 0.

Good luck with your engine.

- Martin
bluescrn wrote:
Are there any sites/books around that discuss perspective correct texturing in fixed point? Everything I've found has been rather PC-oriented, using the FPU...

The book mentioned by Daniel ["Tricks of the 3D Game Programming Gurus-Advanced 3D Graphics and Rasterization"] describes writing fixed point rasterizers. (even on a P4 where an FPU is present).

The book by Eberly mentined above is actually also pretty complete, but it is a bit difficult at first. So the two books together make up a good combo...

In the end it's just about writing a couple of rasterizers until you get fully comfortable with it.

- Martin
bluescrn":30ep5sp8]


If you use a combined approach where you interpolate linearly between reference points computed perspectively correct, then the latter computation could be done in parallel in the FPU while the linear computations being performed in the integer unit. But I really haven't looked at the old Quake code for that.

- Martin
hmwill. i implemented your suggestion. the frame rate jumped for 14 to 22 fps. thanks a lot!

i opened my book "tricks...", i couldnt believe why it didn't mention this trick. and found that it did suggest a similar thing using a bias.

now if i could still find other ways to increase the speed to 30+fps. maybe i could already display a map/world.

i also recommend "tricks of the 3d gurus".. i learned a lot
Another issue with working on small screens with fairly high poly count models is that you may end up not actually rasterizing much screen space ... so your polygon setup code can actually be more of a bottleneck than your rasterizer i.e. seting up 120 poly is more expensize than blitting 100 pixels.

But if you reduce your models too much they look shite when up close, LOD is not an ideal on low memory devices either.

This is an issue that I found when writing a commercial rasterizer a while ago, significant speed ups can be produced by extra careful handling of poly/strip/fan data and poly reduction prior to setup..especially if doing expensive lighting.

Jim.
Jim:
Probably one of the most understated comments I've seen in this group.

Nearly all of our big performance increases came in reducing triangle setup and associated overhead. We had plenty of memory available, so LOD was a huge help as well.

The real kicker to small triangles on a small screen is that, while small, they tend to be very important. One pixel on a 320x240 (or less) screen is a pretty big deal... thus you really need to make sure it is the right pixel and that you don't spin your wheels too long in getting it there.

Cheers,

rcp
rcp wrote:
Nearly all of our big performance increases came in reducing triangle setup and associated overhead. We had plenty of memory available, so LOD was a huge help as well.

Was this on Pocket PCs? Daniel (drgoldie) seems to have identified rasterization as the main bottleneck at least for his implementation (klimt)... At the same time, obviously any triangle that's not going to be set up will not go into the rasterizer either.

Intel had an article on 3d ["3D Graphics Optimizations for Intel® PCA Applications
Processors with Intel® XScale™ Technology"], and for their implementation they give the following numbers (whatever "typical workload for a game engine" may be):

Scanline 46%
TriSetup 17%
Culling 12%
Clipping 9%
Xform 6%

- Martin
Since Varium's rasterizers have been rewritten in ASM I find that converting polys to spans and span setup are the biggest rendering bottlnecks. Performance is dropping more than it should as poly count goes up in my case.

Dan East
hmwill":3hstjvyx]
[quote="rcp wrote:

Nearly all of our big performance increases came in reducing triangle setup and associated overhead. We had plenty of memory available, so LOD was a huge help as well.

Was this on Pocket PCs? Daniel (drgoldie) seems to have identified rasterization as the main bottleneck at least for his implementation (klimt)... At the same time, obviously any triangle that's not going to be set up will not go into the rasterizer either.

Intel had an article on 3d ["3D Graphics Optimizations for Intel® PCA Applications
Processors with Intel® XScale™ Technology"], and for their implementation they give the following numbers (whatever "typical workload for a game engine" may be):

Scanline 46%
TriSetup 17%
Culling 12%
Clipping 9%
Xform 6%

- Martin


Our game is a pool game. The walls are big polys so the numbers Intel claims are probably pretty correct. The table, stick and balls are very small polys and those numbers are inverted. If a triangle is reduced to two or three pixels, then TriSetup and everything above is going to have taken much more time. For example, if a triangle is 2 pixels, the grand total of the rasterization process might be a memory read and store.... two instructions.

None of this is anything new, software renderers have always had to worry about small triangles. Towards the end of Abrash's Black Book he talks about how he and Carmack came up with a special path for small triangles. I believe it was a subdivision method. At the time it was a big increase for them and they used it for character models at a distance. I do believe, however, that they later had the normal path so optimized that it really didn't matter which path was taken.

BTW, now that I look at Intel's number some more... those look pretty wacky. I assume by 'culling' they mean front or backface culling.... if so, there is no way that takes 17% of the time. You can pretty much get that for free in TriSetup. I almost wonder if those number are cumulative....

Cheers,

rcp
rcp wrote:
BTW, now that I look at Intel's number some more... those look pretty wacky. I assume by 'culling' they mean front or backface culling.... if so, there is no way that takes 17% of the time. You can pretty much get that for free in TriSetup. I almost wonder if those number are cumulative....

I don't think they are cummulative because the article presents them as a nice pie chart, and with everything taken together (I left out some misc. stuff) they add up to 100%. "Culling" can be much more than just front/backface culling, like sub-tree elimination while traversing a BSP, elimination of partial scene graphs by bounding volume intersections with the view cone, or techniques based on silhouettes (I think the article mentions that the engine implementation described supports terrains).

- Martin
Okay, i am not really into 3d coding and stuff, but this looks pretty promising. if you want to actually render a world, here are my suggestions (gathered while playing ratchet and clank on ps2 (boy, that game r0x0rs!)):

    -fog of war. limit the distance a player can see
    -load textures only at a certain distance. nicely colored models will work just fine for the rest.
    -actually use different models for different distances (that is fricken ingenious!). use like a few boxes that make up a house but if you get close, add ledges and more details!

This probably was general knowledge here and no-one gained anything from it, but i feel cool now posting in the GDD. :)[/list]
for low poly scenes (large triangles) the scanline rasterization will often be the main bottleneck. for scenes with many, small triangles the triangle setup can become the main bottleneck.

therefore i do affine texture mapping automatically in Klimt if a triangle is smaller than a predefined width and height (e.g. 16 pixels). this skips the large overhead of the gradient calculation and supports the fact that i do linear interpolation for texturing between up to 16 pixels anyhow...

btw: i noticed that mipmapping can help improving the cache usage (and as a result the overall performance), since it helps to make small steps (one texel in the ideal case) in the texture per pixel on the screen...

bye,
DANIEL
Dave Johnston · 03 Jan 2004, 19:27 UTC
shapeshifter-baka wrote:
-actually use different models for different distances (that is fricken ingenious!). use like a few boxes that make up a house but if you get close, add ledges and more details!


= LOD (Level Of Detail) - used in Quake 3, and probably other games before that. Republic: The Revolution has an extremely complex system to do this VERY quickly, and all in software, even if the scene has several million billion zillion quadrillion hundred polygons. Now that's ingenious!

[Just for reference]
Of course, LOD, judging by released games, is VERY tricky getting right. It's one of the biggest things that take me out of the experience of the game, walking up to something and watching as it morphs into what it's supposed to be.
rcp wrote:
BTW, now that I look at Intel's number some more... those look pretty wacky. I assume by 'culling' they mean front or backface culling....

BTW, here's one of the best references on culling and visibility for indoor environments, Seth Teller's thesis on visibility computations:
http://sunsite.berkeley.edu/Dienst/Repository/2.0/Body/ncstrl.ucb/CSD-92-708/pdf
Hope that's going to help you, Izeman...

Cheers,
Martin[/url]