displacement vertex program

Hi i have a 1d texture that is filled with sin values and i’m trying to write a vertex program that will displace the surface by the values based in this texture? i can just displace by vertexPosition + S*vertexNormal; Where S is the look up value in the texture based on the textCoord of the vertex.

the problem is how would i go about looking up the texture value in the vertex program? is this even possible, if so how. Thanks for your help

[This message has been edited by default (edited 04-04-2003).]

I dont think you understood what vertex programs do.

But to keep the answer short, no you can’t. Besides, a lookup table is just as good and possiblly better when comes to precision.

I do admit that i am new to implementation of vertex programs, but V-man, I believe your coment was unwarrented.

I do feel that i have a good grasp on what vertex programs do and how they fit into the GL pipeline: bipasses the fixed T&L stage in the pipeline with a user defined stage, where we can custom alter an incoming vertcies color, position, textcoords, fog coords, etc… I do belevie that this is what i’m trying to do: Displace the mesh’s verticies along their normals by a set amount specifed by some set of data. Now i asked if this was at all possible using data from an exiting texture (i know VP process in the pipeline is well before the texturing stage) so thats why i asked.

but as one who is new to VP i am still trying to learn the ways and techniques in which things get done as well as the limitations. In essence was trying to accomplish this using a look up table i’m just unsure as how to propagate the table the VP. Would i use “ProgramLocalParameter”, etc? How would i pass this set of sin values to the VP, such that i could use the text coords to look up into this table and displace the vertex accordingly?

So i think you should have said: “i dont think you understood how to do things in a vertex program”

(which is obvious since i made this post)

instead of:
“I dont think you understood what vertex programs do.”

anyways if you could inform me on how i could do this with a look up table it would be greatly appreaciated. Thanks

Yes, it would be really really nice if vertex programs could access textures/lookup tables. First, I think you’re likely to see some kind of “render to vertex buffer object” extension first.

In any case, if your lookup table is just a sine table, can’t you just compute that in the vertex program?


“if your lookup table is just a sine table”

yeah i guess i could but i was looking to hopefully pass in arbitrary values so that i could deform the surface like a floating energy ball thing or something. The sin data was just a trial example of what i intended to do to a surface. Could i code a noise function into the VP to achive this? Thanks again

You should be able to hold small lookup tables in constant registers. Look in the spec to see how much you can fit in there. It’s not a lot though.

It depends on the noise function and the maximum size of your vertex program (determined by hardware or performance limits). There are lots of tutorials out there and painfully detailed specs on what can or can’t be done in vertex programs (or any part of the OpenGL API). You were smart enough to learn OpenGL in the first place, already have an idea about what vertex programs are, is it so hard to RTFM?

I think there are demos that create Perlin Noise (google-it if you don’t know), which is a useful kind of noise. If you want a “ripply” effect, you can just superpose multiple sine waves at different frequencies, with their phases offset at different rates. The frequencies, phases and orientation can be constants that you upload.


“You were smart enough to learn OpenGL in the first place, already have an idea about what vertex programs are, is it so hard to RTFM?”

I find part of a good learning process is the ablity to discuss the material I’m trying to learn, now i’ve look been looking over various examples that are quite simple, additionally i’ve read though parts of the extension registry on this extension as well as various other material i’ve been able to dig up (gdc presentation slides and a few web sites with tutorials, i’ve looked at some stuff provided by nvidia as well) so i do RTFM. And when i do RTFM and i have a question that needs some clarification then i seek the forums for help, as none of my peers are doing work in the 3d graphics area. So why be so mean when someone has a legitimate quesion?

You can’t do it the precise way you want it, but you can do it.

Do the dereferencing of the texture coordinate on the CPU. That is, for each texture coordinate in the vertex array, compute S and put it into a 1D attribute array. Bind it with the appropriate gl*Pointer call for binding attribute arrays. Have your vertex program take the scaler value out of that attribute index and use it as the ‘S’ in your equation. Problem solved.

You will need to recompute S if the texture coordinate change. But, otherwise, you’re done.

There are a couple examples in the Cg Toolkit that calculate noise in the vertex program, check out the cg_terrain and cg_vnoise demos.

If you want to see the vertex program source code, you can take at look at it here: