Jump to content
  • Advertisement
Sign in to follow this  
SKerner

OpenGL cg Vertex Shader and multiple objects

This topic is 4874 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

I hope this is the right forum for my problem. If not, please redirect me. I'm trying add a wind animation to an OpenGL tree model. I figured out, the best way would be to use cg vertex shader. The problem is, the tree does not consist out of one mesh, but is constucted using cylinder shaped objects for each branch. I move recursively through my tree object, draw each tree and coordinate system with glRotate and glTranslate and draw the next part. This works really fine for static trees. But if I apply a simple Vertexshader to bend the branches, the next branch is not longer connected to the previous one, cause the shader does not transform glRotate and glTranslate. This tears my branches apart. How can I animate serveral connected objects via vertex shading without losing the connection? Do I need to transform my tree in one mesh, or is there a way to do this in different coordinate systems?

Share this post


Link to post
Share on other sites
Advertisement
It does seem like you need to update the modelproj matrix after every transformation so that the shader is ready to handle the new subtree. It's strange that its still not working.

That is unfortunate. If you are really rotating and translating each branch between rendering calls then its going to be tough and a lot of calls to update the matrix. If the tree had one coordinate system with every polygon relative to that, then you could simply apply a shader that skews the trees position proprortionally to height of a vertex sqared. I've done something like that with a flagpole and it gives a nice looking bend as long as you keep it subtle. I sent a vector with the wind velocity in tree-space and a float that defined the trees "flexibility". That doesnt really answer your question though, now does it. sorry.

just try to send a new modelproj matrix to the shader every time you have made changes to the modelview matrix.

EDIT: I wrote that before i saw your next post.

What exactly is your shader doing?

Share this post


Link to post
Share on other sites
I transformed every vertex in the same basic coordinate system. Now I can draw the whole tree without using glRotate and can use the same Vertex Shader on every vertex.
But the problem is, to model the invuences in the shader. If a shader alters the vertices of a branch it must also do the chances for every branch conntected to this one.
Anyone has an idea for the actual shader or has done something like this before?

Share this post


Link to post
Share on other sites
I have tried something like this and really wasn’t happy with the results I was getting and gave up.

The wind movement was based off the vertex location and a hierarchical number. This number served as a “offset” for my sin based movement. All object ends touching an object had the same number; the other end would be higher. All the other ends had a higher number. And I would interpolate between the 2 when an object touched it part of the way up.

With all the effort to do this there were small problems still, and I figured animating the model would have faster and better looking results.

Share this post


Link to post
Share on other sites
That do you mean by 'animating the model'?
Do you mean windmovement without shader and to move the branches by altering the angle instead?

Share this post


Link to post
Share on other sites
As I said, my first approach was to render each branch in it's own coordinate system and than do transformation of the modelview matix and render the next tree.
One idea I had was to animate the tree by altering the angle between the branches and kind of wave with the branches.

Is there a possibility to let a shader do that work? I mean like let the matrix shade instead of the vertices?

It would make a better effekt, if you additionally use a shader to alter the vertices. Is there a possibility so that the vertex shader does not only shade the vertices, but also alters the transformation for the next coordinate system?

Share this post


Link to post
Share on other sites
Quote:
Original post by SKerner
That do you mean by 'animating the model'?
Do you mean windmovement without shader and to move the branches by altering the angle instead?


I mean by using a modeling program to make the tree and keyframe animate it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!