Skip to main content
gamedev.net
🔒 Locked

Render Order

Started by brekehan Oct 6, 2008 at 6:11 PM 3 replies 1.2k views
Original Post
brekehan
brekehan
I read in one place that you must render back to front: a) opaque objects b) transparent objects c) volume objects I then read that you want to render everything that uses the same material in a batch to reduce switching states and effect variables. Well, you can't do both. What really is a proper render order? How is my rendering mechanism even going to know what is farther back? Back to front depends on the camera and the world orientation, doesn't it?Surely, I do now want to resort a huge list of objects every time the camera moves (every frame?) do you? Further more, there are situations where I couldn't even tell you what "is farthest back." Suppose you have one semi transparent object shaped like a donut and another semi transparent object traveling through its center. Which, is farther back? Which do you render first?
Halifax2
Halifax2
I understand that is probably a little overwhelming for you, so let me try and clear it up.

You want to render opaque objects in batches that have the same material. Then you want to render transparent objects back-to-front. (I don't really know what you mean by volume objects, so I won't comment on that.)

Yes, the back-to-front order depends on the camera, and world orientation. And yes, you will have to create a list of objects every frame.

And to answer your question about what is further back. You will probably want to use an AABB (axis-aligned bounding box), find the center, and use that as your basis in a sorting algorithm.

Supposing I got all your questions out of the way, let me explain a little further about this list. The top open-source engines Ogre and Irrlicht, both provide a BeginScene/BeginRender callback in which an object "registers." This happens at every beginning of a frame. By registering, the nodes add themselves to the list for rendering, and sorting from back-to-front, if the node is transparent.

So I will recommend that you take a look at either Ogre or Irrlicht to help you out a little with these topics. If you have anymore questions, then feel free to ask away. I hope my explanations cleared some things up for you, and if not, then just tell me.
Denzel Morris (@drdizzy) :: Software Engineer :: SkyTech Enterprises, Inc.
"When men are most sure and arrogant they are commonly most mistaken, giving views to passion without that proper deliberation which alone can secure them from the grossest absurdities." - David Hume
brekehan
brekehan
Ok thanks. That makes sense to me. I guess my poor cpu is going to have to take the hit.

I am not sure of the official word for it, but a book referred to "volume rendering", for things like fog, fire, nebulas and the like. I have no idea what it is yet, as I am still working on a basic framework. I do however have a desire to handle such things. Especially since one day years away I'd like to work on a space game with this thing.
Halifax2
Halifax2
Oh okay, those type of volume objects. You will want to do those the same way as transparent objects, with AABBs, etc.
Denzel Morris (@drdizzy) :: Software Engineer :: SkyTech Enterprises, Inc.
"When men are most sure and arrogant they are commonly most mistaken, giving views to passion without that proper deliberation which alone can secure them from the grossest absurdities." - David Hume
Adam_42
Adam_42
Sorting of opaque objects is just a performance optimization. It's not required for correct rendering. Also in some cases when rendering opaque objects you may find that a front to back sort order will help performance more than a sort by material. That's because objects that are close to the camera can occlude distant objects which may save on a significant quantity of pixel shader work.

Fire and other particle effects are often done with these render states:

- D3DRS_ZWRITEENABLE off (but testing on)
- Additive blending (source and dest blend of D3DBLEND_ONE). This means you want your graphics to have a black background.

If you do that then whatever order you render them in they will look the same. If you need alpha blending then you have to sort them for the result to look right.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.