>> Monday, October 10, 2011
I've coded a few physics-based applications with OpenGL, and the overall operation is simple: the host computes a figure's new position based on its velocity and acceleration, and sends the position delta to the vertex shader as a uniform. The vertex shader updates each vertex position with the delta and the figure moves over time.
But now I'm implementing the physics processing with OpenCL. At the moment, my goal is to execute the following loop:
for each figure in the in model
if figure collided with another
change velocity and acceleration of both figures
I'm using the GJK method to detect collisions, and it's not easy. But my main concern is this: if the OpenCL kernel computes velocity and acceleration without updating the host, the host can't set the uniform properly for the vertex shader. However, the kernel can modify the VBO data directly, thereby making the uniform unnecessary.
This raises another concern. In my earlier code, the vertex shader applied the physics update after performing the modelview-perspective transformation. But with this new method, the shader will receive VBOs that have already been updated based on velocity and acceleration. This out-of-order transformation may cause an error.
I'm starting to think that the OpenCL kernel should take over the vertex shader's processing. I wonder what effect this will have on performance.