Can I have access to vertex/index buffer in shader?

Started by
3 comments, last by ritzmax72 5 years, 3 months ago

Constant buffer is used to change transformation matrix of objects and it happens per user interaction. This only changes the camera. What if I wanted to deform and move cube(Let's say I am rendering a cube) on user input. Since cube vertices/index are on vertex and index buffers I can modify them per frame using some upload buffer. Using upload buffer to update coordinates(due to user input) 
doesn't seem performance friendly. Let's say that cube is a character user is controlling. User might be moving the character very fast. So I was thinking if it was possible to access a large buffer of vetex and index resource type in shader and then I could manipulate the character directly from GPU; by sending some transformation data through constant buffer.

Which resources are used to represent highly movable objects in game world? index/vertex buffer, constant buffer or what?
 

Advertisement

What you described is exactly what the vertex shader does. You have the responsibility to determine the screen position of each vertex in that shader which also means that you are free to displace them on the fly however you like. You don't need to reupload vertex data everytime.

There are a couple ways to approach this. The simplest, as mentioned above, is to simply implement the deformation effect in the vertex shader. If you're dealing with a simple one in, one out style of effect then this is a great way to do it and this is how skinning for example is done.

The next step up in sophistication is to not supply the vertex directly to the vertex shader, but to give it access to the entire buffer and use the vertex index to look up the vertices in a more flexible format. (Some GPUs only work this way internally.) That way your vertex shader can use multiple vertices or arbitrary vertices to compute its final output.

The most complex version of this is to write a buffer to buffer transformation of the vertices, which can either be done via stream out in the simple cases or a compute shader in the advanced cases. This lets you store the results for later, not just compute them instantaneously for that frame.

SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

Thanks Promit. I will try to reproduce as you mentioned

This topic is closed to new replies.

Advertisement