Tree movement

Hi,

I have some randomly generated trees in my game (these are sprites). What I want to do is apply some effect which makes the trees
‘bend’ slightly due to wind force. I think this is possible with some simple math:

treeX = (int) (originalTreeX + Math.cos(angle) * windForce);
angle+=0.1;

Problem with this is it would move the whole tree, what I need is this to be applied per pixel, can this be done in the fragment shader?

Thanks

Im not particularly well versed in modern opengl but theoretically you can make a function that takes the height of the pixel in the tree sprite and the wind factor and produces a directly proportional relationship between height and wind. Essentially, if the pixel is higher up in the tree, the wind affects it more

You should use a shader.
But if you dont want to do that you could just have 3 or 4 images for the tree, in each image let the tree be bent slightly more.
Then use the bent images when the wind blows, like an animation.

Thanks guys,

The extra images maybe the way to go for quickness, but fragment shader I’m sure shouldn’t be too difficult…