Dmitrii Nosov
1 min read

Categories

  • csharp
  • unity
  • astrus
  • astronomy
Table of contents:

Idea

I’m experimented a lot with asteroid style for Astrus. In one of these experiments i added trail to bodies. Trail turned out very bright, so i got an idea to make comets and meteors.

Graphics

Shader

There are 2 shaders: body and gas trail.

For body i used already written shader for stars. The most of the time, theese bodies will be very bright to see this shader. Shader is very simple - just a few animated layers of voronoi and gradient noise.

Trail shader is more interesting.

First, i stretch coordinates for noise and add time to X axis. image

Second, i create mask with trail-like shape image

And finally, combine noise and mask. Lerp between raw mask and mask with noise will increase trail density image

Other

Slightly volumetric 2D lighting and lens flare will accent brightness of theese objects.

Lens flare color does not modulate with 2D lighting. I wrote a simple script to support this.

[ExecuteAlways]
[RequireComponent(typeof(Light2D), typeof(Light), typeof(LensFlareComponentSRP))]
public class Light2DLensFlareColor : MonoBehaviour {
    private Light2D _light2D;
    private Light _light;
    private LensFlareComponentSRP _lensFlareComponentSrp;
    public float lensFlareStrength = 0.1f;

    private void Awake() {
        _light = GetComponent<Light>();
        _light2D = GetComponent<Light2D>();
        _lensFlareComponentSrp = GetComponent<LensFlareComponentSRP>();
        _light.enabled = false;
    }

    private void FixedUpdate() {
        _light.color = _light2D.color;
        _lensFlareComponentSrp.intensity = _light2D.intensity * lensFlareStrength;
    }
}

Movement

Comets have hightly eccentric elliptical orbits. My previous article is about them.

Gas trail (shader) are always turned away from star. Dust trail (particles) are slightly rotated.

When near star, comets heating up and start emitting trails. Ice and particles lits by sun, so the closer comet to star the brighter it will be. In reality, comets not THAT bright, but it’s looks cool.