GLSL and NV_vertex_program

Hello,

How can use the NV_vertex_program extension in a GLSL vertex shader. I mean, I have all the shader code written in GLSL but now I need to make a texture lookup in the vertex shader (at an acceptable rate). Creating the texture in GL_FLOAT_RGB32_NV format and leave the rest as it is seems not to be enought because I get a black texture. I read some topics about using the NV_vertex_program3 extension but I’m not sure hoe this is done. All examples I’ve seen with this extension don’t use the GLSL programs (with uniform variables, main functions etc.). So my question is: having the code in GLSL, how can I use this extension to be able to do texture lookups? Can you give me some highlights or point me to some documentation? I’m using the NVIDIA GeForce 6600GT.
Thank you for your attention.

How can use the NV_vertex_program extension in a GLSL vertex shader.
You don’t.

It’s up to nVidia to expose NV_vp3 functionality through their glslang shader. If they aren’t, then the only recourse is to use NV_vp3 itself, or bug nVidia to get working on it.

The problem is most likely with the texture format you use. Nvidia doesn’t support all texture formats in vertex shaders yet. So far only float textures are supported. So the problem should be unrelated to the use of GLSL versus NV_vertex_program_whatever.

Basically, what the other guys are saying is that you don’t need any extensions. The feature is part of GLSL already.

You sample a texture with textureXDLod

From GLSLandSpec.Full.1.10.59.pdf

The built-ins suffixed with “Lod” are allowed only in a vertex shader. For the “Lod” functions, lod is
directly used as the level of detail.

and visit nvidia and download Vertex_Textures.pdf
It talks about everything except GLSL.

Your texture needs to use the GL_RGBA32F_ARB or GL_LUMINANCE32F_ARB format if you want hardware accelerated vertex textures.

More details here: http://developer.nvidia.com/object/using_vertex_textures.html

Hi all!

[/QUOTE]and visit nvidia and download Vertex_Textures.pdf
It talks about everything except GLSL.[/QB][/QUOTE]

That’s my problem! Does the GLSL implementation of NVIDIA really support vertex texturing? I considered all the things that the paper suggests, especially using the right texture formats. But I still get zero texture lookups in the vertex shader. Please take a look at the following code sample:

------BEGIN CODE SAMPLE------------------
glGenTextures(1, &m_iTexName1);
glBindTexture(GL_TEXTURE_2D, m_iTexName1);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT32_ATI, width, height, 0, GL_RGBA, GL_FLOAT, m_pTexData);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);

glUseProgramObjectARB(m_iProgramObj2);

glBindTexture(GL_TEXTURE_2D, m_iTexName1);

<draw points> // These points should be displaced
---------END SAMPLE CODE-------------------------

Here comes the shader:

----VERTEX SHADER----
uniform sampler2D tex2;
void main()
{
vec3 transl = gl_Vertex.xyz;
vec4 sample;
vec4 pos;

sample = texture2D(tex2, gl_TexCoord[0].st);
pos = vec4(vec3(sample.r, sample.g, sample.b) + transl, 1.0);
gl_Position = gl_ModelViewProjectionMatrix * pos;
gl_TexCoord[0]  = gl_MultiTexCoord0;

}

The texture size is quadratic and the width and height is power of 2. The <draw points> function does provide texture coordinates. The purpose of the vertex shader is just to displace the incoming vertex position by the texture lookup.
The output of my program is, that alle points I draw are on the same position, i.e. they are not displaced.

Now comes the remarkeable thing: I replaced the GLSL vertex shader by an assembly vertex program. Just like the one shown in the NVIDIA whitepaper “Vertex Texturing”. Now the points are correctly displaced, whith the same texture!

What am I doing wrong in the GLSL case?? By the way, the compiler does not give any error messages. Also note, that I’m not using mipmapping, so no need for using texture2DLod() !?

Here’s the assembler code that does the job right:

------VERTEX SHADER---------
char *vertexProgram =
"!!ARBvp1.0
"
"OPTION NV_vertex_program3;
"
"ATTRIB pos = vertex.position;
"
"TEMP dpos, displ;
"
"PARAM mat[4] = {state.matrix.mvp};
"
"TEX displ, vertex.texcoord, texture[0], 2D;
"
"ADD dpos, pos, displ;
"
"DP4 result.position.x, mat[0], dpos;
"
"DP4 result.position.y, mat[1], dpos;
"
"DP4 result.position.z, mat[2], dpos;
"
"DP4 result.position.w, mat[3], dpos;
"
"MOV result.color, vertex.color;
"
"END
";

Many thanks for any help!!
spyth

Try using the texture2DLod function instead of texture2D.

Originally posted by jra101:
Try using the texture2DLod function instead of texture2D.
Thanks for the proposal. But I already tried it and it didn’t change anything.

Does anyone has a working GLSL vertex shader with a simple (i.e. without mipmapping) texture fetch? I’ve search the web for some time. Most people did use the wrong type of texture. But I definitely do use the correct one, 'cause the same texture can be used in a assembly vertex program. GLSL just don’t do it for me! :frowning:

I am realy running out of new ideas, how to solve this problem!

spyth

Did you setup the sampler uniform correctly? (vertex texture image unit 0) and look at what you used to fetch the texture.
You need to use the vertex attribute gl_MultiTexCoord0 not the vertex varying output gl_TexCoord[0]!
Try this:

uniform sampler2D tex2;
void main()
{ 
  gl_Position = gl_ModelViewProjectionMatrix *
                vec4(texture2D(tex2, gl_MultiTexCoord0.st).rgb + 
                     gl_Vertex.xyz, 1.0);
                // or texture2DLod with mipmaps.
  gl_TexCoord[0] = gl_MultiTexCoord0;
}

Originally posted by Relic:
[b] …
Try this:

uniform sampler2D tex2;
void main()
{ 
  gl_Position = gl_ModelViewProjectionMatrix *
                vec4(texture2D(tex2, gl_MultiTexCoord0.st).rgb + 
                     gl_Vertex.xyz, 1.0);
                // or texture2DLod with mipmaps.
  gl_TexCoord[0] = gl_MultiTexCoord0;
}

[/b]
Oh my God! Yoda would say: “Made a stupid mistake you have! Assign a value to gl_TexCoord[0] first you have, before use it you can!”
Well, yes indeed, master. :slight_smile:

Thanks Relic for help!
spyth

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.