View Full Version : Vertex/fragment glsl shader performance question

05-22-2004, 11:31 AM

implementing a simple phong lighting shader, i've noticed a strange performance issue:
in my first shot, i've implemented the refection & view vector computation in the fragment shader getting the interpolated value of the light direction and view direction from vertex shader (using varying variable).
Then, thinking that deferring the maximum of the computation to vertex shader would have increased the perf, i moved the reflection part to the vertex shader and added a varying variable to interpolate the reflected vector from the vertex shader to the fragment one.
I then noticed a serious performance hit (-20%).

Does someone have some kind of explanation for this performance hit?

The only explainations i can expect is that adding varying variable is far from "free" or maybe i've reach the vertex shader limitation ...

thx for any help

05-24-2004, 02:50 AM
I have do some tests about varying on FX5900 and it support 8 vec4 varying's. Performaces drops 4-6x times when I use 8 varyngs. Even for simple fragment shader (gl_FragColor = v0 + v1 + v2 + .. + v7;).

For each varying hw must interpolate and compute perspective correction on it in rasterization stage.


05-24-2004, 08:26 AM
ok, but i really think that a simple vec3/4 interpolation is less expensive than a reflect + normalize for each fragment (don't know about the perspective correction complexity).

As you said, perhaps it's due to some hardware limitation...

Anyway, i would really appreciate some light on the "varying" mechanism and the way it is implemented (at least for personnal culture ;) )