PDA

View Full Version : accessing texture in vertex shader



pegasy
04-28-2005, 12:39 AM
hi.
I'm writing a program that works similar to displacement mapping and needs to access texture in vertex shader.
However, my current code works quite slowly, about 0.2 fps.(the rendered result is correct though) After doing some debugging I found that this is caused by the "texture3D" function in the shader. If I remove this statement, the speed goes up to about 50 fps.
So I'm wondering if accessing texture in vertex shader is really that slow, or there're some potential bugs in my program that I'm not aware of.

Here's my source code

uniform sampler3D tex;
varying vec4 gl_FrontColor;

void main(void)
{
vec4 res=gl_Vertex;
vec3 sum=vec3(0,0,0);
sum=texture3D(tex,gl_MultiTexCoord0.xyz).xyz;
res+=vec4(sum,0);
gl_Position = gl_ModelViewProjectionMatrix * res;
gl_FrontColor = vec4(1,1,1,0);
}Could anyone with the experience of accessing texture in vertex shader give me some advice?
Thanks.

I'm working with a 6800GT, with the lastest driver(Forceware 71.89).

sqrt[-1]
04-28-2005, 12:44 AM
I think to get hardware accelerated vertex textures on Geforce 6 they need to be:
a) float texture format
b) not mipmapped
c) only 2D (possibly Rect?)

Correct me if I am wrong...

pegasy
04-28-2005, 01:17 AM
Well, I'm already using float texture format(GL_RGB32F_ARB) and mipmapping isn't turned on.
I tried 2D texture as well but it didn't make things better.(i.e., with texture2D() it's quite slow and without it, it's very fast)

I'm beginning to go mad on this. Is there anywhere I get some samples?

pegasy
04-28-2005, 03:17 AM
I've solved the problem.
What sqrt[-1] said is correct, it works only with 2D float textures.(You can calculate LOD for mipmapping by your own though) Besides, the filtering can only be GL_NEAREST or GL_NEAREST_MIPMAP_NEAREST(for min_filter). Otherwise, the vertices are processed by software and that's why my program got rather slow.(I was using GL_LINEAR)

This is where I found related materials, it really helped a lot.
http://developer.nvidia.com/object/using_vertex_textures.html

Java Cool Dude
04-28-2005, 07:18 AM
Hmmm, according to my own testings, using internal formats other than float luminance 32 would result into horrible slow downs.
This is how I declare my textures:


velocitiesTexture.create2DShell("Velocities Texture", width, height, GL_FLOAT, GL_LUMINANCE32F_ARB,
GL_LUMINANCE, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_NEAREST, GL_NEAREST);

locationsTexture.create2DShell("Locations Texture", width, height, GL_FLOAT, GL_LUMINANCE32F_ARB, GL_LUMINANCE,
GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_NEAREST, GL_NEAREST);