• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Husbj

DX11 Instancing and transparency affording draw order?

5 posts in this topic

I haven't quite got around to try this yet but I was thinking it over and was thinking it may prove a problem.

 

My rendering framework so far draws any opaque meshes first, the Z-order isn't considered important what with the depth buffer. After that "cheap" transparent frames are drawn, also in no particular order but at least after the opaque ones and finally I sort the remaining transparent frames by their screen depth so that a transparent object behind another transparent object doesn't get clipped by being drawn after the first one.

 

However if I'm to use instancing for transparent frames that would benefit from the latter approach... this would be a problem wouldn't it (since they're all rendered in the same draw call and as such can't be sorted in with other meshes)? Is there any good solution to this or am I missing some point to instancing which means this really isn't an issue?

0

Share this post


Link to post
Share on other sites

My rendering framework so far draws any opaque meshes first, the Z-order isn't considered important what with the depth buffer.


You may want to profile the difference you get if you sort front-to-back with opaque objects. Yes, the Z-buffer stops rendering from being wrong, but it doesn't avoid the issue with overdraw. Overdraw is when you draw an object far away and then draw over it. This has a performance hit, especially with complex pixel shaders. With early-Z hardware optimizations, the extra runs of the pixel shader and extra writes into the depth/color buffers are avoided if you sort front-to-back. When it's a win will depend on what you're doing specifically.
 

After that "cheap" transparent frames are drawn, also in no particular order


I presume this means additive or screendoor transparency effects?
 

However if I'm to use instancing for transparent frames that would benefit from the latter approach... this would be a problem wouldn't it (since they're all rendered in the same draw call and as such can't be sorted in with other meshes)? Is there any good solution to this or am I missing some point to instancing which means this really isn't an issue?


The result of the draw operation is dependent on the order the primitives are specified. I don't know where it says it in the D3D documentation (it's clearly guaranteed in OpenGL's spec) but it basically has to be true in order to enable correct translucent rendering like your case. This applies to instances as well as individual primitives. Just sort the instance transform data back-to-front before rendering and you'll be fine.
0

Share this post


Link to post
Share on other sites


I presume this means additive or screendoor transparency effects?

Not really. As I've been lead to understand by various articles changing rasterizer states, blend states and shaders were to be considered more of a bottleneck (in general) than things like draw order. I suppose it makes sense that it can be the other way around if you have a sufficiently complex set of shaders going though; at the moment I don't though so such optimizations haven't really crossed my mind yet. So basically when I said "cheap" transparency I mean they are just drawn after the completely opaque meshes but prioritize state changes over depth when it comes to sorting. This will likely be good enough for things like floor covers. On the other hand if you have a window and can see a (semi-transparent) body of water through it it wouldn't do if the window was rendered first and alpha-blended with the backgrond before the water surface had been written there, so in that case it makes more sense to prioritize depth over state changes.

 


Just sort the instance transform data back-to-front before rendering and you'll be fine.

I thought about that but then if the instances are scattered about a great deal, wouldn't non-instanced (or other instances for that matter) meshes that are positioned in-between fail to end up where they should in a depth sort?

0

Share this post


Link to post
Share on other sites

You will have to split up the instance batches if necessary to ensure that the back-to-front order isn't violated, even between draw calls.

 

You can do this by sorting all transparent meshes back-to-front, then going through that list from the beginning and building instance batches where possible (when the mesh + other draw state stays same for multiple consecutive meshes).

0

Share this post


Link to post
Share on other sites

Not really. As I've been lead to understand by various articles changing rasterizer states, blend states and shaders were to be considered more of a bottleneck (in general) than things like draw order.


If you want correct output, you _must_ draw things in the necessary order, whether it's a bottleneck or not. Some forms of transparency don't need a specific ordering, though. Additive blending, for instance, gives the same results whether you blend A over B over C (where A and B are transparent and C is opaque) or B over A over C. Generally where efficiency matters and you don't want to sort, you _also_ ensure that you are using a blender operation.
 

I thought about that but then if the instances are scattered about a great deal, wouldn't non-instanced (or other instances for that matter) meshes that are positioned in-between fail to end up where they should in a depth sort?


Ah, I misunderstood, sorry. Yes, in this case, instancing will be an issue. Keep your instancing of translucent objects to small clusters to avoid the likelihood of other translucent objects getting in-between the instances. E.g., a single shattered window may be instanced, but you wouldn't want to instance all windows in the scene together unless they're your only translucent objects. This lets instancing help in the most important cases (lots of little pieces) but lets you use translucency elsewhere.

In general, keep your translucent object count fairly low. You might notice they're rare in games outside of particle systems (which often use only additive blending or transparent cutout). That's because they're slow, especially in complex scenes. In a game, having a smooth experience is more important than having a visually complex one. Even modern game engines focus more on lighting opaque surfaces than on adding lots of translucent objects.

A more advanced technique to allow order-independent translucency would be Depth Peeling, but before considering it read Nicol's answer at https://gamedev.stackexchange.com/questions/26239/how-to-properly-implement-alpha-blending-in-a-complex-3d-scene
0

Share this post


Link to post
Share on other sites


If you want correct output, you _must_ draw things in the necessary order, whether it's a bottleneck or not.

I'm aware of this, just to make it clear when I was talking about cheating with "cheap" transparent objects I didn't really mean translucent objects but rather close to 1-bit transparent things like floor covers or tree leaves. There may be some blending but it only occurs along the very egdes then and it therefore can be argued it isn't going to be noticible whether these edges blend properly with other transparent objects behind them. Those kinds of meshes would likely make up most of my transparent ones and actually semi transparent ones won't be very many.

 

So what I then understand is that you can (and should) split up instances in several batches when rendering?

I didn't know you could do that (as said I haven't actually gotten around to implement this yet, will see if I get the time during the weekend) but the approach outlined by AgentC seems to make sense then.

 

 

I'm sure I'll be back with more issues before long, but until then thanks for the descriptions and hints.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0