Skip to main content
GameDev.net gamedev.net
🔒 Locked

Physics on GPU using the vertex shader

Started by fromthefuture Mar 14, 2011 at 6:47 PM 1 replies 3.5k views
Original Post
fromthefuture
fromthefuture
I'm trying to implement simple physics on the graphics card, is it possible to put the physics equations into a vertex or pixel shader? Will it be faster then doing it on the cpu? I've read a few posts by other on this and other sites, and they seem to be saying that it's hard to do because vs and ps can't write the positions of the transformed vertecies back to system memory, that means you have to encode those vertices as textures etc. But I don't understand why I need to get the vertices back from the card. As far as I know, physics simulations (where there is no collisions involved) are not dependent on the previous positions of the objects. All thats required is time, which can be easily sent every frame. Inside the shader I would have techniques that would represent what sort of a physics field I want to simulate. Is this doable? p.s I know there are bunch of libraries that are natively implemented on the GPU like Havok, PhysX, but I want to write my own equations because this project is more for my physics class then for a game. I want to be able to visualize the formulas that we're going through, and since I know how to program I thought it would be useful to implement each chapter that we go through in code, that way I have a small physics engine by the time the class is done. Thanks
Non est ad astra mollis e terris via
karwosts
karwosts
Well as long as there is no persistant state involved, you can implement whatever equations you want inside the gpu. I think when most people refer to "physics" in a game context they are really referring to collision detection, gravity, etc.. all things that affect the game flow and need to be known by the non-graphics side of the engine.

I have no idea what you're really trying to do, so if you think you can implement it you probably can. May want to consider something like CUDA or OpenCL, which may be a more natural fit for parallel equation solving than trying to shoehorn a non-rasterization problem into the shader model (where vertices are supplied, then transformed into primitives, interpolated, rasterized, etc).
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
fromthefuture
fromthefuture
Thanks, on second thought I think im just overcomplicating things, ill just do the calculations on the cpu and I don't have to worry about any work arounds.
Non est ad astra mollis e terris via

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.