This post is the second part in a series. Make sure to start with:        Making a falling sand simulator first!              Immediately

Improving the foundation of our falling sand simulator

submited by
Style Pass
2022-05-16 02:30:07

This post is the second part in a series. Make sure to start with: Making a falling sand simulator first!

Immediately you may notice that sand still forms a perfect pyramid and the wood looks pretty ugly. It's true, and we won't be tackling these in this post.

In the previous post, our Grid held hex strings, or a 0. If we want to be able to add new particles with different rules, we need to lay a strong foundation to build upon - that is, storing objects, not colors.

And add a concept of an empty particle, which every single other pixel, will represent. That's right, lots of instances of Empty.

Just hit "Start Rendering", and when you're ready for the next step, "Pause Rendering". The current approach is very inefficient, and we're going to improve it starting in the next step, so let's not waste computation by keeping this running.

Parsing the color from a string for every channel of every pixel on every frame is expensive! Fortunately now that we know what the problem is, it's a pretty simple fix. We just need to calculate the channels at particle creation time, which we can do in our approach with p.color, then we don't need to do any parsing at draw time, because we're passing around an object with the channels pre-calculated.

Leave a Comment