Advertisement Jump to content


This topic is now archived and is closed to further replies.


im new to vertex shaders....

This topic is 5890 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, first of all i''m a math & comp science major and am familiar with 3-d math and space warps and such; and very clear on the basic 3d gfx pipeline. Let''s say i wish to animate simple ocean waves. Correct me if i''m wrong on this.... I would setup a vertex buffer with all the neccessary vertices that i need, and this vb would pretty much stay constant from frame to frame. Then i setup a vertex shader that would effectivly space warp all the points in my vb along a sine wave or the like. Good so far? But then of course i want the waves to actually be moving, so as a function of time i would modify my vertex shader each frame. *or* is there some way that i can program the vertex shader to automaticly be a function of time, so that i dont need to manually change my vertex shader each frame? Also, If you have some source code of implimenting that using directx7/8 that would be very helpfull. Thanks! - Duck17

Share this post

Link to post
Share on other sites
A vertex shader is nothing but a small program, which is executed for each vertex, and that can modifiy various vertex attributes (colour, position, normal, etc). You only need to load/bind a new vertex shader, if you want to change the algorithm to be applied to the vertex.

For your situation, you would use some form of time dependend program. You won''t need to change the shader program at all, load it once at startup, and that''s it. Time will be a single one-dimensional variable. Design your shader program in such a way, that it computes the height of the ocean vertex, depending on it''s position on the plane (x,y) and the current time.

Now, there are a number of vertex shader registers (read: variables) that can be set by the user, and that keep their given value until the user changes it again. The value can be read by the vertex program, and will be the same at every vertex. Your time variable will be such a value.

In summary: Compute your current time step on the CPU (depending on framerate, speed of the ocean waves, etc). The result will be a scalar floating point value. Set a constant vertex shader register component of your choice to this value. In your vertex shader, use this value as the current time for your wave synthesis.

/ Yann

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!