modern rendering engines: some questions

Started by
2 comments, last by dpadam450 13 years, 4 months ago
Hi all, recently I started learning OpenGL and graphics programming in general. So while reading some books and articles I gained some perspective into what happens in a modern rendering engine, but I'm not sure if all my assumptions are correct.

1. We should sort the objects we want to render by material (to minimize the number of times we change a material, put them in one giant array and send it to the GPU).

2. We should render vertices back to front and the sorting is done in application stage. What do modern rendering engines use for that purpose? Is it still BSP trees? Or can we just use the z prepass? Or both?

3. Given 1. and 2. are true, it can be problematic to fullfill both of them (2 different sorting orders)

Hope someone can clarify those for me.
Advertisement
Back to front rendering is only necessary for translucent materials.
For all solid materials, you sort on material and render all visible objects in batches.

Writing all sorted vertices in one big array on the CPU and sending this to the GPU is usually not the best way to go. Usually, the geometry of static and almost static objects are stored on the GPU in vertex and index buffers. You sort all visible objects according to material (or depth for translucent objects) and render the objects in this order, one after the other.
Thanks, things start to make sense now.
Sorting back to front is ONLY useful for transparency, and even then you can't really do it per-triangle. You store a full 20K vertices model on the graphics card and you tell it to draw. If it gets rotated, the triangles will still be drawn in the same order. So you should draw those back to front per-object.

The best thing you can do is draw front to back for non-transparent objects. Image you have objects A,B,C (a is closest to you and c is furthest). If you draw back to front, you draw C (which takes up 200 pixels on your screen), you draw B, which over-writes those 200 pixels, and then A is really close and overwrites all the pixels drawn by b,c. You drew 200 pixels on the screen 3 times (effectively drawing 600 pixels). You want to draw A first, and then due to depth testing B,C will never actually draw any pixels. This is really useful when doing shaders that do tons of per-pixel operations.

Any calls to the gpu slow your program down. If you want to use a texture, it swaps the old one out and puts the new one in to be used. The order should be:

Draw by Model
Draw by Texture

You won't need to worry much about any of this though. Just start hacking away and getting stuff to work. Optimization is only needed when you come to need it which will most likely be a while.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

This topic is closed to new replies.

Advertisement