|
|
| Should a 2D tile-based map be rendered in 3D? |
|
TeamTerradactyl
Member #7,733
September 2006
|
I was told by a fellow classmate (the few that aren't terrified to talk to a "girl programmer", that is) that the few tile-based games I've been working on could be optimized if I were to rethink the entire tilemap idea. He said that I'm doing a lot of my own routines (from scratch) that redraw several layers of tiles, and that I must have not done something right because there's a lot of flickering, etc. when the map scrolls to follow the player. He suggested that I use some 3D implementation (like OpenGL) to do basically the same layout (2D tiles, etc.) but have OpenGL be in charge of all the redraws, scrolling, etc. Since others have already spent countless hours optimizing the redraw routines for 3D to be "incredibly fast", that would be the best thing for me to do. Then, simply tell the camera to look "straight down" onto the map to get the 2D feel. Has anyone else here done this, or is this just a lot of hot air from someone who doesn't know what he's talking about?
|
|
Hard Rock
Member #1,547
September 2001
|
You can do it that way if you want. The benefit of doing it in 3D is you get lighting, blending effects etc which make it look prettier in general. Plus all textures are filtered so they look nicely stretched and it will run nice on all computers with a 3D graphics cards since it won't be that intensive. The down side is it wont run on a computer lacking a 3D graphics card... so realistically there aren't many Now keep in mind there is no reason Allegro shouldn't be able to handle a few layers. Even on a 400mhz Celeron I was able to get the engine to pump out a ridiculous frame rate (several hundred fps) with translucency, several layers etc etc. This was in 8 bit colour. At 16 bits and 640x480 then some more careful optimization would be needed on the Celeron, but on other computers there was no issue. _________________________________________________ |
|
gnolam
Member #2,030
March 2002
|
TeamTerradactyl said: He said that I'm doing a lot of my own routines (from scratch) that redraw several layers of tiles, and that I must have not done something right because there's a lot of flickering, etc. when the map scrolls to follow the player. Flickering indeed means something's wrong. What kind of buffering do you use? TeamTerradactyl said: He suggested that I use some 3D implementation (like OpenGL) to do basically the same layout (2D tiles, etc.) but have OpenGL be in charge of all the redraws, scrolling, etc. Since others have already spent countless hours optimizing the redraw routines for 3D to be "incredibly fast", that would be the best thing for me to do.Then, simply tell the camera to look "straight down" onto the map to get the 2D feel. Has anyone else here done this, or is this just a lot of hot air from someone who doesn't know what he's talking about?
Bit of both. The reason it's going to be a lot faster in OpenGL isn't because someone's "spent countless hours optimizing the redraw routines for 3D" - it's because you're using hardware acceleration. And... the concept of "having OpenGL be in charge of scrolling" is just... wrong. Yes, I suppose you could brute-force draw the entire map and just translate it, but why oh God why? -- |
|
GrantG
Member #8,173
December 2006
|
I have done a tile map like that a few times before with DirectX. The D3D sprites made it very simple and the speed difference was definitely noticeable. Like gnolam said you definitely don't want to draw all the tiles then just scroll them, I was only drawing the tiles that were in the view of the camera.
|
|
Paul whoknows
Member #5,081
September 2004
|
Quote: He said that I'm doing a lot of my own routines (from scratch) that redraw several layers of tiles, and that I must have not done something right because there's a lot of flickering, etc. when the map scrolls to follow the player.
Probably what you need to smooth your scroll is a high resolution timer. ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
|
ImLeftFooted
Member #3,935
October 2003
|
Quote: is this just a lot of hot air from someone who doesn't know what he's talking about? Its mostly hot air. Theres a small hint of a good idea in there (using OpenGL) but his reasoning for it makes absolutely no sense. Just ignore the guy. Besides, OpenGL isn't always the answer anyways. Use the right tool for the right jobTM |
|
James Stanley
Member #7,275
May 2006
|
You mean the right tool? |
|
Thomas Harte
Member #33
April 2000
|
Quote: Besides, OpenGL isn't always the answer anyways. Use the right tool for the right job For example, if you're doing graphics work then use the graphics processing unit. Your laptop users and users of OSs with modern compositing engines (i.e. Vista, OS X, etc) will thank you forever. [My site] [Tetrominoes] |
|
TeamTerradactyl
Member #7,733
September 2006
|
Okay, so due to the hardware acceleration and all the other fancy stuff built into OpenGL, it would be a lot more computer-friendly to take the simple side-scrolling (or top-down) tile-based game and reduce flickering, movement jumpiness, etc.?
|
|
HoHo
Member #4,534
April 2004
|
yes. __________ |
|
gnolam
Member #2,030
March 2002
|
There shouldn't be any flickering, no matter what method is used. -- |
|
Andrei Ellman
Member #3,434
April 2003
|
Every time I hear about someone using 3D acceleration for a strictly 2D task, part of my childhood dies. -- |
|
HoHo
Member #4,534
April 2004
|
Well, OpenLayer seems to be quite nice for doing 2D stuff. You can also get a lot more eyecandy with it compared to using CPU-only __________ |
|
Alysher
Member #8,406
March 2007
|
Hard Rock said: The down side is it wont run on a computer lacking a 3D graphics card... so realistically there aren't many but if your main coding computer lacks a 3d graphix card then your in trouble;D;D I didn't lose my marbles, I never had any to begin with!!! |
|
Carrus85
Member #2,633
August 2002
|
Quote: but if your main coding computer lacks a 3d graphix card then your in trouble;D;D I dunno, one of those nice (and yet annoying, in some cases) things with openGL is that, by design, any and all features can be implemented in hardware or software transparently (AFAIK). If only some of the API can be implemented on the hardware, so be it; the software end can take care of the gap. Granted, this isn't great for performance, but just because you don't have a 3d graphics card doesn't mean you will get zero hardware acceleration for ANY of the opengl calls. (You likely won't get any acceleration, but if you do have an older 2d-acceleration-only card, in theory, it is possible for some of the routines used by OpenGL are mapped to a hardware implementation). Besides, the software implementations of the OpenGL spec are not THAT slow (they are no where near hardware speed, but if you are careful in what features you use, you should get playable performance from it with a decent CPU. Of course, if you have a decent CPU, you probably have 3d acceleration anyway, so it is a moot point.)
|
|
Thomas Harte
Member #33
April 2000
|
Quote: Every time I hear about someone using 3D acceleration for a strictly 2D task, part of my childhood dies. Oh, it's not like that. The Atari 2600/etc all have specific graphics hardware, and if you went something like Atari 2600 -> C64 -> Amiga -> PlayStation -> now then you'd never have had a platform that just used a CPU to write to a dumb framebuffer. It just so happens that the algorithms used by todays graphics hardware allow for 3d visuals as well as 2d visuals. [My site] [Tetrominoes] |
|
Hard Rock
Member #1,547
September 2001
|
Quote:
but if you do have an older 2d-acceleration-only card, in theory, it is possible for In theory. Have you ever tried using the software implementation that comes with windows (I know there are libraries out there, but unless you distribute them with you game they don't count)? In the games software renderer i think I hit like 20-30fps. With the OpenGL renderer I hit 1 or 2 every few seconds. I'm not actually joking either. This is Counterstrike on a 400mhz celeron. Before you comment keep in mind: _________________________________________________ |
|
OICW
Member #4,069
November 2003
|
Quote: I could run Max Payne 2 up until the part where they had stairs. It took me a good 5 minutes to get to the top
You mean you were programming the gameplay Besides I don't see anything wrong on having the camera fixed at 90° to a surface, having orthographic projection and making a 2d game. It's what you use OpenGL for too. I know a lot of games done this way. Unless you don't have gfx accelerator, in that case it sucks. Quote: But if your main coding computer lacks a 3d graphix card then your in trouble That's why I had to buy new laptop, because my old one had 8MB ATI card which didn't supported OpenGL and I think HW acceleration at all. [My website][CppReference][Pixelate][Allegators worldwide][Who's online] |
|
Andrei Ellman
Member #3,434
April 2003
|
Thomas Harte said:
[quote I]
Oh, it's not like that. The Atari 2600/etc all have specific graphics hardware, and if you went something like Atari 2600 -> C64 -> Amiga -> PlayStation -> now then you'd never have had a platform that just used a CPU to write to a dumb framebuffer. It just so happens that the algorithms used by todays graphics hardware allow for 3d visuals as well as 2d visuals. AE. -- |
|
Tobias Dammers
Member #2,604
August 2002
|
3D acceleration still is mostly really 2D. The graphics card doesn't have a 3-dimensional frame buffer, but rather a 2D frame buffer that holds 5 or 6 dimensional values (R, G, B, A, Z, Stencil). This is not the same. For the GPU, the triangles (after all transforms) are 2D, with an additional vertex parameter that controls texture mapping. --- |
|
Andrei Ellman
Member #3,434
April 2003
|
Tobias Dammers said: And if using the highly optimized rendering pipeline that is already in place to render 2D graphics; what's the problem? As long as it produces the expected results and works fast and reliably, by all means use it. Would a highly optimised pipeline be able to take special cases into account in order to save GPU-cycles? Even if we turn off things like lighting, multi-texturing, mip-mapping, bi/tri-linear filtering, perspective-correct texture-mapping, Z and S buffers, we'd end up with the minimum requirements for drawing a diffuse texture-mapped polygon. Even that is a bit overkill if we want to do a simple 2D sprite-game. A point-sampling function for texture-mapping a 3D polygon also has to take the depth into account. Also, for each scanline, the direction of texture-sampling is different (whereas for a rotated 2D sprite, it's the same). And if we don't want to use sprite-rotation, the point-sampling functions only need to work in one dimension, and then if we're not even zooming, the point-sampling function is just a one-to-one mapping between texels and pixels. Unless the hardware takes into account special cases for things such as the polygon-plane being perpendicular to the camera/screen, or the texture-space as defined by the texture-coordinates mapping to screen-space coordinates by purely using a displacement (that is, one texel maps to one pixel and no rotation is required), the hardware will be doing a lot of extra work unnescescarily. Even if the hardware is optimised enough to be able to do all the lighting, transformation and perspective-correction etc. within the time it takes to fetch the texture from texture-ram, it will mean that using the entire pipeline will use up more energy than is needed and therefore produce more heat. But by all means, if this is the fastest way of drawing a 2D sprite, then go for it. Game-players want the fastest possible graphics, and don't care about heat-generation. I just think it's a pity that the hardware-designers didn't take 2D sprites as a special case into account (if they haven't). AE. -- |
|
TeamTerradactyl
Member #7,733
September 2006
|
Andrei Ellman said: I just think it's a pity that the hardware-designers didn't take 2D sprites as a special case into account (if they haven't). I think they probably HAVE taken 2D sprites into account. For example, most 3D games have some sort of on-screen menu, or names of other players walking around, or something else that is drawn onto the screen that should not be rotated by any 3D calculations. Since 3D objects always have textures overlaying their polygons, I'm sure they have all SORTS of 2D functions (software and hardware both) that have been optimized and loops unrolled. I agree, though, that for a top-down, or even side-scroller, you probably won't be doing very much sprite rotation, zooming, change of depth, or all those other things you mentioned. And since they're not being used, there's no reason for the GPU to have to heat up calculating anything unnecessary. I'm just thinking that someone else who has worked on OpenGL (or DirectX or whatever) and has already done all the math. I just come along and use what they've already optimized. Like Allegro: I wrote my game for Windows, with 2GB RAM, 256MB graphics card, etc. However, I used the Allegro libraries. Now, anyone who has Allegro compiled for their machine can play the game. I didn't have to do any of the math or #ifdef __MACINTOSH__'s. So if I use a 3D library to render the 2D game, I take advantage of all the hardware acceleration and code optimizations that I have never had to think about: I simply tell it, "You! Shift all the tiles over by 8 pixels!" and it does it however it feels happiest. TT
|
|
Andrei Ellman
Member #3,434
April 2003
|
TeamTerradactyl said: I think they probably HAVE taken 2D sprites into account. For example, most 3D games have some sort of on-screen menu, or names of other players walking around, or something else that is drawn onto the screen that should not be rotated by any 3D calculations. I would have thought so too, but I've seen at least one implementation of a 2D font-renderer that turns the texture into two triangles and renders them as 3D polygons. Maybe this was just a one-off, but who knows... TeamTerradactyl said: Since 3D objects always have textures overlaying their polygons, I'm sure they have all SORTS of 2D functions (software and hardware both) that have been optimized and loops unrolled. Actually, texturing a 3D polygon is a much more involved process than drawing a 2D bitmap. Even a single-textured (diffuse-mapped) polygon that is textured without perspective correction can take more effort to render than a 2D scaled and rotated object. Once perspective-correction is taken into account, the processing-time becomes even greater. TeamTerradactyl said: So if I use a 3D library to render the 2D game, I take advantage of all the hardware acceleration and code optimizations that I have never had to think about: I simply tell it, "You! Shift all the tiles over by 8 pixels!" and it does it however it feels happiest. I agree. I was just commenting from the perspective of a low-level programmer. Anyone who uses a rendering engine does not need to worry about what goes on inside the black box and just have faith that it does it's thing in the best possible way. However, I've been around a few engines in my time, and my faith has become a bit wobbly. AE. -- |
|
ImLeftFooted
Member #3,935
October 2003
|
You know I think for a simple side-scroller OpenGL is a bad idea. You're hurting your user-base. It wont work on half the computers you wish it did. This is the sort of thing Allegro was made for. Remember to Use the right tool for the right jobTM |
|
Goalie Ca
Member #2,579
July 2002
|
With using opengl you get a lot of effects and capabilities for free. One that hasn't been mentioned is resolution independance and camera capabilities. I'd say go ahead and learn opengl because I feel its worth knowing. Sometimes its also a good idea to take a look at how other people implement things. Opengl is pretty well thought out and designed. There are probably ideas you can take from it to improve your own design. ------------- |
|
|
|