Jump to content
  • Advertisement
Sign in to follow this  
viertara

OpenGL modern rendering engines: some questions

This topic is 2780 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!