• Advertisement
Sign in to follow this  

Slow shaders

This topic is 1853 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:
[code]void main(void)
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}[/code]

depth.frag:

[code]void main(void)
{
gl_FragColor = vec4(gl_FragCoord.z);
}[/code]

shadow.vert:

[code]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;
}[/code]

shadow.frag:

[code]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);
}[/code]

Share this post


Link to post
Share on other sites
Advertisement
[quote name='polyfrag' timestamp='1355471801' post='5010513']
I use CamStudio
[/quote]
Have you tried the free version of [url="http://www.fraps.com/"]fraps[/url] ? Your shaders aren't really complex and should not be responsible for a slow down. Edited by Ashaman73

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement