DEV Community

Cover image for CFAST Unity Dev Report #1: Integrating NIST's Fire Simulator into a Game — Real-Time Smoke Rendering and Numerical Stability
Hidenori Ishii
Hidenori Ishii

Posted on Edited on

CFAST Unity Dev Report #1: Integrating NIST's Fire Simulator into a Game — Real-Time Smoke Rendering and Numerical Stability

Table of Contents

Introduction

I am an independent developer working on a firefighting and disaster response game called SOKYU: OPERATION RESCUE BLAZE SERIES.

The project combines several technical disciplines, including game development, embedded systems, robotics, artificial intelligence, and fire simulation.

In this development report, I would like to introduce how I integrated CFAST, a fire simulator developed by the National Institute of Standards and Technology (NIST), with the Unity game engine.

In many video games, fire and smoke are represented using particle systems, shaders, and other visual effects.

For this project, however, I wanted to explore a different approach.

Rather than simply creating visually convincing fire and smoke effects, I wanted to calculate the underlying fire conditions and visualize the results inside Unity.

These conditions include:

  • Smoke accumulation inside rooms
  • Changes in smoke layer height
  • Temperature changes
  • Oxygen concentration
  • Gas transport between compartments
  • Smoke exhaust and air intake through doors and windows
  • Changes in combustion conditions caused by player interactions

The goal is to create an interactive game environment in which fire and smoke respond to changes in the simulated physical conditions.


1. What Is CFAST?

CFAST (Consolidated Fire and Smoke Transport) is an open-source fire simulation program developed by NIST.

Official website:

https://pages.nist.gov/cfast/

CFAST calculates the evolution of fire-generated smoke, gases, and temperatures in buildings containing multiple compartments.

It primarily uses a two-zone model, dividing each compartment into two gas layers:

  • Upper layer: A layer in which hot gases and smoke typically accumulate.
  • Lower layer: A relatively cooler gas layer.

As a fire develops, the temperature, gas composition, optical density, and thickness of these layers change.

CFAST also calculates gas transport through openings such as doors, windows, and horizontal vents.

Compared with computational fluid dynamics (CFD) simulators such as FDS, CFAST does not directly resolve detailed three-dimensional flow fields throughout a room.

Instead, it represents fire conditions at the compartment and gas-layer levels.

This relatively lightweight computational model makes CFAST an interesting candidate for integration with an interactive game engine.


2. The Game Project

SOKYU: OPERATION RESCUE BLAZE SERIES is an independently developed game project focused on firefighting and disaster response.

For the indoor firefighting experience, I am currently working with two residential environments:

Stage Building Layout
Stage01 One-bedroom apartment with a living, dining, and kitchen area (1LDK)
Stage02 Two-bedroom apartment with a living, dining, and kitchen area (2LDK)

Players take on the role of firefighters and perform activities such as entering buildings, operating firefighting equipment, opening doors, and extinguishing fires.

These actions can change the conditions inside the building.

For example, opening a door changes the available gas transport paths. Applying water to a fire changes its gameplay state and the heat release input sent to CFAST.

The challenge is to connect these interactive gameplay events to a scientific simulation.


3. Integrating CFAST with Unity

A conventional fire simulation workflow generally looks like this:

Building Model
    ↓
Fire and Ventilation Conditions
    ↓
Fire Simulation
    ↓
Simulation Results
    ↓
Analysis and Visualization
Enter fullscreen mode Exit fullscreen mode

The simulation conditions are defined before execution.

A game, however, cannot determine every player action in advance.

Players may:

  • Open or close a door.
  • Open a window.
  • Apply water to a fire.
  • Extinguish a fire.
  • Change the ventilation conditions inside the building.

The simulation therefore needs to respond to changing input conditions during gameplay.

To address this requirement, I developed a stateful derivative of CFAST that communicates with Unity and advances the simulation incrementally.

System Architecture

┌─────────────────────────────────┐
│              Unity              │
│                                 │
│  Player Input                   │
│  Fire State                     │
│  Door and Window State          │
│  Game Logic                     │
└───────────────┬─────────────────┘
                │
                │ STEP Request
                │ Fire and Opening Conditions
                ▼
┌─────────────────────────────────┐
│       CFAST Native Worker       │
│                                 │
│  Stateful Simulation            │
│  DASSL Numerical Solver         │
│  Compartment Gas Layers         │
│  Combustion and Gas Transport   │
└───────────────┬─────────────────┘
                │
                │ Simulation Results
                ▼
┌─────────────────────────────────┐
│        Unity Visualization      │
│                                 │
│  Fire Rendering                 │
│  Indoor Smoke Volume            │
│  Opening Smoke Particles        │
└─────────────────────────────────┘
Enter fullscreen mode Exit fullscreen mode

Unity sends a request containing updated simulation conditions and a target simulation time.

The CFAST worker advances the simulation to that time and returns the results.

Unity then validates the received data and updates the fire and smoke visualization.

This process is repeated throughout gameplay.

The important point is that CFAST preserves its internal simulation state between requests.

It does not restart the entire simulation whenever the player opens a door or changes a fire condition.


4. Visualizing CFAST Results in Unity

CFAST does not provide ready-to-render smoke particles or three-dimensional smoke meshes.

Instead, it provides numerical information describing the state of the fire environment.

I divide the smoke visualization into two separate rendering systems.

4.1 Indoor Volumetric Smoke

Indoor smoke is rendered using compartment geometry and the gas-layer information calculated by CFAST.

The main inputs include:

  • Upper-layer optical density
  • Lower-layer optical density
  • Gas-layer interface height
  • Compartment geometry

The upper and lower layers are visualized according to their calculated optical conditions.

As smoke accumulates and the interface moves downward, Unity updates the visible smoke volume.

          Ceiling
    ┌─────────────────────┐
    │                     │
    │  Upper Smoke Layer  │
    │                     │
    ├─────────────────────┤ ← Layer Interface
    │                     │
    │  Lower Gas Layer    │
    │                     │
    └─────────────────────┘
            Floor
Enter fullscreen mode Exit fullscreen mode

This approach makes it possible to represent smoke accumulation without relying entirely on the lifetime of individual smoke particles.

4.2 Smoke Transport Through Openings

Smoke moving through doors and windows is rendered separately.

The rendering system uses information such as:

  • Gas mass flow rate
  • Flow direction
  • Gas density
  • Opening area
  • Optical conditions of the source gas layer

The volumetric flow rate can be derived from mass flow rate and gas density:

Volumetric Flow Rate = |Mass Flow Rate| / Gas Density
Enter fullscreen mode Exit fullscreen mode

An average flow velocity can then be calculated using the relevant opening area:

Average Flow Velocity = Volumetric Flow Rate / Opening Area
Enter fullscreen mode Exit fullscreen mode

These values are used to drive the visualization of smoke moving through openings.

The resulting architecture is:

CFAST Simulation Results
          │
          ├── Compartment Layer Data
          │          │
          │          └── Volumetric Smoke Rendering
          │
          └── Opening Flow Data
                     │
                     └── Particle and Mesh Rendering
Enter fullscreen mode Exit fullscreen mode

CFAST is not calculating the position and velocity of every individual smoke particle.

The particles in Unity are a visualization driven by compartment-level and opening-level simulation results.

This distinction is important when using a zone model as the basis for real-time graphics.


5. A Numerical Stability Problem in Stage02

During development, I encountered a problem in which CFAST stopped returning new simulation results.

Unity itself continued running.

The player could still move and interact with the environment, but the indoor smoke and opening smoke could no longer receive updated simulation data.

Initially, several possible causes were considered:

  • Unity rendering performance
  • Asynchronous task management
  • Inter-process communication
  • File-based result handling
  • The CFAST numerical solver
  • Building geometry and simulation input conditions

To isolate the problem, previously recorded simulation inputs were replayed directly against the native CFAST worker, without Unity.

The numerical stall could also be reproduced in the isolated native environment.

One test produced the following result:

Measurement Result
Last accepted simulation time 16.10 s
Requested simulation time 16.15 s
Requested simulation interval 0.05 s
Response waiting time At least 112 s

A request to advance the simulation by only 0.05 seconds failed to return a response within 112 seconds.

This indicated that the problem was not simply a rendering performance issue inside Unity.


6. Investigating Horizontal Vents and Numerical Instability

The Stage02 CFAST building model consists of seven indoor compartments and an attic compartment.

Compartment Description
R1 Bathroom
R2 Washroom and dressing area
R3 Left bedroom
R4 Living, dining, and kitchen area
R5 Entrance hall
R6 Toilet compartment
R7 Right bedroom
R8 Attic

The investigation identified a problematic numerical condition associated with horizontal vent H4, which connected the living area (R4) to the attic (R8).

6.1 Discontinuous Gas Layer Assignment

CFAST determines how gas entering a compartment through a horizontal vent should be assigned to its upper or lower layer.

The investigated calculation includes a switching condition associated with a temperature difference of 1 K.

Near this boundary, small changes in the numerical trial values can change the destination layer of the incoming gas.

The following is a simplified conceptual representation:

             Gas Inflow
                  │
                  ▼
        Layer Assignment Decision
                  │
         Temperature Boundary
                1 K
                  │
         ┌────────┴────────┐
         ▼                 ▼
    Upper Layer       Lower Layer
Enter fullscreen mode Exit fullscreen mode

When the gas flow rate is significant, switching the destination layer can abruptly change the contributions to the mass, energy, and volume balance equations.

The problem becomes particularly important during iterative numerical calculations.

6.2 DASSL and Newton Iteration

CFAST uses DASSL, a numerical solver for differential-algebraic equations (DAEs).

A general DAE system can be represented as:

$$
F(t,y,\dot{y})=0
$$

DASSL uses backward differentiation formulas and iterative methods to solve the resulting nonlinear equations.

During the isolated investigation, I observed the following sequence:

Predict the next simulation state
                ↓
Evaluate the residual equations
                ↓
Perform Newton iteration
                ↓
Cross the temperature switching boundary
                ↓
Change the destination gas layer
                ↓
Abrupt change in residual
                ↓
Convergence failure
                ↓
Reduce the internal time step
                ↓
Repeat the calculation
Enter fullscreen mode Exit fullscreen mode

The repeated convergence failures and time-step reductions prevented the solver from efficiently reaching the requested simulation time.

This behavior resembles threshold-induced chattering in embedded systems.

However, it is important to clarify that the physical gas is not rapidly moving back and forth between layers.

The switching occurs in the numerical assignment of gas flow during the solver's internal trial evaluations.

6.3 Observed Numerical Evidence

The isolated test produced the following observations:

Measurement Observed Value
Gas inflow through H4 Approximately 12.49 kg/s
Change in R8 upper-layer volume residual Approximately +10.523 m³/s
Increase in Newton correction norm 67.3×
Internal time-step reduction To one-quarter
Convergence rejections 16,243
Rejections with layer switching observed in the same Newton pass 16,150

The co-occurrence rate was approximately:

$$
\frac{16150}{16243}\times100
\approx99.43\%
$$

In other words, layer switching was observed in the same Newton pass for approximately 99.43% of the recorded convergence rejections.

The change in the upper-layer volume residual also matched the calculated contribution from H4.

This provided evidence of the numerical mechanism connecting the layer assignment change to convergence rejection.

However, this percentage is an observed co-occurrence rate, not the probability that H4 caused every numerical stall.

The detailed mechanism was confirmed in an isolated test. It was not independently established for every unresponsive STEP observed during Unity gameplay.


7. Fixing the Building Model Instead of the Solver

After investigating the numerical solver, I reconsidered the building model itself.

In the Unity scene, the rooms are separated from the attic by structural ceilings.

However, the original CFAST model contained open horizontal vents connecting the indoor compartments to the attic.

The visual building and the simulation model were therefore inconsistent.

Instead of modifying DASSL or changing the gas transport equations, I decided to correct the building model.

Before the Modification

                 R8 Attic
    ┌─────────────────────────────────┐
    │                                 │
    └───↑────↑────↑────↑────↑────↑────↑┘
        H1   H2   H3   H4   H5   H6   H7
        │    │    │    │    │    │    │
       R1   R2   R3   R4   R5   R6   R7

        Gas transport into the attic
Enter fullscreen mode Exit fullscreen mode

After the Modification

                 R8 Attic
    ┌─────────────────────────────────┐
    │                                 │
    └═════════════════════════════════┘
         Structural ceiling: sealed

       R1   R2   R3   R4   R5   R6   R7

          H1-H7 permanently closed
Enter fullscreen mode Exit fullscreen mode

All seven horizontal vents, H1 through H7, were permanently closed.

The attic compartment itself was retained.

By eliminating gas transport through these openings, the contribution of the affected flow assignment to the gas-layer balance equations was removed.

The modification did not require changes to:

  • The production CFAST worker
  • DASSL
  • The physical calculation equations
  • Solver convergence tolerances
  • The temperature switching condition
  • Unity's shared smoke rendering system

This was a correction to the simulation input model, rather than a reduction in numerical accuracy.


8. Validation Results

After applying the building model correction, previously recorded inputs were replayed against the existing production worker.

The results were:

Validation Item Result
Previously unresponsive conditions resolved 3 / 3
Successful native STEP responses 1,078 / 1,078
Successful Unity tests 37 / 37
Failed Unity tests 0
Skipped Unity tests 0
Gas flow through H1-H7 Zero
Independent code review PASS
Outstanding review findings 0

The Unity scene tests covered three gameplay modes:

  • AIM3D
  • AIM3D2
  • ZERO

In the tested scenes, the accepted CFAST simulation time advanced beyond 20 seconds, while indoor smoke and opening smoke continued receiving updated simulation results.

Additional checks covered water damage state retention, entrance door operation in ZERO, and native worker release when returning to the title screen.

The modifications were integrated into the production source code.

These results establish that the previously identified unresponsive conditions were resolved within the tested scope.

They do not guarantee stability for every possible fire scenario, building configuration, hardware platform, or gameplay sequence.


9. Optimizing Smoke Rendering Performance

Numerical stability was not the only technical challenge.

Real-time smoke rendering also introduces CPU and GPU workloads.

During development, I identified unnecessary processing in Unity's opening smoke renderer.

Previously, particle retrieval and mesh updates could still be performed even when an opening had no smoke particles to render.

I introduced two optimization strategies.

9.1 Skip Unnecessary Operations for Empty Openings

When an opening has no particles to render, the following unnecessary operations are skipped:

  • Particle data retrieval
  • Vertex generation
  • Mesh data transfer

Appearance and boundary buffer updates are preserved.

If gas flow becomes zero while existing particles remain, their visualization continues according to the existing rendering behavior.

9.2 Reuse Existing Meshes

When the rendering input is exactly identical to the previous input, the existing mesh is reused.

The comparison includes information such as:

  • Particle position
  • Particle size
  • Particle rotation
  • Optical appearance
  • Transformation matrices

If the input changes, the mesh is updated normally.

Opening Smoke Rendering
          │
          ▼
    Particles Present?
       │        │
      No       Yes
       │        │
       ▼        ▼
 Skip Particle  Compare Rendering
 Retrieval and  Input with Previous
 Mesh Transfer        │
                ┌─────┴─────┐
                ▼           ▼
             Identical    Changed
                │           │
                ▼           ▼
             Reuse Mesh  Update Mesh
                │           │
                └─────┬─────┘
                      ▼
          Preserve Appearance and
           Boundary Buffer Updates
Enter fullscreen mode Exit fullscreen mode

No new approximation threshold or fixed mesh update interval was introduced.

The objective was to eliminate redundant work without deliberately reducing rendering quality.

9.3 Performance Measurement

A controlled comparison was performed in the Stage02 ZERO scene using the Unity Editor.

The test covered 13 openings containing no smoke particles.

Measurement Before After
Median CPU processing time 0.09370 ms 0.04965 ms
Particle retrieval calls per frame 13 0
Mesh write calls per frame 13 0

The reduction in CPU processing time was approximately:

$$
\frac{0.09370-0.04965}{0.09370}\times100
\approx47.01\%
$$

Approximately 47% less CPU processing time for the measured operation.

This is a component-level performance measurement.

It does not mean that the overall game frame rate increased by 47%.

The effect on overall FPS in the production standalone Player has not yet been confirmed.


10. Dynamic Interior Doors and Smoke Transport

Six interactive interior doors were added to Stage02.

All six doors begin in the fully closed state.

Opening Connected Compartments Opening Direction
V1 Entrance Hall ↔ Toilet Toward the entrance hall
V3 Bathroom ↔ Washroom Toward the washroom
V4 Living Area ↔ Left Bedroom Toward the living area
V5 Entrance Hall ↔ Washroom Toward the washroom
V6 Entrance Hall ↔ Living Area Toward the living area
V7 Living Area ↔ Right Bedroom Toward the living area

The former opening V2 is permanently closed. V7 is the designated entrance to the right bedroom.

When a player operates a door, Unity updates the opening condition and passes the relevant input to CFAST.

Player Opens or Closes a Door
              ↓
Unity Updates Door State
              ↓
Opening Conditions Sent to CFAST
              ↓
Gas Transport Calculation
              ↓
Updated Simulation Results
              ↓
Indoor and Opening Smoke Rendering
Enter fullscreen mode Exit fullscreen mode

For example, closing V6 prevents direct gas transport through that opening between the living area and entrance hall.

Opening V6 establishes a possible transport path between the compartments.

The actual flow rate and direction depend on the CFAST simulation results.

Opening a door does not simply trigger a predefined smoke effect.

It changes the input conditions of the fire simulation itself.

This is an important part of the interactive fire environment I am developing.


11. AI-Assisted Development and Independent Code Review

This project is being developed with the assistance of OpenAI Codex.

The development process involves more than generating Unity C# scripts.

It includes investigating Fortran source code, analyzing numerical simulation logs, implementing inter-process communication, and conducting regression tests.

I use separate implementation and review roles.

Requirements and Design
          ↓
Developer Approval
          ↓
AI Implementation Agent
          ↓
Testing and Measurement
          ↓
Independent Review Agent
          ↓
Developer Acceptance
Enter fullscreen mode Exit fullscreen mode

The developer remains responsible for defining the requirements, approving design decisions, and determining whether an implementation should be adopted.

One important lesson from this project was that AI-generated testing can expand beyond the actual requirements.

For example, an AI agent may introduce acceptance criteria for functionality that has never been designed or approved.

This can lead to unnecessary investigations, repeated tests, and implementation changes outside the intended scope.

I therefore established a development policy based on approved requirements.

Status Meaning
PASS The approved requirements are satisfied.
FAIL An approved requirement is not satisfied, or a regression exists.
BLOCKED A required verification cannot be completed due to a concrete blocker.
NOT_RUN An applicable test has not been executed.
N/A The functionality is outside the current scope.
PROPOSAL A proposed addition that requires approval.

The absence of an undesigned feature is not automatically a failure.

Before introducing a new feature, its relevance to the game must first be evaluated.

AI makes it possible to conduct extensive investigations and generate large numbers of tests.

However, effective software development still requires clear engineering objectives, defined responsibilities, and controlled acceptance criteria.


12. Interactive Technical Documentation

I have also prepared a technical explanation of the CFAST and Unity integration on the project website.

The website is designed to explain the simulation architecture through visual diagrams, animations, and interactive content.

CFAST × Unity Technical Guide

https://ronsard.sakura.ne.jp/sokyu/cfast-guide.html

Stage02 Technical Validation

https://ronsard.sakura.ne.jp/sokyu/cfast-guide.html#stage02-validation

The technical documentation covers topics such as:

  • CFAST's two-zone fire model
  • Stateful simulation and Unity integration
  • Indoor volumetric smoke rendering
  • Smoke transport through openings
  • Building compartment geometry
  • Horizontal vents and numerical solver instability
  • DASSL convergence rejection
  • Smoke rendering optimization
  • Dynamic interior doors

The project website is currently presented primarily in Japanese, with diagrams and visual explanations of the technical concepts.

If you are interested in the intersection of scientific simulation, game development, and real-time graphics, please take a look.


13. What I Learned from This Project

Integrating a scientific fire simulator with a game engine involves much more than importing simulation results.

The project has required work across multiple engineering disciplines:

Technical Domain Application
Numerical simulation CFAST and DASSL
Native software development Fortran
Game programming C# and Unity
Systems engineering Inter-process communication
Geometry processing Compartment and opening models
Computer graphics Volumetric smoke and particle rendering
Performance engineering CPU and GPU optimization
Software quality assurance Regression testing and independent review
AI-assisted development Codex

One of the most significant lessons was that a numerical solver problem does not necessarily require a numerical solver modification.

In this case, a mismatch between the visual building geometry and the simulation model introduced gas transport conditions associated with numerical instability.

Correcting the building model resolved the previously identified unresponsive conditions without modifying the production solver.

Another important lesson was the need to distinguish between the scientific simulation state and its visual representation.

CFAST calculates the physical state of the environment at the compartment level. Unity transforms the available numerical information into an interactive game experience.

The two systems serve different purposes, and understanding their respective responsibilities is essential.


14. Future Development

I am continuing to explore fire simulation technologies for interactive game development.

In addition to CFAST, I am working with another NIST fire simulation tool:

FDS (Fire Dynamics Simulator)

FDS uses computational fluid dynamics to calculate spatially detailed fire-driven flows.

The long-term development direction is to explore how these different simulation models can complement one another.

  • CFAST for compartment-level incremental simulation
  • FDS for detailed fire and smoke analysis
  • Unity for interactive gameplay and real-time visualization

The objective is not to replace every game effect with a scientific simulation.

Instead, I want to explore how scientific computing can contribute to new forms of interactive game environments.

This project is being developed as a game. It does not claim validated accuracy for real-world fire prediction or certified effectiveness as a professional firefighting training system.


References


About the Project

SOKYU: OPERATION RESCUE BLAZE SERIES

An independently developed firefighting and disaster response game combining:

  • Fire simulation
  • Unity game development
  • Real-time graphics
  • Embedded systems
  • Robotics
  • Artificial intelligence

Developed by Motomachi Digital Making Lab, Yokohama, Japan.

Technical Guide:

https://ronsard.sakura.ne.jp/sokyu/cfast-guide.html


CFAST × Unity Development Report #1

November 26, 2026

Top comments (0)