D2X-XL Worklog
Notes on features and problems from the development of D2X-XL, newest first.
Effects |
|
Transparency Transparent things - smoke, sprites, glass, shields, cloaked robots - have to be drawn from back to front to look right. D2X-XL does this by sorting them by their distance from the eye into a very large number of buckets, which are then drawn from the farthest to the nearest. To keep the number of draw calls down, the renderer collects things of the same kind into a batch for as long as it can. Something of another kind only forces the batch out when its area on the screen overlaps that of the batch: if they don't overlap, they cannot share a pixel, and the order between them doesn't matter. For 2.0 I also tried order independent transparency (WBOIT). It doesn't sort at all. All transparent pixels are simply added up, each with a weight that depends on its distance from the eye: the closer, the more it counts. From that sum the renderer computes an average color and blends it over the scene, depending on how much of the scene still shows through all the layers. The order doesn't matter anymore, but the result is an approximation: a weighted average instead of real layers on top of each other. I stayed with the buckets. The puffs smoke is made of all face the screen, so they are parallel to each other and never intersect. Sorting them gives the exact result, and there is no need for an approximation. Glow Things that are meant to glow are drawn a second time into a separate glow picture. This picture is blurred and added to the scene, and the sharp original goes on top of it, so a glowing object keeps its crisp shape inside a soft halo. Explosions, thruster flames, light trails, shields and lightning all get their glow this way. The usual way to get such an effect is bloom, which makes everything glow that is brighter than some threshold, with one blur for all of it. I tried it, and it couldn't replace the glow renderer. With glow, only what is deliberately drawn into the glow picture glows - a bright wall doesn't - and every kind of effect has its own blur width and brightness. Explosions The shock wave of an explosion is not drawn as an object at all. When the frame is finished, the picture is distorted around the explosion: the scene bulges outward in a ring that grows and fades. A wall standing in front of the explosion hides it. Mega Missiles and Earthshakers add a heat wave: an invisible shell of hot air that bends the picture behind it, most of all along its rim, where you look through the most of it. It shimmers, drifts upward and glows from a yellowish white to a dull red while it cools. These biggest blasts also switch on a strong light for a few seconds, and it is the only light of this kind that makes objects cast shadows. For a moment it wipes out all the other shadows around; then it fades, and the regular shadows come back. Shrapnel flies straight away from an explosion, every fragment with a red glowing head and a thin trail of smoke, and the parts of a destroyed robot spin away, trailing fire and smoke. Spawn Effect When a ship appeared in a level, D2X-XL used to show a blast sprite collapsing on it. The ship now appears inside a ball of plasma. The ball boils and glows while it grows, cooling down from white hot through yellow and orange to dark red, and finally fades away. Bolts of lightning with a red core and a yellow mantle shoot out of the ball and light up the surroundings, the ship grows to its full size inside it, and space around it warps. |
![]() |
|
Lightning A lightning bolt now has a sharp, bright core inside a soft halo. A strike ignites with a wide flash that contracts quickly, the bolts writhe in place, and they light up their surroundings. The Omega Cannon fires a thick trunk with a few thin, erratic arcs around it, and heavily damaged robots and ships have sparks running along the edges of their hull. Missile Smoke Trails A smoke trail is made of a lot of puffs, and in the beginning that is what it looked like: every puff was a sprite of its own that was blended over the scene, and you could make them out one by one. The way from there to soft smoke took a few steps. First the puffs got shading, then their edges were frayed with a noise pattern. The decisive step was not to draw them into the scene at all anymore. All puffs of a trail are now added up in a separate smoke picture, and that picture is shaded as a single body: the way the thickness of the smoke changes from pixel to pixel gives it a surface, the lamps around it give it light, thick smoke shades itself, and its dense core is darker. Only then the smoke is laid over the scene. A trail starts as a flame right behind the missile, with a white hot core and a narrow orange seam, before it turns into grey smoke; it fans out behind the missile, and air currents ruffle it sideways. Smoke is expensive, because close to you a few puffs cover a large part of the screen many times over. So it is rendered at half the resolution and put back into the picture exact to the pixel: where smoke meets the edge of something standing in front of it, the game compares depths and takes the smoke belonging to the right one, instead of smearing it over the edge. The puffs are drawn nearest first, and where the smoke has become opaque, those behind are skipped. And all of this only happens in the part of the screen the smoke actually covers. |
|
Fog, Water and Lava Technically, water, lava and fog are the same thing: segments filled with a medium. The outer faces of all connected segments holding the same medium form a closed hull. In every frame the game determines for each pixel where your line of sight enters such a hull and where it leaves it again, or where it hits something solid before that. What remains is exactly how much of the medium lies between your eye and the scene. The scene is then dimmed accordingly: the more medium, the less comes through, and the medium's own color is swallowed least, which gives the tint. The medium is not uniform anymore: fog shows slowly drifting wisps, water and lava show flowing streaks, each medium with a flow of its own. That makes them look more realistic than the uniform old fog effect. Fog is also lit. The light of the lamps in and around it is computed when the level loads, including light that is scattered in the fog several times, and lights that change are added while you play, so a shot lights up the fog it flies through. None of this is exotic; these are the building blocks volumetric fog is made of everywhere - industry standard. |
|
Energy Shields A shield is a sphere around a ship or a robot, and it now only shows when it is hit: every hit brings it back, and then it fades away again within a few seconds. How bright it gets tells you how much shield its owner has left. The shell is bright along its rim, where you look along its surface, and dark in its center, where you look straight through it, which makes it read as a bubble. A pattern of veins slowly moves over it, and the spot where a shot struck flares up. While it shows, the shield throws light of its own color on its surroundings. Player shields are blue, or white while the player is invulnerable; robot shields are red, except for the Guide Bot, whose shield is blue. |



