Loading course content...
Loading course content...
Computer memory doesn't have dimensions—it's a single long sequence of numbered storage slots, like a hallway with numbered doors. This creates a challenge for CS2's 3D voxel grid that uses coordinates like (5, 10, 3), because memory only understands one-dimensional door numbers. The solution is surprisingly elegant: the computer "flattens" the entire 3D grid into a simple one-dimensional list stored sequentially in memory, similar to how a book's text appears two-dimensional across pages but is really just a one-dimensional stream of characters flowing from first page to last. CS2's 20×20×20 grid containing 8,000 voxels becomes a list of 8,000 values stored consecutively: voxel 0, voxel 1, voxel 2, up to voxel 7,999, with each position storing whether that voxel contains smoke (1) or empty air (0). To bridge the gap between 3D coordinates and list positions, the computer uses a mathematical formula that instantly converts any coordinate into the correct list position using the pattern: position = x + (y × width) + (z × width × height). The logic organizes voxels like stacking layers of graph paper—the first layer (z=0) fills the list with 400 voxels (20×20), then the second layer adds another 400 right after, and so on. When checking voxel (5, 10, 3), the computer calculates: skip 3 complete layers (1,200 voxels), skip 10 rows in the current layer (200 voxels), then move 5 positions along the row, landing at position 1,405.
This storage approach makes voxel access instantaneous because checking any coordinate requires just one multiplication, one addition, and one direct memory lookup—operations completing in billionths of a second. When a bullet travels through smoke at coordinates (12, 8, 5), the game doesn't search through complex nested structures; it calculates the list position, jumps directly to that memory address, and reads the value. This efficiency enables CS2 to handle bullet interactions, grenade explosions, and spreading calculations across thousands of voxels every frame without lag.
The next critical question is why CS2 chose voxels the size of a player's head—an engineering decision balancing visual detail against game performance that we'll explore in the upcoming material.
You now understand that CS2's smoke system uses voxels—tiny invisible cubes forming a 3D grid where each cube stores whether it contains smoke or not. The next question is: how does the computer actually store and access thousands of these voxels efficiently during fast-paced gameplay?
Here's something that might surprise you: computer memory doesn't have dimensions. It's not organized into rows, columns, or layers like the 3D grid we've been imagining. Instead, memory is just one long sequence of storage slots, like a hallway with numbered doors stretching into the distance.
Each door has a unique number (called an address), and behind each door is space to store one piece of data. Door 0, door 1, door 2, and so on. When a game needs to store something—a player's health, an enemy's position, or a voxel's state—it puts that data behind one of these numbered doors.
This creates a problem for CS2's voxel grid. The grid exists in three dimensions with coordinates like (5, 10, 3) representing a voxel at position x=5, y=10, z=3. But memory only has one dimension: door numbers. The computer can't store data at position "(5, 10, 3)" because that's not a valid door number.
So how does CS2 bridge this gap between 3D coordinates and 1D memory addresses?
The solution is surprisingly straightforward: the computer takes the entire 3D voxel grid and "flattens" it into a simple one-dimensional list stored sequentially in memory.
Imagine you're reading a book. The text appears across pages in two dimensions—left to right, top to bottom across the page surface. But the book's actual content is really just a one-dimensional sequence of characters: letter after letter, word after word, flowing from the first page to the last. The 2D layout is just presentation; underneath it's a 1D stream.
CS2's voxel storage works the same way. A smoke grenade's 20×20×20 grid containing 8,000 voxels becomes a list of 8,000 values stored sequentially in memory: voxel 0, voxel 1, voxel 2... voxel 7,999. Each position in the list stores one simple value: is this voxel filled with smoke (1) or empty air (0)?
The first voxel goes behind memory door 1000 (arbitrary starting position), the second behind door 1001, the third behind door 1002, and so on until all 8,000 voxels are stored in consecutive memory locations.
But this creates a new question: if you want to check whether the voxel at coordinates (5, 10, 3) contains smoke, how does the computer know which door number in this long list corresponds to that 3D position?
The computer uses a mathematical formula to instantly convert any 3D coordinate into the correct position in the 1D list. You don't need to memorize this formula or do the math yourself—the computer handles this calculation automatically thousands of times per second. But understanding that such a formula exists helps explain how the system works.
The formula follows a simple pattern: start at the x position, then add offsets based on y and z coordinates to find the unique list position for that 3D location.
Here's the logic behind it:
Think of organizing the voxels like stacking layers of graph paper. The first layer (z=0) contains all voxels where the z-coordinate is 0. You fill this entire layer into the list first: all positions from x=0 to x=19 and y=0 to y=19. That's 400 voxels (20×20) stored sequentially.
Then comes the second layer (z=1), with another 400 voxels added to the list right after the first layer. Then the third layer, and so on. Within each layer, you move across each row (x direction) before moving to the next row (y direction).
To find voxel (5, 10, 3), the computer calculates: "I need to skip past 3 complete layers (that's 3×400 = 1,200 voxels), then skip 10 complete rows in the current layer (that's 10×20 = 200 voxels), then move 5 positions along the current row." The total position is 1,200 + 200 + 5 = 1,405. Voxel (5, 10, 3) is stored at position 1,405 in the list.
The formula the computer uses is: position = x + (y × width) + (z × width × height)
Again, you don't need to calculate this yourself. The key insight is that the computer can instantly convert any 3D coordinate into a specific list position using basic multiplication and addition—operations that processors execute in nanoseconds.
This storage approach explains why CS2 can handle bullet interactions, grenade explosions, and spreading calculations in real-time without lag.
When a bullet travels through smoke at coordinates (12, 8, 5), the game doesn't need to search through a complex nested structure or navigate through layers of organizational overhead. It simply calculates the list position using the formula, jumps directly to that memory address, and reads or modifies the value stored there. That's one multiplication, one addition, and one memory lookup—operations that complete in billionths of a second.
Compare this to how you might find a friend in a crowded stadium. If people were organized randomly, you'd have to check every section, every row, every seat. But if everyone had an assigned seat number calculated from their section and row, you could walk directly to the exact seat without searching. The mathematical formula acts like that seat number calculator.
This is why the game can clear voxels along a bullet's path, check vision-blocking for every player simultaneously, and run spreading calculations across thousands of voxels every frame. Each operation breaks down into simple coordinate-to-position calculations followed by direct memory access.
The voxel grid now exists as trackable, efficiently accessible data in memory. But knowing how data is stored doesn't explain what makes some voxels filled with smoke and others empty air. That's where we need to understand how smoke spreads through this grid after the grenade detonates.
You now understand that the 3D voxel grid is actually stored as a simple sequential list in computer memory, with a mathematical formula converting coordinates to positions. Next, we'll explore why CS2 chose voxels the size of a player's head—a critical engineering decision balancing detail against performance.