Included in this package is a demo scene which simply contains all the component you need to render your own volumetric galaxy.

The volumetric galaxy objects

Galaxies are simply spheres with the center of the galaxy in question centered in the position of the sphere. What matters here, really, is the material on the sphere. It doesn't need to be a sphere, it could be any mesh with more than 2 vertices, like a single triangle. The algorithm is agnostic about this, and merely uses the vertices to calculate rays in cast into the galaxy volume in run-time. However, please be aware that using a flat object will cause the galaxy to only be fully visible head on, and if you must do this, then at least use a quad which is big enough to accommodate the entire width/breadth of the galaxy plane.

The sphere used in the demo scene (and also in the prefab that is used there) is a conscious choice in order to visualize the physical extents of the galaxy in the simplest way possible.

Dual cameras

The camera setup in the demo scene is comprised of two separate cameras.

The first one in the render queue (child camera) renders only the galaxy object (as filtered by layer) to a target render texture.

The other, the main camera, has a script which picks this render target up and blits it on to the main camera's render surface at some given point of the render pipeline. This is done using Unity CommandBuffers, injected by the script in question. Change the point of the render pipeline to suit your needs.

Why the two cameras?

One of the prefabs found in use by the demo scene is the FullscreenTextureCamera which has a child object called RayMarcherCamera. These both are cameras. The main reason for this is in order to render the galaxy at a set resolution, as defined by the Resolution Tracker behavior of the child camera. This allows for the galaxy to render at a preset resolution or a resolution relative to the main camera resolution, and then be scaled up to full resolution as it is copied onto the main camera's render buffer. The idea is that fluffy things (like clouds, galaxies...) don't require the highest resolution in rendering to look good as it's mostly comprised of low frequency shifts in color and intensity. In fact, it sometimes looks better to scale it up rather than rendering at full resolution. A fortunate side effect of this, or course, is that it helps tremendously with performance to only render at a low resolution and then scaling up.

What if I don't want two cameras?

It need not be this way. You can do this either way suits you best. In the Demo scene, you will also find another prefab (disabled by default) called DirectRenderingCamera. This is a standard camera which simply includes the TransparentFX layer in which the volumetric galaxy resides. You can render the galaxy with any regular camera if you like, just make sure the galaxy object is in a layer visible to the camera. Please be aware, however, of the performance impact on high resolution displays. It can be much higher than you might expect.