A study of Color, Fresnel Refraction Shaders, VFX Particle Swarms, and Shader Graph Distortion & Gamma Ray Burst Shaders in an unlit Space Environment.
There is a UI control system in play, controlling manual and auto indexing of the various galaxies Necesse Est is traveling through as well as the corresponding settings for the various visual effects. Volume control and time to next index event sliders are provided. It's P
to pause, ESC
to quit. Separate manual and auto simulation direction buttons complete the UI.
The Black Hole itself consists of the sphere, the upper and lower Plasma Ejecta
standard particle systems, and the upper and lower Gamma Ray Burst Shader objects. The entire assembly is rotating with the rotation speed exposed for designers to manipulate. Note the off-axis gamma rays. The lower one is slightly offset by offsetting the base texture image. More on this next panel:
...since the base texture is 2D, and this is 3D, we simply maintain orientation towards the camera as the parent sphere spins AND the camera orbits. This image capture was made at +22.5° inclination from the accretion disk. The UI Control image was captured at -22.5° and the Black Hole image is of course at 0° inclination. The camera itself orbits on a special axis all its own, which you can see in the code!
See CameraOrbitor.csA partial view of the VFX particle swarm system. The system induces the gaseous
effect of gas and dust being heated and gravitationally compressed into plasma. There are 200,000 active particles used to simulate a continuous stream of gas collapsing inwards towards the Black Hole. The second block in the image controls particle initialization properties: lifetime, random start position, etc.
This effect is a combination of the Shader Graph depicted above, a line renderer, and a Standard Particle System (the base). If you look at the center of the Shader Graph image, you can see the 2D texture that serves as the main node of the graph. Additional nodes, with input variables exposed, control the amount and characteristic of noise and color applied to the main texture. In this manner, the final output becomes the Gamma Ray emanating from the Black Hole.
No fewer than 22 stars orbit Necesse Est, each with a custom Star Shine Shader
applied to a material to simulate various common star sizes and colors. Each is moving on a Fixed Update loop in a circular or eliptical orbit, off axis to the accretion disk. The parameters of each star are exposed for the designer to manipulate. In the video, note the purposeful, periodic, orbit phase alignment.
Orbiting Gas Particle Swarm Control is achieved via a destroy/reinstantiation method for prefab swarm objects. Swarms are swapped out on each indexing event, with each new swarm's exposed parameters set by the designer, via the HSV color model (Hue, Saturation, and Brightness). Using the HSV color model also enables control of particle swarm emmisive intensity, contributing to the overall glow effect.
See GasPSOrbitor.csHandles particle updating and final rendering Output Particle Quad. Note the modular randomized inputs and HDR/HSV color inputs.
The Fresnel Shader causes a specular color to render on surfaces directly facing the camera, and another specular color to render on the surfaces that are perpendicular to the camera. In our case, the perpendicular part is the outline of the 3D sphere. Since we have exposed properties on various nodes in the shader graph, we can, using the HSV color model, vary both the color and intensity of the effect.
With each indexing event, a collection of data points needs to be synchronized to present a coordinated and correct rendering for each frame of the simulation. To achieve this we have a separate class (think SOLID - separation of concerns) that manages it all. In particular, Fresnel Power (emmissive light intensity), Fresnel Color, and overall simulation indexing are maintained.
See ObjectAccessor.csThe brightly lit inner portion of the accretion disk with tendril like arms inevitably drawing in gas, compressing it into plasma at the event horizon
, is a 2D twirled texture applied to a Particle System with separate minimum and maximum color gradients also applied. Each of the inidividual color gradient parameters are exposed for the designer to match the overall theme of the twirl to the current galaxy.
We have only scratched the surface of Shader Graph and VFX Graph. Below are some useful curated links to learn more about shader programming!
Intro To Shader GraphThe Distortion Shader has a 2D texture as the central node of the graph. Additionally, the material the Distortion Shader is applied to has the Render Queue set to Transparent-1. This coupled with noise applied at an exponential rate via Additive/Power nodes force the noisy transparent rendering. Additionally, the Rotation node is applied with exposed rate inputs, enabling a self-rotation
.
Enabling real time input for Shader Graphs is more than just exposing variables to the inspector. HLSL (High Level Shader Language) is the tool of choice for this. Similar to Nvidia's Cg, .hlsl files can be written directly in Unity just like a .cs file. Then import this code into a Custom Function node and write it up as you would any other node in Shader Graph. Below is an excellent tutorial for doing just that!
HLSL TutorialIn this Project, we explored Unity's Shader Graph and VFX Effect. There are a host of other shader languages and platforms to create shaders with. While debateable, the most useful tool for general shader authoring can be found at ShaderToy. It's full of tools and helpful advice! Be sure to have a look at Shader of the Day
and the many fine works others have shared.
The music track, titled Pheonix (Necesse Est)
was recorded and mastered by Javo Muñoz, a talented musician from Jalisco, MX. The track, and the Bip
sound, are routed through the simulation's mixer with only attentuation changes based on the volume slider input, thus it sounds just like it should! The Bip has had its pitch reduced.
So, the idea here is to simulate a large gravity well pulling in gas from the surrounding area and compressing it into an accretion disk. As the gas accelerates and compresses into plasma, it finally crosses the event horizon with a relatively small amount of energy expelled as gamma rays. The distorion shader overlaps the particle swarm just a bit to as to distort the backgorund skybox lighting in order to appear being sucked in and conglomerating into one of the 200,000 particles.
This project's primary purpose is to illustrate the low load the simulation would incur in a full blown game project. Turns out, Necesse Est runs at approximately 600 frames per second, leaving ample room for Quantum Runners Unsanctioned
where the tori are spaced in and around the accretion disk, or perhaps a derivation of Zero-G-Cats
coming to Steam ...soon.