PDA

View Full Version : shader goes slow!



jedge
02-06-2006, 06:01 AM
Hi,
I'm just writing a (very) simple shader to compute geometry from a depth map (actually an elliptical depth map). The code is very simple and only require s a couple of texture lookups in the vertex shader. However, it runs extremely slow. The code for the vertex shader is below:

uniform sampler2D vs_elliptical_map;
uniform sampler2D vs_depth_map;

void main()
{
gl_Vertex = texture2D(vs_depth_map, gl_MultiTexCoord0.st)*(2.0f*texture2D(vs_elliptica l_map, gl_MultiTexCoord0.st) - vec4(1.0f));
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}

vs_elliptical_map stores an elliptical projection in a texture map, and vs_depth_map stores the depth of my object along each of these vectors. The code works - but as I say, it is slooow. In fact I don't think there is any significant advantage over calculating the elliptical projection in the vertex shader! If I comment out the gl_Vertex line the shader flies (as you'd expect because its just a pass through). The fragment shader just does texture mapping so I haven't included the code here. I'm running on an nVidia 6600 with the latest drivers.

jedge
02-06-2006, 06:34 AM
I've checked the info log and it seems that there is a couple of syntax errors (i.e. using 1.0f instead of 1.0) and you can't assign directly to gl_Vertex. I've fixed these but it still runs slow. The useful code is just a single line now:

gl_Position = gl_ModelViewProjectionMatrix*(texture2D(vs_depth_m ap, gl_MultiTexCoord0.st)*(2.0*texture2D(vs_elliptical _map, gl_MultiTexCoord0.st) - 1.0));

Any ideas?

V-man
02-06-2006, 10:23 AM
You should use 3Dlabs shader validator.

Besides what you mentioned, your first shader makes no sense. You are writting to gl_Vertex and using ftransform. ftransform won't use gl_Vertex

You are doing a VS and use texture2D which is meaningless. Use texture2DLod

Finally, the texture format matters.

ftp://download.nvidia.com/developer/Papers/2004/Vertex_Textures/Vertex_Textures.pdf

jedge
02-06-2006, 11:06 AM
Thanks for the reply. You're right - the first one shouldn't have worked at all (but strangely it did - maybe a clever compiler). I've fixed the speed issue by using the GL_RGBA32f_ARB format for the texture. Obviously it was the format that was the issue and it made the program run in software. I haven't had any issues with using texture2D in a vertex shader. The orange book says that texture2DLod can only be used in vertex shaders (because of the missing fixed functionality), but I can't see where it says that texture2D can't be used.

V-man
02-06-2006, 04:20 PM
I think what they mean is that in VS, only the "Lod" version can be used. At the vertex stage there isn't any "mipmap selection".
Maybe nVidia is mapping texture2D to texture2DLod(xxx, xxx, 0.0) which I think is not legal.