PDA

View Full Version : why my vertex shader is killing the framerate



homer_simpson0
02-19-2009, 09:12 PM
i'm simply trying to use a heightmap to make a terrain with glsl

this is my vertex shader.


uniform sampler2D texx;
varying vec2 vTexCoord;
void main(void)
{
vec4 position = vec4(gl_Vertex.x, 0.0, gl_Vertex.z, 1.0);
gl_TexCoord[0] = gl_MultiTexCoord0;
vec4 color = texture2D(texx,gl_TexCoord[0].st);
position.y=gl_Vertex.y+((color.r+color.g+color.b)* 10);
gl_Position = gl_ModelViewProjectionMatrix * position;
}


it works but it is very slow. i am using GL_NEAREST for filtering and i'm pretty sure something stupid that i've done.
thanx in advance.

ZbuffeR
02-20-2009, 12:48 AM
Hardware ? VTF can be very slow on some cards. How many vertices in your mesh ?

If your replace the texture2D() with a constant, I guess it is very vast ?

scratt
02-20-2009, 01:38 AM
What ZbufferR said. I'd bet money it's falling back to software for the VTF.

Hardware? ATI by any chance?

homer_simpson0
02-20-2009, 08:45 AM
i have nvidia 7800 gt, and the mesh is 256x256
i had expected more from the card =/

plus i thought that glsl is implemented in purely harware in the pipeline?

Nicolai de Haan Brøgger
02-20-2009, 01:18 PM
Performance will be OK (although not exceptional) with VTF on GT7800 as long as you use one of the two texture formats that are hardware-accelerated in the VS - GL_LUMINANCE32F_ARB and GL_RGBA32F_ARB. Make sure you stick to NEAREST though even with these to avoid the software fallback.

homer_simpson0
02-21-2009, 03:44 PM
i know this might sound stupid but you mean to use my textures using :
glTexImage2D(GL_TEXTURE_2D, 0, type, width, height, 0, GL_RGBA32F_ARB, GL_UNSIGNED_BYTE, imageData);

??
because when i tried that the texture doesn't get passed to down to program shader at all. =S

Brolingstanz
02-21-2009, 05:36 PM
You need to bind your texture to the current program using glGetUniformLocation to retrieve the sampler in tandem with glUniform1i to set its value.

homer_simpson0
02-22-2009, 09:40 PM
problem solved:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT32_ATI, texture[0].width, texture[0].height, 0, type, GL_UNSIGNED_BYTE, texture[0].imageData);


i had to use GL_RGBA_FLOAT32_ATI anything else would fall back on software...

bertgp
02-24-2009, 06:47 AM
problem solved:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT32_ATI, texture[0].width, texture[0].height, 0, type, GL_UNSIGNED_BYTE, texture[0].imageData);


i had to use GL_RGBA_FLOAT32_ATI anything else would fall back on software...

Hmmm... That's impossible. Something else must have changed since (from glext.h):

#define GL_RGBA32F_ARB 0x8814
#define GL_RGBA_FLOAT32_ATI 0x8814

Relic
02-25-2009, 07:59 AM
>>glTexImage2D(GL_TEXTURE_2D, 0, type, width, height, 0, GL_RGBA32F_ARB, GL_UNSIGNED_BYTE, imageData);<<

This didn't work because your user data format is invalid.
glGetError() would have told you.
It should have been GL_RGBA.
The GL_RGBA32F_ARB belongs into the internalFormat parameter!

homer_simpson0
02-25-2009, 07:17 PM
oh yes that too :p