Obscured glow

ObscuredGlowEver since VectorStorm started to support non-glowing objects (Game in a Week #3: Thunderstorm), there’s been a problem with how how it performed the glow effect. The problem occurred when you drew something that doesn’t glow over something that does — the obscured glow would “show through”, as seen on the left side of this image.

In every game I’ve made which used both glowing and non-glowing graphics, I’ve had to jump through hoops in order to avoid ever putting myself in the situation of drawing non-glowing geometry on top of glowing geometry, because doing so would expose this bug.

New in the latest version of the VectorStorm library, we now keep track of glowing objects in a separate color buffer. Previously, we just used a single color buffer for everything, and marked that buffer’s alpha channel for each pixel to denote whether or not it should glow.

The problem with using the alpha channel to specify whether a pixel should glow is that once it’s been set, it’s very difficult to unset. If you try to draw an alpha value of 0, OpenGL will typically interpret that as saying that the object is invisible, and so it won’t modify the data in the color buffer at all. This means that if I drew a glowing pixel, and then overwrote that pixel with a different color which wasn’t supposed to glow, the alpha channel would remain set in the ‘glow’ state, even though the glowing pixel wasn’t visible any more — the glow flag was still set for that pixel.

That’s why the glowing lines appear to glow through the HUD panel, in the left of the image above. The hud panel’s pixels are glowing exactly where there are glowing lines behind it. On the right side is the new method, where the glow is written to a separate color buffer. The object which draws in front can write over the glow color specified by the object in back, which stops this “glow bleed-through” problem that I’ve had for years.

This is a very important improvement for me. The last big UI feature I need to add to MMORPG Tycoon 2 is a floating window which will allow the user to display and edit certain parameters. This window will sit in front of any other UI elements (apart from the cursor).

The problem I had with this design — and the reason that it wasn’t included as part of the MS5 build — was that all the glowing HUD pieces would glow straight through this opaque window. These bright glows made the window contents very hard to read when it was placed over any of the HUD pieces (which is hard to avoid unless you’re playing on a large screen; MMORPG Tycoon 2 uses a lot of HUD real estate). With this change, that’s no longer a problem; the glow doesn’t show through the window any more, making window contents legible again.

There are more improvements, too. In order to draw an object which contained some glowing parts, I have to perform two draws. For example, a selected building has one draw call to draw the solid building, and another to draw its glowing outline. But now I can theoretically do both things in a single draw, since I can render colors into the glow buffer and non-glow buffer at the same time. And they don’t even have to be the same color — I could have white geometry which glows green, for example. That was never possible under the old system. (Note that the default shader still considers a single piece of geometry to either all-glow or all-not-glow, depending on its material settings, so actually doing this would involve writing a new shader to do it)

TerrainGlowGrid As an example, here’s a view of a simple MMORPG Tycoon 2 terrain, which is emitting a glowing blue grid from its surface, under the grass, all rendered as a single draw call.

So I’m extremely pleased to have this working! I’ve needed it for a very, very long time.