kirbysayshi / HSHG

Hierarchical Spatial Hash Grid, used for fast spatial hashing in 2D and 3D of any sized object in infinite space
8 stars 2 forks source link

Improve HSHG by using shaders #1

Open sled opened 12 years ago

sled commented 12 years ago

hi,

I've read the paper about HSHG and found your implementation in JavaScript, which is great by the way. I'm currently writing my own physics engine in JavaScript using WebGL and I was wondering if you have thought about moving some parts into a shader program so that the collision detection could be outsourced to the GPU. I think there would be a great boost in performance because the collision detection could take use of the GPU's parallel architecture.

My idea was to map the grids on to a texture, upload it to the GPU - perform the collision detection and write the result to another texture which gets rendered into a framebuffer that can be accessed by javascript.

What do you think?

best regards

Simon

kirbysayshi commented 12 years ago

Simon, that sounds absolutely awesome! But that is also beyond my current expertise... I have very little knowledge of 3D graphics.

Given that, i do have a few ideas about what you've written...

While yes, you could use the parallel architecture to speed things up, would it in the end? You might spend a lot of time translating between the shader/framebuffer representation and the actual objects... maybe you could map each object to a particular shade of color? But then you have to somehow translate the framebuffer, which I assume would just be pixels, into a list of colliding objects. How would you do that?

If you think you have a pretty good idea of how it might work, please do share, or even try writing it!