Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 10

Thread: displacement vertex program

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2003
    Posts
    10

    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
    Also i'm using ARB_VERTEX_PROGRAM

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

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,256

    Re: displacement vertex program

    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.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2003
    Posts
    10

    Re: displacement vertex program

    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

  4. #4
    Junior Member Regular Contributor
    Join Date
    Nov 2000
    Location
    Belmont, CA
    Posts
    249

    Re: displacement vertex program

    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?

    -Won

  5. #5
    Junior Member Newbie
    Join Date
    Mar 2003
    Posts
    10

    Re: displacement 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

  6. #6
    Junior Member Regular Contributor
    Join Date
    Sep 2000
    Location
    Lubbock, TX, USA
    Posts
    197

    Re: displacement vertex program

    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.

  7. #7
    Junior Member Regular Contributor
    Join Date
    Nov 2000
    Location
    Belmont, CA
    Posts
    249

    Re: displacement vertex program

    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.

    -Won

  8. #8
    Junior Member Newbie
    Join Date
    Mar 2003
    Posts
    10

    Re: displacement vertex program

    "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?

  9. #9
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    3,576

    Re: displacement vertex program

    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.

  10. #10
    Advanced Member Frequent Contributor
    Join Date
    Jan 2001
    Location
    NVIDIA, Austin, TX
    Posts
    555

    Re: displacement vertex program

    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:

    http://cvs1.nvidia.com/MEDIA/program...oise/vnoise.cg

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •