Slow shaders

Started by
1 comment, last by polyfrag 11 years, 4 months ago
I've noticed that when I use CamStudio to record my game while it uses shaders it's really slow but runs fine without shaders.

What's causing this slow down and how can I fix it?

The shaders do shadow mapping, multi-texturing, and diffuse lighting.

depth.vert:
void main(void)
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}


depth.frag:

void main(void)
{
gl_FragColor = vec4(gl_FragCoord.z);
}


shadow.vert:

uniform mat4 lightMatrix;
uniform vec3 lightPos;
uniform vec3 lightDir;
varying vec4 lpos;
varying vec3 normal;
varying vec3 light_vec;
varying vec3 light_dir;
out vec4 vpeye; // vert positions in eye coords
out vec4 vneye; // normals in eye coords
void main(void)
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;
vec4 vpos = gl_ModelViewMatrix * gl_Vertex;
lpos = lightMatrix * vpos;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
vpeye = gl_ModelViewMatrix * gl_Vertex;
vneye = normalize(vec4(gl_NormalMatrix * gl_Normal, 0));
light_vec = vpos.xyz - lightPos;
light_dir = gl_NormalMatrix * lightDir;
normal = normalize(gl_NormalMatrix * gl_Normal);
gl_FrontColor = gl_Color;
}


shadow.frag:

uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D shadowMap;
//uniform sampler2D texture4;
varying vec4 lpos;
varying vec3 normal;
varying vec3 light_vec;
varying vec3 light_dir;
in vec4 vpeye;
in vec4 vneye;
void main (void)
{
vec3 smcoord = lpos.xyz / lpos.w;
float shadow = max(0.5, float(smcoord.z <= texture2D(shadowMap, smcoord.xy).x));
vec3 lvec = normalize(light_vec);
float diffuse = max(dot(-lvec, normal), 0.0);
vec4 s_eye = normalize(vec4(lpos - vpeye)); // direction from point to light
vec4 v_eye = normalize(-vpeye); // direction from point to viewer
vec4 r_eye = reflect(-s_eye, vneye); // reflect vector from light to point based on normal
vec4 texColor = texture2D(texture1, gl_TexCoord[0].st) * texture2D(texture2, gl_TexCoord[1].st);
//vec4 spec = texture2D(texture4, gl_TexCoord[0].st) * pow(max(dot(r_eye, v_eye), 0), 128);
gl_FragColor = vec4(gl_Color.xyz * texColor.xyz * diffuse * shadow * 3.0, gl_Color.w * texColor.w);
//gl_FragColor = vec4(vec3(1,1,1) * pow(max(dot(r_eye, v_eye), 0), 10), 1);
}
Advertisement

I use CamStudio

Have you tried the free version of fraps ? Your shaders aren't really complex and should not be responsible for a slow down.

I found out that it was so slow because I was using a 4096x4096 shadow map.

This topic is closed to new replies.

Advertisement