I know this is a very difficult thing to simply modify without the full project code, but I am having a massive performance problem with GLSL code that seems to be very efficient to me. I am stuck at 14 fps if I use mipmaps and only 23 if I am simply using the normal glTexImage2D() method, yet have it setup to render 30 times per second. The problem is in the fragment shader - the vertex shader is ridiculously fast, as it is just passing the parameters in to the fragment shader.
varying vec4 color;
varying vec3 normal;
varying vec4 position;
uniform sampler2D t_diffuse;
uniform sampler2D t_bump;
uniform sampler2D t_specular;
uniform mat4 light_color;
uniform vec4 light_position;
void main() {
vec4 diff = texture2D(t_diffuse, gl_TexCoord[0].st);
vec3 bump = normalize(texture2D(t_bump, gl_TexCoord[0].st).xyz * 2.0 - 1.0);
vec4 spec = texture2D(t_specular, gl_TexCoord[0].st);
vec4 ambient = vec4(light_color[0][0], light_color[0][1], light_color[0][2], light_color[0][3]);
vec4 diffuse = vec4(light_color[1][0], light_color[1][1], light_color[1][2], light_color[1][3]) * diff;
vec4 specular = vec4(light_color[2][0], light_color[2][1], light_color[2][2], light_color[2][3]) * spec;
vec3 vector = light_position.xyz - position.xyz;
float distance = sqrt((vector.x * vector.x) + (vector.y * vector.y) + (vector.z * vector.z));
vec4 final = ambient + diffuse + specular;
final.xyz *= max(0.0, dot(normalize(vector), bump)) / distance;
gl_FragColor = final;
}
The light_color variable holds one color in each row, so light_color[0] is red, light_color[1] is green, et cetera.
The textures aren't even vary large - and even then, I can do Starcraft 2 at max settings (30-40 fps), so it isn't like they are much of an issue. What is in here that can possibly be so slow?