Re: [Algorithms] Fast renderstate sorting
Brought to you by:
vexxed72
From: Ruslan S. <ru...@fu...> - 2008-01-31 10:13:56
|
That's basically the approach we have taken as well. Our sorting is performed in two passes, though. First pass sorts alpha-blended objects, groups instanceable opaque objects together, and sorts them front-to back inside the batch. This all packs to the 64-bit key as well, in the folowing way (number of the bits is in the parentheses): Alpha-blended (1) Alpha-blended objects: Render priority(3) Distance back-to front (19) Layer ID(3) Shader ID(6) Opaque opjects: Shader ID(6) Shader Hash(15) Distance front-to-back(7) After the first pass objects are grouped into the batches ("the batch" here means the group of objects, which are to be instaced into single drawcall), and then there is a second sorting pass (this time only opaque batches are sorted). The key is composed in a similar way: Render Priority (3) Alpha-tested bit(1) Distance front-to back (8) Shader ID(6) Vertex Shader Permutation Cookie (7) Pixel Shader Permutation Cookie (7) So, front-to-back distance sorting is performed in coarse layers (around 10 meters in our case). Vertex/Pixel shader permutation cookie is basically the set of the shader permutation flags (we went the uber-shader way). The sorting is done with custom radix sort function, which in our case performs at least twice as well versus std::sort. Generally, this approach seems to work quite well. Ruslan Shestopalyuk ----- Original Message ----- From: <chr...@pl...> To: "Game Development Algorithms" <gda...@li...> Sent: Thursday, January 31, 2008 2:26 AM Subject: Re: [Algorithms] Fast renderstate sorting > Along the lines of keeping things simple but very flexible, > we just form a 64-bit key that contains bitfields (of varying > length) for layer ID (skybox, world, HUD, etc), transparency > flag, depth, material hash, etc. > > As we 'render' things we store pairs of the key and the pointer > to the object rendered into an array. We then perform what > amounts to a normal qsort on the array, after which we loop > over the array one extra time to actually submit the objects > for drawing. > > This way we can easily change the way we sort things without > reengineering any code; we just change how we assemble the > bits in the 64-bit key. > > We also get things like e.g. back-to-front sorting of translucent > objects and front-to-back sorting of opaque objects "for free" > with this approach (if we want), simply by inserting appropriate > values into the depth field of the key. > > Sorting a few thousand items in a cache-efficient array once > per frame really isn't that bad, and the flexibility it gives > is very nice. > > > Christer Ericson, Director of Tools and Technology > Sony Computer Entertainment, Santa Monica > http://realtimecollisiondetection.net/blog/ > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > GDAlgorithms-list mailing list > GDA...@li... > https://lists.sourceforge.net/lists/listinfo/gdalgorithms-list > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_name=gdalgorithms-list |