Tuesday, January 27, 2015

I have recently been fiddling to try and fix problems I have encountered on this project which is now named Dynamaton. One issue I realized is that forces all take effect at the same magnitude at any particular distance. In reality, the electron shells of atoms repel each other strongly only in close proximity. To simulate this I included something that is very expensive: each force has a base "radius." Inside of this radius, particles do not interact using that particular force. Between that radius and the radius + 1, the force linearly increases to its maximum; then after radius + 1 it decreases with the inverse square law. This means that some forces will take effect in close proximity while some will take effect further away.

The biggest issue I had to deal with was making space toroidal. Since I implemented this by using the shorter radius, meaning that if on any particular axis the length was more than half of the space I would use the radius that wraps around, if two particles were precisely half of the width of the space in distance from each other they would toggle back and forth and achieve an equilibrium. This would always result in this pattern occurring in which every clump of particles spread into a cube matching the shape of the space like this.

I decided at this point that I would either leave space unbounded or bound it without making it toroidal. Unbounded space was not an option because then stuff would fly everywhere and it couldn't be seen. I tried bounding using a cube, which worked, but then everything went to the corners of the simulation. So now I am doing this.

I made it so that the velocity bounded off of the edge of the sphere where the hypothetical "new position" would be, not changing the position, when particles exceeded the bounds of the sphere.

Presently, this is single threaded and running on my CPU. I have plans to use OpenACC to easily make this run in parallel on my GPU, which should let me have many more particles than I presently do. Space segmentation optimizations will come later. The radius issue is particularly expensive because I must compute the square inverse of the adjusted radius for each force, which reduced the amount of particles I could spawn by a factor of 10, but it does make some significantly more interesting interactions, so I will continue to do this for now.

In addition, the meshes are set up. When particles enter a threshold and leave another, they mesh together and break apart. Before I had elasticity between meshed particles, but I might simply leave that functionality off. The last feature to implement is the reaction-diffusion system, so that will be coming up shortly. I also want to improve the graphics so that the particles look more like this shader toy shader and these spells from Skyrim (much more glowy). In addition to that, I will need to switch to the new shader pipeline, since I am sadly using OpenGL 1 features so far, since graphics performance isn't the limiting factor presently. OpenGL ES might be my target so that I can port this to Android fairly easily.

No comments:

Post a Comment