[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4787: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3922)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4789: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3922)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4790: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3922)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4791: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3922)
InsideQC Forums • View topic - Faster Dynamic Light Updates

Faster Dynamic Light Updates

Post tutorials on how to do certain tasks within game or engine code here.

Moderator: InsideQC Admins

Faster Dynamic Light Updates

Postby mh » Fri Jul 23, 2010 3:58 pm

User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Re: Faster Dynamic Light Updates

Postby Baker » Sun Jul 25, 2010 1:33 am

The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Postby metlslime » Sun Jul 25, 2010 2:19 am

metlslime
 
Posts: 316
Joined: Tue Feb 05, 2008 11:03 pm

Postby metlslime » Sun Jul 25, 2010 2:21 am

metlslime
 
Posts: 316
Joined: Tue Feb 05, 2008 11:03 pm

Postby mh » Sun Jul 25, 2010 11:11 am

To be honest, with the amount of bandwidth on todays hardware, uploading changes per surface can still give reasonable performance, and the format differences only really kick in when you encounter a troublesome driver like I had. (Aside: developing on bad hardware can sometimes be great for highlighting issues like this that might pass you by otherwise.)

The bigger difficulties come from use of GL_RGB format and from multiple texture changes.

GL_RGB is bad because no such format actually exists in hardware. Sending data down in GL_RGB format means that your driver has to make a copy of it, expand it to 4-component and most likely then swizzle it to GL_BGRA. You may as well just use GL_BGRA in your code instead and bypass those steps.

There's great info about this on OpenGL.org: http://www.opengl.org/wiki/Common_Mistakes

Multiple texture changes are not that bad in themselves as texture changes are fast these days. Where trouble kicks in is that your driver is unable to optimize your vertexes into bigger batches for you, so you end up doing lots and lots of itty bitty draw calls instead of very few big ones. Interestingly, with OpenGL this seems to be the case irrespective of whether you use glBegin/glEnd or vertex arrays so the driver must be doing some behind-the-scenes optimization of it's own.

Sorting surfaces by texture, then by lightmap within that is the way to go. Building lightmaps in texture order also helps, and increasing the lightmap size to 512x512 (so you get more surfs per lightmap, and a better chance that all surfs with the same texture also have the same lightmap) improves things again.

Do a single bulk upload of all modified lightmaps after the sorting pass but before the drawing pass, and draw something else or do some other CPU work before you draw the lightmapped surfaces so that the glTexSubImage2D calls have time to finish updating the textures before you need to use them and you're in business.

What really caught me by surprise was GL_UNSIGNED_BYTE versus GL_UNSIGNED_INT_8_8_8_8_REV. I'm guessing that on my bad driver GL_UNSIGNED_INT_8_8_8_8_REV is giving it a hint that "this data is already in the format you like best so there's no need to pull it back to system memory (or whatever it is you're doing) and have your evil way with it there". It was faster by a factor of 30 on this driver, and marginally edges out GL_UNSIGNED_BYTE on other, better drivers.

On the other hand GL_BGRA was just twice as fast as GL_RGBA, smaller but still significant.

Of course, the formats that were fastest on my driver and my platform aren't necessarily going to be the fastest elsewhere, which is why it's important to check a few of them.

The end result is able to handle scenes where wpoly counts go into the thousands, and where almost every surface has an animating lightmap, without dropping below 72 FPS. Which is nice. :D
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Postby Baker » Sun Jul 25, 2010 11:22 am

The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Postby Spike » Sun Jul 25, 2010 12:35 pm

.
Spike
 
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby mh » Sun Jul 25, 2010 1:26 pm

User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Postby metlslime » Sun Jul 25, 2010 10:12 pm

metlslime
 
Posts: 316
Joined: Tue Feb 05, 2008 11:03 pm

Postby metlslime » Sun Jul 25, 2010 10:16 pm

metlslime
 
Posts: 316
Joined: Tue Feb 05, 2008 11:03 pm

Postby Spike » Sun Jul 25, 2010 10:51 pm

.
Spike
 
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby mh » Sun Jul 25, 2010 11:36 pm

You don't even need to use a strip, just great big soups of GL_TRIANGLES is enough (and will likely get you bigger batch sizes and with less fiddly stuff than using strips. No need for degenerate triangles - yayyyy!)

Triangle strip order is fine, best case is that each triangle will reuse 2 verts from the previous one, and you'll get better vertex cache efficiency. You can model that with GL_TRIANGLES and indexes, like Spike says. For the likes of Quake you probably won't really notice it though (I got maybe 1 FPS from putting on MDLs), and the setup and ordering cost might be prohibitive.

Saving vertex bandwidth in Quake doesn't have much return on investment most of the time. You can just convert your GL_POLYGONs (or fans or strips) to GL_TRIANGLES and indexes at run time, add them to a list, and render that list when it fills up or when state changes. You'll also get a single rendering path for everything on-screen this way, the code will be simpler, and easier to maintain, debug and enhance.
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am


Return to Programming Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests