Weekly Update: June 23, 2023

(This update contains some minor spoilers for an upcoming NPC feature)

This past week I’ve continued to work on some new mid-game content.

One of these required recreating a feature that existed in Starcom: Nexus, but I hadn’t yet implemented for Unknown Space: cloaked enemy ships. This turned out to be one of those features that sounded pretty straight forward having done it before, but had enough new corners to end up taking half the week.

I didn’t want ships to simply blink out, I wanted them to do some kind of transparency transition. This turned out to be a bit tricky: ship modules use custom shaders to support features like color swatches. Adding transparency to these shaders would be inefficient: if a pixel might be transparent, the GPU always has to worry about drawing what’s behind that pixel (overdraw). Since 99.9% of the time ship modules are opaque, that’s pretty wasteful. One option would be to create an alternate version of the shader just for cloaked ships, but that had some issues: for one, I already have two versions of the module shader, a standard one and one without emission. I’d need copies of both of those shaders with transparency, and keep those updated with any future changes. Another issue is that it wouldn’t work if ships had a component that wasn’t handled by the standard module shader.

Instead, my current solution is to have a cloak effect object that takes a snapshot of all the materials in the ship and adds a second “fade” material with transparency. Imagine a kind of paint that can transition from clear to black: put that on top of the ship’s normal module material. Have it transition to black, remove the underlying module material, then transition back to clear. This will let the transition work correctly regardless of the underlying material.

When the ship decloaks, it reverses the steps.

Some of the corner cases/questions encountered during implementation:

  • Implementation of cloaking exposed some issues in the visibility system, like being able to lock-on to ships that you can’t detect. Prior to cloak, it was basically impossible for a ship to be on screen and not detectable.
  • Needed an AI agent that made decisions appropriate to a cloaked vessel. E.g., after cloaking while falling back, it should sometimes change course so you couldn’t just follow where it last had been.
  • Various particle effects like engine thrust needed to be turned-off if the ship was cloaked.

It now is working to my satisfaction, and now I’m back to working on the content/story that required this feature.

Until next week!