Game Development Community

Custom Shader performance...

by Jeremiah Fulbright · in Torque Game Engine Advanced · 12/19/2007 (6:45 pm) · 5 replies

I was wanting to know if there is any performance to be gained from using a custom shader versus procedural generated ones?

I know custom obviously allows making changes easier and such, but I'm talking instead of having 50 hlsl files for one level/scene, versus having one "shader" that is utilized across the board that does everything needed.

#1
12/19/2007 (11:29 pm)
1 shader for 50 tasks -> bad idea, bad performance, lot of extra calculation in most cases that are not needed at all.
Each OP counts in a shader so if you just overbloat it by a single super shader instead of different specialized ones, its a seriously bad idea.
#2
12/20/2007 (9:16 am)
It actually depends, switching shaders is one (or the) most expensive state changes you can do. So the mega shader could allow you to avoid that cost.

That all being said, it's better to track down performance issues systematically. There's a great guide to doing so in the NVPerfHud documentation.
#3
12/20/2007 (12:09 pm)
I know that they are costly. But I definitely think that a 5 shaders with 50 ops each are more performant on pre DX10 cards than 1 shader with 250 ops especially if the textures get larger and we are talking of enough object and one wants to support cards < 600 / 700 series from ATI and NVIDIA with their serious cap in shader unit count.
#4
12/20/2007 (5:46 pm)
I wasn't talking about one mega-shader for everything, but more along the lines of specific shaders... (DiffuseOnly, DiffuseNormal, DiffuseNormalSpec, DiffuseGlow, etc)... instead of relying on auto-generated ones which right now we're at about 48+ shaders per level/mission which doesn't make a whole lot of sense, but since its being auto-generated, its no surprise
#5
12/21/2007 (12:05 am)
Its one per material you generate. if you have a lot of identical materials just with different texture names, making a costume one out of one of those might be a good idea as it reduces the amount of switches.

but if they differ in the effects or number of textures it wouldn't help that much.