Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a dynamic surface in WebGL, that is animated in vertex shader. I want other objects to interact with this surface (for example, an object riding on dynamic terrain). What's the best way to do this? Should all these calculations be done on CPU? Is there a way to calculate this stuff on GPU?

Basically, what I want is vertex shader with access to other (already transformed) vertices -- that would be perfect.

share|improve this question

A vertex shader cannot access transformed vertices in WebGL. It can only access uniforms and attributes sent in via one of the draw calls from a bound buffer.

As an example let's discuss how to place a piece of vegetation on a heightfield. Suppose you render the heightfield and transform the terrain vertices in the VS according to this heightfield. Then you render your object and you need to move it by the height it inhabits over that field. A way to do that without CPU work is to pass in an objects center (either via uniform or via attribute) and lookup the heightfield value at the objects center, and then move the vertices vertically by that amount.

share|improve this answer

You could always represent your original vertices as a texture that is sampled in a fragment shader, and all the appropriate transformations to said vertices can be performed there and rendered to an offscreen render target (i.e. render to texture operation). The data in the resulting rendered texture should then represent the transformed vertices that you're after...

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.