Jump to content
  • Advertisement
Sign in to follow this  
JoystickX

Frequent shader change

This topic is 4681 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

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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!