Sharp Shaders


The Difference

September 10th September 20th

Go ahead, click both of those images so they show up full size. Don't worry, they'll pop up in new tabs.

Ten days ago, my game looked like the image on the left. Today, it looks like the image on the right.

Wow! Looks a lot better, doesn't it? But every graphical improvement has a price... So how much slower does the game run now?

Well, all of these graphical improvements come at the cost of a huge performance improvement.

Wait, what?


But first, the news.

Before we start, let's stop for a moment and talk about voxels, just so everyone's on the same page.

No 3D object in ScrumbleShip is textured.

ScrumbleShip renders its world using voxels, which are the 3D equivalent of your monitor's 2D pixels. In ScrumbleShip, these are shown as small, untextured cubes. We also have "blocks", which are collections of voxels 16 long, 16 thick, and 16 tall. So every block we put on the screen is composed of 16*16*16, or 4096 tiny cubes. This allows for some cool tricks, one of which we'll talk about today.

Now on to the improvements!


Order and Chaos. Well, ordering. Lots of ordering.

The most obvious improvement between the two images is the view distance, which has at least quadrupled. Hundreds of blocks that used to be rendered as featureless blanks suddenly pop into full view.

The big thing that allowed me to do this was changing the order in which I hand voxels to the graphics card. Nearly every opengl tutorial I've seen makes at least passing mention of drawing the scene from front to back, but I had always discarded this as a potential minor optimization - Nice for some day, but not really vital for now.

I was very, very wrong.

It turns out that modern graphics cards are remarkably efficient when scenes are drawn front-to-back. For the average ScrumbleShip scene, they're over ten times as efficient. So where we used to struggle along at 20-30fps with 100,000 voxels, now we can see a million voxels at 30-40fps.

End result? Wonderful scenes like these, rendered at playable speeds:

Expanded


VSync? More like VSunk.

When I originally re-ordered the voxels, I had some very interesting results. My render times instantly went "Non-linear". In other words, I could suddenly render 1 million voxels at the same frame rate as 100,000 voxels.... And that frame rate was 22 frames per second.

22FPS is... not awesome.

So what was going on? If I could render a million voxels slowly, why couldn't I render 100,000 voxels quickly?

The answer turned out to be in the vsync features of ScrumbleShip. Before the graphical update, more than 30fps was basically wasted effort, so I'd told one of our libraries to "sync" the image with every other frame your monitor displayed. Well, due to the particular sub-millisecond timings of these events, the best the engine could do was sync with a small handful of these events.

In short, turn off the vsync, and the framerate soars to 30-60fps.


Using a shader to shade things

Another large graphical improvement comes in the from of an absolutely tiny effect - I vary the color of each side of each voxel by 10%. This simulates some of the effects of diffuse lighting in the real world, and suddenly the 3D nature of objects "pops", and the tiny cubes actually look like tiny cubes.

Here's an example using some heavy damage on some factory blocks:

Voxel Damage Improved

I do use a little trickery here - I color the "top" of the voxel a little brighter than the "bottom". This poorly simulates the way light in space would work, but it correctly simulates our everyday experiences walking around with the sun overhead, so it ends up looking more natural to the human eye.

This process is done entirely in something called the "Fragment shader" of the graphics card. This fragment shader is designed to manipulate hundreds of megabytes of textures across the entire screen. Since ScrumbleShip doesn't deal with textures, we've been badly under-utilizing the fragment shader. It's basically like having Vincent Van Gogh paint your house.

Since this lightening/darkening process is done within an under-utilized portion of the graphics card, it cost us 0fps - A free improvement!


The wizard of LOD

Before EightCache EightCache

Another change I made is the introduction of a Level-Of-Detail system. Previously in ScrumbleShip, any individual block was either "High Resolution" (16x16x16 voxels), or "Block Resolution" (1 big voxel). This created a somewhat jarring effect when trying to look at things in the distance. Because, well, you couldn't.

The big breakthrough was when I realized that people couldn't really see 16x16x16 blocks in the distance. Stuff got all blurry and it looks more like a lower resolution block, like maybe 8x8x8... Hey. Why not average some of the voxels and *actually* display an 8x8x8 instead of the 16x16x16 block? And after that, maybe a 4x4x4 block!

You can see the results of this system in the link above. The two images contain the same blocks, but the one with level of detail is miles ahead of the one without. The level-of-detailed blocks just end up looking slightly blurry.


What's next?

Well, there are still optimizations to make, that's for sure. I doubt I'll find another 10x improvement... But then, if you'd told me I would find a 10x improvement two weeks ago, I would have laughed at you.

All these changes are in the latest "bleeding edge" release, and will be making their way into the full, released version in another week or two.

The most obvious improvement to make is to send less redundant data to the video card. Because of the amount and frequency of the voxel data we send, there's a tiny hiccup every 5 frames or so, causing that frame to show up on the screen for 1-2ms longer than it normally would. Not a huge difference, but it might be worth a few FPS to fix.

Other than that, I really think it's time to focus on features other than the graphics. With these changes, I've finally gotten the graphics to a point where they truly look and perform well. Maybe I should focus on combat? Atmospheric simulation? Ship stress simulation? Tell me your thoughts in the comments, please!


Curious about the game?
Get
Click here for demo and purchase info

Cheers,
-Dirk

zellman zellman's picture

Looks really great, Dirk, the slight change in color on each individual voxel really makes them pop. Even though, like you said, it is a little "cheaty" it ends up tricking my eyes into accepting it without question. Good work!

guestaccess guestaccess's picture

wow this is...epic! good job dirk! as for whats next..you decide!

Woodledude

Wow, the game looks so much better now! This has made me a happy man. :) As for what you could focus on next, I'd really like to see atmospheric simulation put in next, as weird as that sounds. It's something a lot of similar games put on the backburner, and it suits yours quite well. Not that weapons and flight aren't interesting or fancy, but they suddenly get a lot more interesting when there's atmosphere to take into consideration.

Feralcus Feralcus's picture

Holy wow....That's a damn big improvement! Great job!

As far as focus goes in all honesty I would say just start adding blocks, then hull stress.
Look at the developement cycle that minecraft went through; in the begining it ran like hell and had no real game mechanics and yet people swarmed to it. The ability to just make stuff attracted a great many.

Plus if you have the main block library built adding features and mechanics becomes much easier I would think.

After that I'd say hull stress, that way people have a guideline to build their hulls with and won't have to rebuild everytime an update comes out.
Perhaps atmospherics as well as they would have quite an effct on hull stability.

Oh and if bio ships could get a little love too I wouldn't complain. :)

guestaccess guestaccess's picture

sweeeeeet. i think some atmosphere and AI should be implemented but thats me oh and...Those voxels :D

tcc242

I suggest atmospherics as the next focus. It would make combat a lot more interesting when it gets added in as well. We need to take our space suits off, it's getting a little smelly inside them.

The Ensorceler

I don't particularly have a preference for what to do next, but if it is atmospheric simulation, actual characters should exist to interact with said atmosphere, and if stress modeling is done, could we have rotation? (No idea how hard that is though...)
All in all, this just blew my mind. Good job Dirkson!

insolent insolent's picture

As I said before, absolutely stunning job.

As for what to focus on next, here's my proposed development roadmap:

(1) I agree with those who have suggested atmospheric pressure. It's a unique feature that only one other 3D game I know of is planning to simulate, and it will add a "survival" element to the game.

(2) Atmosphere simulation would also, in my view, requires simulating tanks/holds, because you need somewhere to store the oxygen.

(3) Atmosphere simulation would also require electricity generation and storage simulation, because you need a way to cycle the air.

(4) That then leads to material scarcity, mining, refining, and component fabrication, because you can't just have an unlimited supply of air - it needs to be fabricated from... well, actually I hadn't given much thought to where you get air when your sole source of materials is asteroid ore! Perhaps there can be ice-teroids. ;) But I think materials extraction and fabrication should come third in line after atmosphere and power.

(5) IMHO, that then leads naturally to having character models as The Ensorceler suggested - a survival simulation would really benefit from having physical characters capable of taking various kinds of damage and interacting with other characters (e.g., pulling them to safety when they start drifting off into space).

(6) Having damageable character models that can interact with each other would then naturally flow into FPS combat with lasers and other weapons - possibly as a way to compete with other players over mining rights!

(7) FPS combat with weapons would naturally flow ship-to-ship combat, meaning ship flight and hull physics.

Just my two cents on an order I think might make sense. You could end up going a very different way which would work as well or better.

Feralcus Feralcus's picture

A "Quick Save" button would be awsome as well...

ArizonaDixon

mayhaps some improvements on the construction tools, i think you could probably hammer out some really usefully tools in a short amount of time to help us build the 1,2,10Km ships of our dreams.

Feralcus Feralcus's picture

Actually yeah, a symmetry tool would be great forever.

Oebele

I vote proper ship movement!
Rotation, acceleration, etc.

Wirenut

Damn Fine work Dirkson!

Mr. Eldritch

Proper ship movement, without a doubt. It is the single most basic, critical element that is missing from this game, and until you handle that, adding more of these features is like adding better bodywork and padded seats and a souped-up engine to a car with no wheels.

torus2112

Awesome update! The graphics are so much easier on the eye now, I feel like this adds a lot to the experience of playing the game. That's not to mention all the new things letting it run better, which is excellent.

As for how to move forward, it seems like people do want features that will firm up major aspects of ship design. As for the order those should go in, I suppose just for example ship stress could come before atmosphere because it's more fundamental to the design of a ship, and as Feralcus mentioned it would be easier to retrofit a ship to have life support than to change its structure. Likewise though different systems tie in to each other that make a difference how you plan them; just for example I think insolent mentioned that atmosphere itself would require tanks and power to figure out correctly.

I think if we figure out the best order to put out the basic features though, from propulsion to stress to internal systems, and maybe which ones should be developed alongside each other, it would make it easier on people who want to plan functional ships sooner. It would also help people get excited about the realism of the game, which is its main selling point and its main differentiating feature from similar games, by being able to show how they work and how you have to take them into account when you build.