shaders and speed

I implemented the “Blinn-Phong model” lighting model from the lighthouse:

verbatim (ie, I didn’t add any code to it)*, which according to them this is the same algorithm used by the fixed pipeline. And it does look identical.

However, when I turn the shader off:
it runs 8-10% faster (frame rate goes from mid 1300’s to mid 1400’s).

I haven’t really seen anyone claiming that shaders provide higher performance, just greater tweaking power.

I suppose this loss of speed is card/driver specific. Is it usually that much?

*I did optimize it slightly by removing “normalize” from the normal computation, since my normals are already unit length.

yeah Mr.End, take the conditional out for a start. It makes a hell of a lot of difference on older cards, and gives a little boost even on modern cards. Rule of thumb, only use conditionals if the operation inside the condition is expensive. You’re using it to avoid a few mults. Only use it to avoid texture samples and complicated maths. Unless it’s on older cards, in which case only use it if you literally can’t find any way of avoiding it, as it’s cheaper to sample from textures and do lots of square roots/sin/cos than it is to have a conditional.

Wow, that’s interesting. Not that I study assembly type stuff, but hmmm. I guess this reflects something about the nature of a GPU.

Anyway, it is a slightly silly condition. Can’t say removing made any difference tho.

next idea, take out the pow function and replace with a uniform lookup. Well, first take out the pow function and replace it with nothing and see if you get a boost.
then try doing the maths with half precision floats.
from previous posts I’ve gathered you’re running on nvidia hardware, so you can bet your boots that their fixed function shader (because they are definitely using just a plain old shader) is using half floats.

(frame rate goes from mid 1300’s to mid 1400’s)

Framerate, especially when it is that high, is a lousy performance metric. Use direct timing tests instead.

true, but it’s still indicating his shader is less optimal than nvidia’s fixed function shader.