August 23, 2013

Graphics 9-10: 60 shades

Evening, our loyal supporters, and other random passersby who happen to read this blog, if for no other reason that its choice of font is excellent.

While this period's plan was to get wet (insert Snoop Dogg reference here), shadows were deemed more important and pushed water back to next period. Grass, having already been taken care of at a satisfactory level, will drop off the plan, having been replaced by water.


Here you see the importance map with some more functions of importance: distance from the camera, surface normal, and the luminosity of the seen pixel.

Distance is obvious, close shadows need more resolution than far-away ones. The surface normal function boosts the importance if the surface happens to be facing the camera, as shadows on that are more visible than those on a wall at an angle. And finally, darker pixels need less shadow resolution than brighter ones.

Together, we have approximately 16 times better resolution than good-old-shadow maps.


Then, the work progressed towards soft shadows. You might chip your finger on those hard edges if you're not careful, is all.

Having checked the most often used books on your coder's bookshelf, the Necronomicon and the Book of the Law had nothing on soft shadows, which was greatly surprising. Thus we had to dig deeper, finding an antique copy of Gpu Pro 2 buried in a temple close by.

That book details an incantation of screen-space soft shadows, a scalable spell that produces nice-looking soft shadows from any shadow technique. It's far from a uniform blur; shadows are sharper close to the caster as they should be.


Unfortunately we're not immune to a characteristic of warping shadow techniques: the edges swim. What could be done to limit it has been done, but as shadow pixels vary in size and position, fully stable shadows aren't possible with warping techniques.

Luckily, it's not that noticeable with soft shadows and racing at speed. Still, it highlights how this is still an open problem.

The next bit is for artists.



Here we have the screen and shadow views of a fence. There's slight peter panning going on, but otherwise it's looking good. Artists could help the Pan problem by making the fence thicker.




Going forward next to the fence, we see the shadow suddenly disappear. What's that? A fence made of grass decided to rot and disintegrate in place? No, nothing of the sort, sadly. Not even termites.

In the shadow view we see the issue: uneven warping due to huge triangles. Sure enough, checking the wireframe view, the fence tris are rather big. Warping techniques are sensitive to huge triangles: they can cause artifacts like these. Subdividing the appropriate parts gets rid of that.


And finally, water was started on. We have nice glittering summer caustics here, visible at the pool's bottom. Hard to see in a still picture you say? Aye, it be so. Take a sip of your closest bottle of rum, and repeat enough times that the lights in the picture start to move to get a picture of how it looks like.

So, the remaining time shall be spent in all kinds of wetplay; hopefully 0.8.1 will be out soon, so we can begin integrating the graphics changes. Many of them need updates to tracks so that they can be fully realized, which would push a release back a century or so, give or take 99.8 years.

August 9, 2013

Graphics 7-8: gods in motion


Long time no ABC, Pöysti mah man.

What you see above is a sneak peek from the latest work of the Great Sitting Artist, samuncle. He's been getting intimate with the new lighting system, and it shows - can you see how much it blushes? It's adorable really.

Back to our regular scheduled program. The topics for the biweek were motion blur and god rays. Bugs were found, and according to the great principles of persistence hunting (a method used by no other animal than humans), were ran after until they collapsed to death from mere exhaustion.

While that certainly takes the fun out of seeing the bugs writhe in pain, at times you simply can't outrun them and need other measures.



The existing motion blur was a radial blur with protection for a certain area of the screen. It looked good enough, but was a bit slow, and the protection area was static.

Given the task here is eye candy, physical correctness be damned; one had to see how it would act when optimized and tweaked first. Before and after, with the protected area visualized in rogue red:



As you can see, the static area didn't cover the kart when speeding, resulting in blur being applied to it when it shouldn't have.

With that fixed, some optimization improved the motion blur's speed by 33%, and as it still looked good, that was that.



God rays, light shafts, or a strange sky hybrid of SSAO and radial blur, are this thing you see when your room has not seen a vacuum cleaner in a month and somebody opens the curtains.



Implemented according to the letter and spirit of the long-dead guru GPU Gems 3, may she rest in peace, we draw the sky and sun to a texture, trace the path to the sun, and sample along that path.

Hijacking on the occlusion query for the lens flare, we can determine the visibility of both effects with one stroke, as both are only visible when the sun is.



This section will be a bit more technical than usual; please bear with us.

Shadow maps, invented by Sir Williams the Fourth in 1887 or thereabouts, are a method not used by ancient Romans to fake shadows in a two-dimensional quantum display, otherwise known as a picture.




The problem of shadows, unlike that of light, is still unsolved, to the dismay of many. There is no known method to have beautiful shadows that scales well. Therefore we limit ourselves to only casting shadows from the sun; as a directional light, it's merely one render pass more, compared to six for a normal point light.

The above picture is an implementation of a basic shadow map. Far from a next gen darkness system, it produces 50 shades of Minecraft, as one can't simply get enough resolution for the whole visible camera range.

Clearly this is not adequate for us; for we are neither Minecraft nor fans of Twilight fanfiction. As it happens, the current state of the art in shades is rectilinear shadow mapping, made public a year ago by Paul Rosen.

Unlike some other publications of the same era, this technique can be fully implemented in GL 2.1+, without requiring any kind of GPGPU or even float textures, and it also runs faster than the previous state of the art solution, cascading shadow maps.


Rest assured no animals were harmed in the production of this picture; the lines are completely fake leather. What we have here is a packed depth image from above the Jungle level. The area highlighted in white is the back-projection of every visible pixel to this camera, allowing us to find a much smaller area to focus the shadow map on.


The importance map in closer view. In Rosen's algorithm, we determine an importance value for each pixel; in this image, every visible pixel is given an importance of 1, and invisible pixels 0.

What you see on the borders are visualizations of the two 1-dimensional importance maps generated from this image. For each horizontal and vertical line, we take the maximum value to the corresponding 1D importance map. This is done via a per-pixel loop in a fragment shader.


For each importance map, we then generate a warp map of the same dimensions. Red means shift this pixel back, black means stay put, and green is shift this pixel forward.

It's these two 1D warp maps that make the core of this technique. No shadow map area is wasted on pixels not visible (with the exception of those in the same row/column), and the important pixels are bigger than the less important ones. This means that the core area of a shadow might have less resolution than the shadow edges, giving the illusion of a much higher resolution shadow map.

For the exact format, it is a normal RG8 texture, and you can easily use RGBA8 instead with two bytes wasted. The negative range, -1 to 0, is stored in the red channel, and the corresponding positive range in the green channel.

This gives us 16 bits of precision for the warp map, which ought to be plenty.


Here's a warped image of the same Jungle level. As this image only uses the visibility importance, it is not that warped yet; only invisible pixels are removed from the shadow map.

Applying other forms of importance, we can decide that shadow edges need more resolution, or that pixels close to the viewer need more. This is a quite powerful technique using little power or VRAM; 1x512 RGBA textures take 2kb each.

This implementation is not yet complete, there are some remaining artifacts, and optimization & tuning has yet to be done. So expect more shadow work in the coming weeks.


Finishing this investigative report, we have a picture of an old classic game Slicks'n'slide. It's a top-down racing game with weapons, a favorite of mine.

Signing out,

Want to play online ?

Hi you,

After my last post which was very technical about the network, I wanted here to show you at what point is currently the online racing in your favorite open-source game ! So I've decided to make a short video for you to see that you can starting from now play online with other players, as long as you don't have high pings (<100ms).
I didn't know where was the server when I recorded the video but now I can tell, the server is in Paris, France, and my ping to the server is under 50ms. This is important because there is no lag compensation yet, but don't worry hiker is working on it :).
For instance, i played with Arthur who has a ping (from Norway) of 75ms to that server. Turned out that we felt the lag while playing essentially concerning picking powerups.

I won't make you wait, here's the video.

Do not hesitate to send your comments here or on youtube !
Cheers,
Robin 'hilnius' Nicollet

August 8, 2013

Random ramblings among riveting revisions

Greetings, SuperTuxKart-lovers (and occasional passers-by)! Your benevolent blabbering brat is back, to give some additional updates between all the honest, hard-working heroes writing here nowadays.

Zero point eight point one pontifications
I guess the first thing people are wondering is where did 0.8.1 go. The simple answer is that it's still not quite ready, for various reasons. One being that we didn't anticipate GSoC and all that would entail when giving our first tentative guesstimates, and the other being personal commitments taking up most of the rest of time the developers had. So where is it at right now?

Wiimote support is almost ready. However, the newer Wiimotes with built-in Motion Plus does not work so far, mostly due to lack of developer time. Bringing full support for Wiimotes might be pushed back so as to not stall the release even longer.
Soccer mode has been worked on by Yasin, who was one of the students we would have really liked to have but didn't have room for. Mad props to him for staying with us nonetheless and helping out even though he has various other things to deal with. Right now soccer mode has team support, with markers showing which karts are on which team, and will just need a few additions to be in a usable state. How fun it will be in the first release is left to see, but that will surely be refined later.
The tutorial and Easter egg mode are both pretty much finished, though for the latter there's an acute lack of tracks with eggs defined. 0.8.1 might just become a preview release for this feature, just like soccer mode.

STKSoC(sic)
Then there's the GSoC stuff. Yeah, that's not really exciting, so I guess you don't want to read about it.
Just kidding! Cease fire, please! We just had our mid-term evaluations, which means we evaluate whether the students have done what they've promised, and if not what can be done to repair it to get a passing grade. But due to the hard work of our three students there was no question at all that they would all pass with a spotless record. But don't take my word for it; just read the excellent blog posts they've written! Cand with his fancy-pants graphics (making an old-school grump like me wonder whether I should drool or say 'meh'. I kind of do both at the same time, though I'd never want to go back), hilnius with his back-packet trips back and forth the interconnections, and unitraxx with his... wait, where are his blog posts? Oh, there they are! Be sure to read his musings on being a Google Summer of Code student and how he's solved his tasks with dialogs and obligatory screenings. Congratulations to all of you, and keep up the good work!

Blondes on snowmobiles

What's this? Could it be... yes, it is indeed a new kart and a new character! She's Sara, incidentally also a princess and the mascot of OpenGameArt.org. Our resident 3D artist samuncle's first kart, it also features a unique jump animation, which will also be created for the other karts with time. See it in action here:



That's all the weather for now folks, and if I've forgotten something please remind me.

July 26, 2013

Graphics 5-6: Anti-this, pro-that

Good evening our loyal supporters. Welcome back to the same spiderchannel, at the same spidertime.

This biweek's plan was MLAA and SSAO. In addition, some remaining issues with lighting were squashed, and some unplanned effects were added, business as usual.



Selective bloom, requested by artists, was added. Now you can mark objects as causing bloom, even if their native brightness is not enough to catch them in the normal siphoning.


The test object in this picture is not the best one; you will likely see this effect used in the green crystals of the mine, and the windows of the mansion. The aforementioned windows may get something else too, but that's a secret, so don't tell anyone.

This is done by keeping a list of all such marked objects, and rendering that list with color and depth writes off, only writing the stencil. This results in 4x-8x drawing speed, as most graphics cards have that path optimized for uses such as Z-prepass.

This stencil is then used to copy the affected pixels from the picture to the bloom texture.

The bloom threshold was made configurable per-track. As you can see in the picture, the left version is clearly not bloom over-use.


The right is the default threshold, left was altered a bit to show how glorious a bit of bloom looks like.



Lightmaps were enabled in the new system. Before, after, the map.




This is a splash of older tech, and quite laborous for the artists too. However four tracks currently have it, so it should be used there.



MLAA, or Morphological Anti-Aliasing, is a shader-based AA technique. This means it can run in situations where traditional MSAA cannot, or catch edges such as those inside transparent textures better. It can usually reach better quality at the same speed; the quoted numbers for this particular technique are MSAA 8x quality at MSAA 2x speed, but the exact specifics obviously depend on the scene.

While no longer the state of the art, Jimenez's MLAA was used due to the author's familiarity with the technique, and the very decent results it still achieves. The most common competitor, FXAA, is a bit faster, but results in inferior quality - it blurs textures noticeably, which should not happen.


A short overview of the technique follows. First, any jagged edges are detected and marked for processing using the stencil. This greatly improves the performance of the technique, since the heavy shader for the following pass is only run on the needed pixels.

In the second pass, each edge is classified according to a pre-generated map of edges. This map tells the following pass where to fetch information from - essentially, which pixels to combine and the weights for them.

The final pass simply overlays the combined pixels on the picture. Before - after:




Dear reader, meet JJ.


Have no fear though, the glistering brightness that fills you with awe is a bit toned-up in this picture; sadly, the version to make it in the game will be more subtle. This comes as a disappointment to fans everywhere, and there have already been mass protests of over a thousand people outside my residence.



Levels can now choose to have cloud shadows. This completely fake system only fits some levels with a bright, daytime sky with clouds, but there are a few of such levels, and it improves them quite a bit.




It's a fairly subtle effect, and so hard to catch from a still picture, but when moving in the wind it's quite nice.

Itching to hear more I bet? This very fake effect is done inside the sun light, as that's the only thing that should be affected by it. A straight planar top-down mapping is created based on the pixel's world-space position; it's offset by the wind, and then used for a look-up in a specially made texture.

The effect is quite cheap. It does come with the downside that as currently there is no shadow mapping, the cloud shadows (just like sunlight) are visible inside buildings, caves and such. This may limit the levels where this can be used a bit for now, but with the overworld and hacienda, those areas are few and having it there is not distracting.



Finally, SSAO, or Screen-Space Ambient Occlusion.



"Mama, I want contact shadows and dark creases" "Sure thing, hon"

Another fake effect with no real-world equivalent, SSAO usually enhances scenes quite a bit. It approximates global light bouncing by making approximate ray traces around a pixel, checking if those points can possibly occlude some light from reaching this pixel.

Like you can probably imagine, it is expensive. Several tradeoffs were made in order to get it to run on the majority of the user base; it should still look acceptable, while the FPS hit is much less than the usual implementation.

Low - high:
The high variant merely runs at full resolution, and no tuning has been done for that one, as the majority will run on low or off.

The low option runs on a quarter resolution, taking only a single sample per step, without randomness, or an edge-aware blur.

Each of the listed parts lessen its quality somewhat, while increasing speed. First of all, the lower resolution prevents small creases from being detected, limiting the effect only to contact shadows. The upside is that it's 16 times less area, directly resulting in a 16x speedup over the high version.

Second, being able to only take a single sample per step, the information we have to work with is the normal plus a linearized, 8-bit depth. This results in some false occlusions in case the occluder is outside the hemisphere; the alternative however, making positions available, would double the cost of this effect.

The randomness in SSAO is usually implemented via a small normal texture. Its cost (beyond flicker that always results from randomness) is that it changes the step's texture read to a dependent one - named using great wit since the coordinates depend on another texture read.

A dependent texture read is a costly operation, since it prevents caches from pre-fetching the actual read. The exact cost cannot be calculated in a highly parallel pipelined system, but assuming it delays each read by 300 instructions (a typical cache miss), a core clock of 400MHz, and 16 steps, each pixel is delayed by about 12 microseconds. The delay is highly variable due to inter-dependencies, so take that cost estimation with a pinch of salt.

The first couple programmable desktop GPUs could only prefetch textures based on coordinates from a varying (that is, export from the vertex shader) or a hardcoded value. This is still the case for many mobile GPUs, but any desktop GPU from about 2004 onwards supports a set of math operations, such as additions and multiplication, making our set of vectors completely pre-fetchable. Should the target be a mobile GPU, this limitation could be circumvented by making the calculation of those vectors in the vertex shader and passing them as varyings.

As for using a normal gaussian blur over an edge-aware one, it results in some of the occlusions bleeding over a bit, but is about 4x the speed of the alternative. A 2x component comes from the fact that the edge-aware blur cannot take advantage of the bilinear hardware, requiring it to do twice as many samples, and the other 2x from requiring a branch for each sample.


With this, we end today's infotainment. Tune back next time!