Search code examples
openglcollision-detectionglslwebglshader

Is there any example on the web how Collision Detection can be implemented with Shaders?


Is there any OpenGL, OpenGL ES or WebGL code example on the web how 3D Collision Detection can be implemented with Shaders (preferably GLSL)?

Thank you.


Solution

  • GLGE has shader based collision detection. See this demo. (WASD,spacebar and mouse to move around. Notice how you collide with walls, etc.)

    If you look at the source code, collision detection is handled with the code

    var ray=gameScene.ray(origin,[0,0,1]);
    

    If you follow this into glge.js you'll see how this is implemented with a special render mode GLGE.RENDER_PICK (which in turn uses a picking fragment shader in pkfragStr).