Sign in to follow this  
carpat

Speed of setting shader constants and textures, and sampling textures

Recommended Posts

I have a decent system set up for multipass rendering that minimizes shader changes, but I don't yet have anything for generating shader permutations. I've been thinking about how to do it and the way I'd like to solve the problem is by avoiding in entirely.

For a basic phong shader, instead of generating a version with a specular power from a texture and one with a specular power set as a constant, I could just use the texture version and have a 1x1 pixel texture with the power. Same thing goes for getting a normal from a texture vs not using normals (not using normals would be a 1x1 texture with 50% red, 50% green, 100% blue), light maps, etc.

So my question is, is setting shader constants significantly faster than setting and then sampling a texture? Would using a few ubershaders be significantly slower than using many specialized generated shaders?

Share this post


Link to post
Share on other sites
Swapping textures is very expensive. I covered this yesterday in an article on my site for my new next-generation game engine.
[url="http://lspiroengine.com/?p=96"]http://lspiroengine.com/?p=96[/url]
I did not mention that sampling from textures is also a heavy function.

Swapping shaders also incurs a huge hit to the performance.


Swapping textures and sampling from them is always going to be slower than setting constants. #1: Swapping textures is always slower than setting a constant. #2: Sampling textures is always slower than reading a constant. There is no win here, not to mention the heavy resources needed to make a new texture for every power value.
Use one shader for texture speculars and one for constant speculars.

In my experience, uber-shaders have always been much slower than having several specialized shaders, but again, as my article says, you need to know when to trade off dynamic branching for shader permutations.
When it comes to phong lighting, your pixel shader will be fairly heavy and called very very frequently. Keeping light shaders mitigates the cost of swapping shaders, so it is best to have more permutations, each lighter in operation count.


L. Spiro

Share this post


Link to post
Share on other sites
Ah well I was hoping I could get away with it...

If only artists weren't so demanding with what they could customize :D I guess I'll get started on a permutation management system. Awesome blog by the way, bookmarked it and will be reading after I get some sleep :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this