Jump to content
  • Advertisement
Sign in to follow this  

Material sorting & shader question

This topic is 4785 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, I know that sorting meshes on material is not a bad idea because it prevents a 'material switch' between every object that needs to be rendered. But sorting is not always that handy. For example, if there's lots of culling, the list of polygons that needs to be rendered can change every frame and so the sorting needs to be adjusted as well right? I wonder how a FPS game like Doom3 or Hl2 handles this. As far as I know, it uses something like BSP to cull. What happens to the visible polygons/walls or whatever groups? Are they sent to a 'doRender-list' or something? And is this list sorted on material each frame as well or not at all? The amount of 'the-same' materials on a screem might be pretty low so maybe its not worth to sort? I'm trying to find out the efficiency of material sorting. I made my engine in such a way that it sorts everything. It might be very good for large amounts like grass-planes but its also a pain in the *ss for culling and other stuff. How important is to sort on material? Another problem are shaders. For example, there are 10 objects with exactly the same shader and the same parameters (10 palmtrees with the same texture(s) for example). So, the engine does this: 1- pass the shader parameters 2- enable the shader 3- render all objects with this shader The modelviewmatrix is passed only 1 time at step1 so all objects have the same position while I have translated/scaled or rotated them. How to fix this? Can it be fixed by adjusting the modelViewProjectionMatrix parameter each time before render an object? Greetings, Rick

Share this post

Link to post
Share on other sites

I asked something about scenegraphes / renderer a week ago, and amongst the replies, someone suggested this to me :

On loading, pre-sort all your graphic entities by materials, shader, or whatever. So you can re-use this in runtime to know in which order you have to render your objects.

This is valid only for objects whose materials, shader, etc. don't change during runtime. So you could have a part of the renderqueue with "static" objects (and for those, you already computed the order, so you don't have to do it again) and "dynamic" objects (their render states can change during runtime, so you need to sort them) This way, you only have a small amount of object to sort by render states.
And I think you could even cache those results as long as the render states didn't change. Because between 2 frames, even with a lot of occlusion, most of the objects will still be visible.

For your shader, I would do this like that :

1- Set the parameters which are common to every entity using this shader
2- Enable the shader
3- for each entity
3a- set the shader parameter for this entity (for example, transformation)
3b- render the entity
4- Disable the shader

In DirectX, the 3a step is done via the ID3DXEffect::CommitChanges() method

I hope I helped a little ^^

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!