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