varying vec3 posToView;
varying vec3 transformedNormal;
varying vec3 posToLight1;
varying vec3 posToLight2;
void main(void)
{
vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Vertex);
posToView = normalize(-ecPosition);
transformedNormal = normalize(gl_NormalMatrix * gl_Normal);
posToLight1 = normalize(gl_LightSource[0].position.xyz - ecPosition);
posToLight2 = normalize(gl_LightSource[1].position.xyz - ecPosition);
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
fragment
varying vec3 posToView;
varying vec3 transformedNormal;
varying vec3 posToLight1;
varying vec3 posToLight2;
void main (void)
{
vec3 E = normalize(posToView);
vec3 R = normalize(-reflect(posToLight1,transformedNormal));
vec4 Idiff1 = gl_LightSource[0].diffuse * max(dot(posToLight1, transformedNormal), 0.0);
vec4 Ispec1 = vec4(1.0, 1.0, 1.0, 1.0) * pow(max(dot(R,E),0.0), 16.0);
R = normalize(-reflect(posToLight2,transformedNormal));
vec4 Idiff2 = gl_LightSource[1].diffuse * max(dot(posToLight2, transformedNormal), 0.0);
vec4 Ispec2 = vec4(1.0, 1.0, 1.0, 1.0) * pow(max(dot(R,E),0.0), 16.0);
gl_FragColor = Idiff1 + Ispec1 + Idiff2 + Ispec2;
}
When I enable this shader, my fps drops from 630 to 530. When I''m not using the shaders, I let the fixed function pipeline in opengl calculate the diffuse colors only with the same two lights.
Now it seems to me, there shouldn''t be such a large drop in speed.
I just tested some more, with emulating the diffuse color only in the vertex shader, and not having a pixel shader. This drops the framerate to around 500 fps. Why would a vertex shader only, have a lower fps than a vertex and pixelshader both? (in this case I write to gl_FrontColor in the vertex shader)