Jump to content


Best way to sort mesh rendering


4 replies to this topic

#1 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 17 October 2008 - 04:53 PM

I've basicly finished the dynamic lighting portion of my engine and am now attempting to build a good, stable geometry renderer that isn't a clustered abomination.

So one question I'm asking is the best way to sort the rendering. Rendering front to back is no longer an issue because of the magical pre-z pass and deferred lighting, so that priority is last. I am deciding between priority sorting by complete mesh or by material.

My 2 basic options in mind are:
- make a list of everything in the scene that uses the same material. This includes all the different parts of the models (such as the characters clothes is the same material as the bed, so they are rendered at the same time) and does not try to render the entire mesh at once, that would be second priority.

for type of material (variable set)

     for each mesh

          for each mesh attribute

               render the attributes that match the material variables

     }

}

I know there is a substancial speed penalty for constantly switching shader variables so this option is attractive.

- render each mesh as a whole. This is how it is done in the DX SDK samples, but I have a feeling it is for clarity and not efficiency.

for each mesh

     for each attribute

         change shader material variables 

     }

}


I know there is also a speed penalty for constantly switching between drawing different types of meshes. I have a feeling the first option is faster but I'm just making sure.

Thanks in advance.
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5305 posts
  • LocationBellevue, WA

Posted 17 October 2008 - 06:00 PM

I would also guess the first option is faster, but as always you should profile it to be sure. ;)
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 17 October 2008 - 09:01 PM

Reedbeta said:

I would also guess the first option is faster, but as always you should profile it to be sure. ;)
yes, I definitley will have to because i had a sudden realization. The first technique might force me to switch the world matricies more, potentially causing a big slowdown. :-( always so complicated.
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 5305 posts
  • LocationBellevue, WA

Posted 17 October 2008 - 09:39 PM

Switching matrices around is actually very fast. It's just loading some numbers into a vertex program constant register. Switching around shaders/textures is potentially a lot more expensive, because it might have to be loaded from system memory, the fragment shader constants might have to be patched etc.
reedbeta.com - developer blog, OpenGL demos, and other projects

#5 starstutter

    Senior Member

  • Members
  • PipPipPipPip
  • 1039 posts

Posted 18 October 2008 - 03:22 AM

Reedbeta said:

Switching matrices around is actually very fast. It's just loading some numbers into a vertex program constant register. Switching around shaders/textures is potentially a lot more expensive, because it might have to be loaded from system memory, the fragment shader constants might have to be patched etc.
hmm, alright, sounds good :) Thanks for the help
(\__/)
(='.'=)
This is Bunny. Copy and paste bunny into
(")_(") your signature to help him gain world domination.
bunny also wants to fight spam: Click Here Bots!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users