Category Archives: gratuitous space battles

I was never 100% happy with the radiation effect in Gratuitous Space Battles 2, so I’ve coded a better version for the next patch. Here it is in very short silent video form:

I thought maybe some people may be interested theoretically in how it is done. Now I’m sure if this was in 3D in unity there is already a 99c plug-in that does it without you even having to understand coding, but thats not how its done so here we go…

The first thing to remember is that the spaceship is not a 3D mesh at all. its a series of sprites rendered to different render targets and then composited. That means that I’m not wrapping a texture around a mesh, but drawing one sprite on top of another, but cropping the final output to the alpha channel of the base (ship outline) sprite.

Before I learned much about shaders, I had a system that did this using mostly fixed function, which I use here, but build on with better shaders to do more stuff, making it a hybrid approach and fairly complex :D. To simply draw one sprite on top of another, but use the alpha channel from the bottom sprite, I use a custom vertex format that has 2 sets of texture co-ordinates. One set is from the splatted image ‘radiation’ and the other is from the alpha channel of the ship outline.

It gets a bit fiddly because where I’m drawing the splat sprite could be anywhere on the ship, so I need to work out the offset and dimensions of the splat in relation to the ship image, and store that in the second set of texture UVs, and pass that into a shader.

The shader then simply reads the color data and alpha data from the radiation splat, and multiplies the alpha by the alpha at that point on the base ship texture, and voila, the image is cropped to the ship.

But thats a very simplistic explanation because there is more going on. To make things fast, all of my radiation gets drawn together (to minimize texture / render target / state change hassle), so its done towards the end of processing. In other words, there is no painters-algorithm going on and I need to check my depth buffer against this ships Z value to see if the whole splat is obscured by some nearby asteroid or debris. That requires me passing in the screen dimensions to the shader, and also setting the depth buffer as a texture that the shader can read.

So that gets us a nicely Z-cropped image that wraps around the ship at any position. It also fades in and out so we need to pass in a diffuse color for the splat sprite and calculate that too. We also have to do all this twice, once for the splat, and once for the slightly brighter and more intense lightmap version, allowing the radiation effect to slightly light up areas of the ship hull during final composition.

At this point the shader is a bit complex…and there is more…

I wanted the radiation to ‘spread’, and to do that, I need to splat the whole thing at a fixed size, but gently reveal it expanding outwards. To do this I create yet another texture (the spread mask) which also gets passed to the shader. There were various ways to achieve this next bit, but what I did was to ‘lie’ to the shader about the current UV positions when sampling this spread mask. Basically I calculate and pass in a ‘progress’ value for the spread, and I use that, inverted, to deflate the UVs of the source image (which is CLAMPed). So effectively my first UVs are -4,-4,4,4 and the spread splat is a small circle in the center of the splat, expanding outwards to full size.

Because I’m only doing this when I sample the alpha channel from the spread mask, the color and alpha data from the base ‘splat’ texture remains where it is, so it looks like its a static image being revealed by an expanding circular (but gaussian blurred) mask.

I’m pretty pleased with it. The tough bit I’ll leave for you to work out is how that works when the source radiation image is actually a texture atlas of different radiation splats :D

Fun fun fun.



A long list of fixes, tweaks and improvements this time for Gratuitous Space Battles 2. Here is the full list:

Version Release 1.38 July
1) Fixed bug when toggling between fleets in a custom map, where the player fleets icons would not re-load.
2) Fixed bug where ship components that spun are were not composites ignored applied custom textures.
3) Fixed bug where textures may display wrongly in some cases on the ship design screen.
4) Fixed bug where green ship running light did not appear.
5) F2HullMod 8 can now be colored correctly.
6) Zyrtari ship components now ordered correctly.
7) Fixed bug where the game could crash if you beat the first campaign mission when trying to autoload the next one.
8) Point defense beams now oscillate wildly around missiles traveling too fast for them to intercept.
9) Weapons that deliberately do zero damage (like decoys) no longer qualify as least damage done in the post-battle stats.
10) Contrails now correctly drawn even on complex multi-layer fighter & gun ship designs.
11) Ship module comparison window now shows extra data for shield penetration vs resistance.
12) Point Defense weapons now display tracking speed.
13) Missile modules now display missile speed.
14) Balance Change: Frigate/Destroyer Anti-fighter missile Range boosted from 800 to 900.
15) Balance Change: Frigate/Destroyer Anti-fighter missile Damage effectiveness changed to 100% vs Hull, 25% vs Shield.
16) Balance Change: Frigate/Destroyer Anti-fighter missile Firing interval reduced from 2900 to 1500.
17) Fixed text spillover on the messages screen.
18) Added new feature: messages in your inbox now contain a button to jump to the challenge if appropriate.
19) Added new window that shows effectiveness of point defense weapons vs missiles when you select the tracking attribute for one.

The ones in bold are the ones I think really matter. These are things that make the user experience of the game so much smoother. Making comparisons between modules and selecting the right tool for the job just got a lot easier. Since this patch uploaded I’ve been working on a fairly ambitious change to the way shields are drawn, and it looks like it just cannot be done, but its helped me find and fix some other minor graphical glitches as I do it, so hopefully its not time wasted. I may do a long technical blog post about what I was attempting and why it didn’t work at some point.

In the meantime you can grab the game from the link below:


In other news Tim is still beavering away on the code for Big Pharma, you can read about the upcoming patch for the game which includes patents and custom games over at his blog here.


There are no comments yet

*note, only the windows patch is live at the moment, linux & mac updates are in progress.

I just released version .136 of Gratuitous Space Battles 2. The changelog is this…

Version Release 1.36 July
1) Fixed potential random crash when first starting a battle.
2) Balance Change: An across-the-board 30% boost in the hit-points of all frigate modules.
3) Balance Change: Double the damage of frigate anti-fighter missiles from 9 to 18.
4) Balance Change: 50% boost for the damage from a frigate flak cannon from 5 to 7.5.
5) Balance Change: 50% Boost for the beam power (time it can stay on) for both frigate tractor beam variants.
6) Balance Change: Increased the tractor beam recharge rates for frigates by 25%.
7) Balance Change: Increased the thrust of all frigate engines by 25%.
8) Balance Change: Increased the shield pen of Heavy beam laser for frigates to 15 so it can now do damage to all frigate shields but plasmatic, and also damage light cruiser shields.
9) Balance Change: Increased heavy frigate plasma shield penetration from 19 to 23 so it is also a viable option to damage cruisers with heavy shields.
10) Fixed campaign bug where you could re-deploy already deployed ships.
11) New Feature: You can assign custom textures to any part of a ship, even modded textures, and include them within challenges, using new right-click option.
12) Holding down shift now allows for pixel perfect ship design movement using the arrow keys.

But the most exciting bit is the new ‘custom textures’ feature. Its so exciting I made a video about it. I might one day write a play about it, or compose an opera. For now, here is the video:

There are no comments yet

We just rolled out a nice l33t update to Gratuitous Space Battles 2 that fixes a few things, tweaks a few things and also OMG adds a new campaign mode. It meant changing some menu stuff around, but its all explained below in this video. This MASSIVELY changes how you play (if you choose to play the campaign) because you have to be thinking several battles ahead, and suddenly ships are no longer expendable. I hope people like it, and I hope people realize how easy it is to mod (more on that later…)…

For those who have been on another planet…I should point out that Gratuitous Space Battles 2 is very much on sale now from us direct, and also from steam, from gog and the humble store. Go grab a copy and start blowing the galaxy to bits.

There are no comments yet

This is a good one…it introduces both custom ship battles / scenario designer, PLUS the option to turn off ship hull levels in the editor…which is cooler than you think… Here is the complete changelist:

Version Release 1.31 May
1) New custom battle feature, combined with scenario editor for custom challenges now added.
2) Game not longer checks for an achievement incorrectly if the player has not set up an online username.
3) Fixed lack of scrolling support on the mods browser.
4) Fixed crash bug when deleting installed mods.
5) Game no longer attempts to undo splitting a composite in the editor (which would crash…).
6) Fixed Graphical bug that drew large colored areas sometimes if limpets were launched but never drawn on screen.
7) Change to turret rendering to preserve detail colors.
8) Fixed crash bug in German Language version.
9) Removed that beeping sound nobody liked.
10) Added module data to design screen showing limpet weights and seek speeds.
11) Repair and refuel limpets now seek faster
12) Multi-point tractor beam now has less range and takes longer to recharge.
13) New option to disable Limpet GUI circles in battle.
14) Fixed bug when rotating a composite hull item then splitting or saving it.
15) You can now right-click a ship hull to hide it.

And here is a video with me explaining the best changes…

There are no comments yet