Frequent shader change

Started by
9 comments, last by ph33r 18 years, 7 months ago
In our game we want to use shaders. We want to use them frequently, few ten-times, maybe few hundred-times shader change per frame. Is that approach good, or it will be incredible slow? Thanks in advance
Advertisement
Hi there JoystickX,
How are you doing?

The Problem
Changing shaders alot of times per frame

The Solution
Doing alot of changes per frame is always bad.. What I normally do might help you in deciding how you will do yours.
I have a shader manager that batches all the entities that needs to be drawn with the same shader. This will save state changes.
With frequent do you mean like changing them alot or just using them to render entities... if so, my approach will work out for you.

Some other people might have some better solutions and I hope you come right.

Take care bud,
Good luck
I don't do a lot of shading yet, but it seems like you could do the following approach:

Depending on the complexity of your shaders, you could probably throw 4 or 5 together and check flags in the constants register. Each time you want to use 1 of the 5 shaders, you'd just set a constant to 0 through 4. You'd still have to batch those up, because obviously the larger the shader gets, the longer it takes to load. There are also size limitations. 100's of shaders seems unusual per frame. What exactly are you doing? Maybe there are other ways to do it?
Chris ByersMicrosoft DirectX MVP - 2005
I have found that the easiest way to batch states is to organize all of them into a tree-like structure, similar to the one below:
                     Shader1                            Shader2               |--------|--------|                 |--------|--------|           TextureSet1      TextureSet2       TextureSet3        TextureSet4       |--------|--------|      ...               ...               ...   ConstantSet1      ConstantSet2       |                 |     Entity1          Entity5     Entity2          Entity6     Entity3     Entity4

This minimizes state changes, like Armadon and Supernat mentioned. It's also really easy to implement and transverse.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
You know, Dustin, I've seen this diagram of yours a billion times. Do you keep it in the clipboard or what? [grin]

Quote:Original post by Coder
You know, Dustin, I've seen this diagram of yours a billion times. Do you keep it in the clipboard or what? [grin]

[lol] What can I say? It's a handy diagram!

p.s. I store it in my bookmarks
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
To give you a benchmark number, AOE3 has

120 Shader changes per frame and 360 texture changes per frame

380,000 tris / frame
3,900 drawprim calls per frame.

One way I thought would be good is to create 2 Draw Lists while culling one with alpha and one without. Then I sort the opaque objects by shader and sort the alpha objects by distance.

Anyone else know of any better ways?
Quote:Original post by ph33r
To give you a benchmark number, AOE3 has

120 Shader changes per frame and 360 texture changes per frame

380,000 tris / frame
3,900 drawprim calls per frame.

That is quite unusual. Both ATI and Nvidia recommend a *maximum* of 1,000 DIP calls per frame. Also, at the rate you are suggesting, only 97 triangles are drawn per batch.

Do you have a source for this info or something?
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
Quote:Original post by ph33r
To give you a benchmark number, AOE3 has

120 Shader changes per frame and 360 texture changes per frame

380,000 tris / frame
3,900 drawprim calls per frame.


From where do you know this? Can you give a link?

This topic is closed to new replies.

Advertisement