{"id":3359,"date":"2014-07-21T18:00:32","date_gmt":"2014-07-21T08:00:32","guid":{"rendered":"http:\/\/www.vectorstorm.org\/?p=3359"},"modified":"2014-07-21T18:03:53","modified_gmt":"2014-07-21T08:03:53","slug":"obscured-glow","status":"publish","type":"post","link":"https:\/\/www.vectorstorm.com.au\/2014\/07\/21\/obscured-glow\/","title":{"rendered":"Obscured glow"},"content":{"rendered":"

\"ObscuredGlow\"<\/a>Ever 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<\/em> — the obscured glow would “show through”, as seen on the left side of this image.<\/p>\n

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.
\n<\/p>\n

New in the latest version of the VectorStorm library<\/a>, 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.<\/p>\n

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.<\/p>\n

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.<\/p>\n

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).<\/p>\n

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<\/em> 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.<\/p>\n

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)<\/p>\n

\"TerrainGlowGrid\"<\/a> 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.<\/p>\n

So I’m extremely pleased to have this working! I’ve needed it for a very, very long time.<\/p>\n","protected":false},"excerpt":{"rendered":"

Ever 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…<\/p>\n","protected":false},"author":1,"featured_media":3360,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[4,3],"tags":[],"jetpack_featured_media_url":"https:\/\/www.vectorstorm.com.au\/wp-content\/uploads\/2014\/07\/ObscuredGlow.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/po9WK-Sb","_links":{"self":[{"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/posts\/3359"}],"collection":[{"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/comments?post=3359"}],"version-history":[{"count":9,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/posts\/3359\/revisions"}],"predecessor-version":[{"id":3370,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/posts\/3359\/revisions\/3370"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/media\/3360"}],"wp:attachment":[{"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/media?parent=3359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/categories?post=3359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vectorstorm.com.au\/wp-json\/wp\/v2\/tags?post=3359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}