Shader-Based Chemical Simulations: Mitosis in Gray-Scott Model

BY Mark Howell 20 September 20244 MINS READ
article cover

The Gray-Scott Model of Reaction-Diffusion is a fascinating example of emergence. By simulating a small chemical system with only a few components and reactions, complex and mesmerizing patterns appear. These simulations can be interacted with directly, allowing users to drop some green and reset the simulation with ease. The underlying math and local rules are simple, but the computations are heavy. Each time step requires applying rules to compute the concentrations of every component at every location. Running such simulations on a CPU would be extremely slow, but GPUs are designed to handle large volumes of small computations in parallel.

Description: A visual representation of the Gray-Scott reaction-diffusion model showing complex patterns.

Prerequisites for Understanding Simulations

Simulating any physical system involves computing what happens at any location for any moment in time. However, the real world is continuous in space and time, which computers cannot simulate directly due to infinite computations. To overcome this, we discretize both space and time, subdividing space into a fixed grid and time into fixed durations. For each cell of this grid, a computation determines how its content changes over one time step, approximating a continuous world. The smaller the grid and time steps, the more accurate the simulation.

The Gray-Scott Model Explained

The Gray-Scott model describes a specific family of reaction-diffusion systems involving an auto-catalytic reaction. A chemical reaction consumes one or more reactants to produce one or more products, described by equations like \(A + 2B \rightarrow 4C\). The speed of a reaction is proportional to the concentration of every reactant. Diffusion spreads out and homogenizes chemical species concentrations, modeled as each cell leaking a fixed proportion of its content to its neighbors.

Implementing the Simulation with Shaders

Shaders are programs designed to run on a GPU, controlling how a 3D world is rendered to a 2D screen. They are written in languages like GLSL. By implementing the Gray-Scott simulation as a fragment shader, we leverage the GPU's parallelization strength. Web-based editors like Shadertoy allow compiling and running shaders in the browser without installation, making it easy to start writing shaders.

Writing the Shader Code

The shader code involves defining variables and setting an initial state for the simulation. Constants for the reactions and diffusion are defined, and the simulation is initialized with a fixed state for the first 10 frames. The shader then repeatedly applies update rules to every pixel in the texture buffer, effectively running the simulation.

Playing with the Simulation

Experimenting with different parameter values can produce a wide range of behaviors. The Gray-Scott model has been studied in-depth, and certain parameter values are known to produce interesting results. Users can interact with the simulation by tuning parameters and adding catalysts to observe the emergent patterns.

Description: An example of shader code used to implement the Gray-Scott model.

Hacking on the Code

Beyond tuning parameter values, there are other ways to experiment with the simulation. The Gray-Scott model can be seen as a continuous extension to discrete cellular automata like Conway’s Game of Life, where each cell's state is represented by two numbers from a continuum of possible values. Other continuous cellular automata include the Lenia family and Flow Lenia, used by researchers to explore conditions for the emergence of proto-life.

Conclusion

Using shaders for simulations introduces GPU programming in an accessible way. This approach simplifies the complex linear algebra involved in 3D rendering, making it easier to implement concepts familiar to many. Exploring systems that exhibit emergence is a fascinating field, and future posts will delve deeper into this topic.
Remember these 3 key ideas for your startup:

  1. Leverage GPU Power: Utilizing GPUs for parallel computations can significantly speed up complex simulations, making them feasible for real-time applications. This can be a game-changer for startups working on computationally intensive tasks.

  2. Experiment with Parameters: Tuning simulation parameters can lead to a wide range of emergent behaviors. This flexibility allows startups to explore various scenarios and optimize their models for better outcomes.

  3. Use Web-Based Tools: Platforms like Shadertoy provide an easy way to write and run shaders in the browser, reducing the need for complex setups. This accessibility can save time and resources, allowing startups to focus on innovation.

Edworking is the best and smartest decision for SMEs and startups to be more productive. Edworking is a FREE superapp of productivity that includes all you need for work powered by AI in the same superapp, connecting Task Management, Docs, Chat, Videocall, and File Management. Save money today by not paying for Slack, Trello, Dropbox, Zoom, and Notion.

  1. Description: Edworking superapp interface showcasing integrated productivity tools.
    For more details, see the original source.

article cover
About the Author: Mark Howell Linkedin

Mark Howell is a talented content writer for Edworking's blog, consistently producing high-quality articles on a daily basis. As a Sales Representative, he brings a unique perspective to his writing, providing valuable insights and actionable advice for readers in the education industry. With a keen eye for detail and a passion for sharing knowledge, Mark is an indispensable member of the Edworking team. His expertise in task management ensures that he is always on top of his assignments and meets strict deadlines. Furthermore, Mark's skills in project management enable him to collaborate effectively with colleagues, contributing to the team's overall success and growth. As a reliable and diligent professional, Mark Howell continues to elevate Edworking's blog and brand with his well-researched and engaging content.

Trendy NewsSee All Articles
CoverEdit PDFs Securely & Freely: Breeze PDF In-Browser SolutionBreeze PDF is a free, offline browser-based PDF editor ensuring privacy. It offers text, image, and signature additions, form fields, merging, page deletion, and password protection without uploads.
BY Mark Howell 2 mo ago
CoverDecoding R1: The Future of AI Reasoning ModelsR1 is an affordable, open-source AI model emphasizing reasoning, enabling innovation and efficiency, while influencing AI advancements and geopolitical dynamics.
BY Mark Howell 26 January 2025
CoverSteam Brick: A Minimalist Gaming Console Redefines PortabilitySteam Brick: A modified, screenless Steam Deck for travel, focusing on portability by using external displays and inputs. A creative yet impractical DIY project with potential risks.
BY Mark Howell 26 January 2025
CoverVisual Prompt Injections: Essential Guide for StartupsThe Beginner's Guide to Visual Prompt Injections explores vulnerabilities in AI models like GPT-4V, highlighting security risks for startups and offering strategies to mitigate potential data compromises.
BY Mark Howell 13 November 2024
CoverGraph-Based AI: Pioneering Future Innovation PathwaysGraph-based AI, developed by MIT's Markus J. Buehler, bridges unrelated fields, revealing shared complexity patterns, accelerating innovation by uncovering novel ideas and designs, fostering unprecedented growth opportunities.
BY Mark Howell 13 November 2024
CoverRevolutionary Image Protection: Watermark Anything with Localized MessagesWatermark Anything enables embedding multiple localized watermarks in images, balancing imperceptibility and robustness. It uses Python, PyTorch, and CUDA, with COCO dataset, under CC-BY-NC license.
BY Mark Howell 13 November 2024
CoverJungle Music's Role in Shaping 90s Video Game SoundtracksJungle music in the 90s revolutionized video game soundtracks, enhancing fast-paced gameplay on PlayStation and Nintendo 64, and fostering a cultural revolution through its energetic beats and immersive experiences.
BY Mark Howell 13 November 2024
CoverMastering Probability-Generating Functions: A Guide for EntrepreneursProbability-generating functions (pgfs) are mathematical tools used in probability theory for data analysis, risk management, and predictive modeling, crucial for startups and SMEs in strategic decision-making.
BY Mark Howell 31 October 2024
Try EdworkingA new way to work from  anywhere, for everyone for Free!
Sign up Now