• Effect: Black Hole Background

Graphics and GPU Programming

For one of the upcoming projects (which will follow in some of the following posts), and as it had to fit the lore of the game, a black hole was necessary. Before going forward - let me add an image of what result I want to achieve:

Artist conception of black hole - NASA/JPL-Caltech

While the image is similar to the final effect I wanted to achieve, I did some changes on the effect to be more colorful and bright - but the original idea was from this image.

The effect is actually separated in 3 major parts - Disk, Streaks and Post processing.Of course there is also the core of the black hole (which is just a small sphere, with black color).

Disk

The disk around black hole is actually just matter that rotates around the core. Depending on the distance from the core the average density will increase near the event horizon and decrease further from it. Near the core the density can be so high that it may eventually have temperature close to star - therefore there might be high emissive energy - and therefore light.

Also, due to the time dilation (and therefore light having hard time escaping near the event horizon), the emissivity is getting lower very close near the event horizon. Anything beyond event horizon is invisible from the outside, because gravity there is so strong, not even photons can escape.

At least that is what I understand from the topic from physics point of view.

This actually explained what can be seen on the image and what is going on graphically, that is:

1. The disk rotates around the core
2. The density of disk decreases further from the core
3. The emissive light decreases further from the core, and therefore some (outer) parts of the disk will be lit by inner part ... although inner part around the core has to be somehow darker

Which can be solved with simple texturing and some basic lighting of the result. Using whirl-like texture as a basis proved to be a good start for me. I started off by creating a whirl-like texture that would define density in various parts of the disk, which resulted in this:

Generating a normal map for lighting from this is actually quite straight forward (and easy in Substance Designer F.e.) - and after short time, I also had a normal map:

Putting just these together with basic diffuse lighting (standard N.L) from the center (slightly above the plane) gives us some basic results:

Next thing is defining emissivity. This is done simply by using 1D gradient texture for which the coordinate will be distance from the center. The gradient I came up with is:

Notice the left part - which is near the event horizon.will give us similar feeling to the image as we're not jumping straight to bright value. Applying emissive value (as both - multiplier for the color, and as emission) gives us this look:

Which looks good enough already - I personally played a bit with values (mainly playing with contrast and other multiplication factors - F.e. for alpha channel/transparency), and ended up with this result:

Resulting pixel shader is as simple as:

fixed4 frag (v2f i) : SV_Target
{
// Calculate texture coordinate for gradient
float2 centric = i.uv * 2.0f - 1.0f;
float dist = min(sqrt(centric.x * centric.x + centric.y * centric.y), 1.0f);

// Light direction (hack - simulates light approx. in the middle, slightly pushed up)
float3 lightDir = normalize(float3(centric.x, -centric.y, -0.5f));

// Use normals from normal map
float3 normals = normalize(tex2D(_NormalsTex, i.uv).xyz * 2.0f - 1.0f);

// Simple N.L is enough for lighting
float bump = max(dot(-lightDir, normals), 0.0f);

// Alpha texture
float alpha = tex2D(_AlphaTex, i.uv).x;

// Mix colors (note. contrast increase required for both - lighting and alpha)
return fixed4((gradient * bump * bump * bump + gradient) * 0.75f, min(alpha * alpha * 6.0f, 1.0f));
}

Streaks

There are 2 streaks, directing upwards and downwards from the core. My intention was to make them bright compared to the core and blue-ish - to keep the background more colorful in the end.

Each streak is composed from 2 objects, a very bright white sphere (which will take advantage of used post processing effects to feel bright), and a geometry for the streaks (instead of using particles). The geometry is quite simple - looks a bit like rotated and cut hyperbole, notice the UV map on the left (it is important for understanding the next part):

This geometry is there 4 times for each direction of the streak, rotated around the origin by 90, 180 and 270 degrees.

The actual idea for streaks was simple - have a simple geometry of cut surface, and roll a texture over it. Multiplying with correct color and distance from the beginning of the streak adds color effect that nicely fades into the background. To create a particles-like texture that varies in intensity I used Substance Designer again and come up with:

By simply applying this texture as alpha, and moving the X-texture coordinate the streak is animated, like:

Multiplying by wanted color gives us:

And multiplying by factor given by distance from the origin of the streak results in:

Which is actually quite acceptable for me.

For the sake of completeness, here is the full pixel shader:

fixed4 frag (v2f i) : SV_Target
{
// Texture coordinates, offset based on external value (animates streaks)
float2 uv = i.uv.xy + float2(_Offset, 0.0f);

// Alpha texture for streaks
fixed alpha = tex2D(_AlphaTex, uv);

// Distance from origin factor (calculated from texture coordinates of streaks)
float factor = pow(1.0f - i.uv.x, 4.0f);

// Multiplication factor (to 'overbright' the effect - so that it 'blooms properly' when applying post-process)
float exposure = 6.0f;

// Apply resulting color
return fixed4(exposure * 51.0 / 255.0, exposure * 110.0 / 255.0, exposure * 150.0 / 255.0, alpha * factor);
}

Putting the effects together ends up in:

Post Processing

By using simple bloom effect, we can achieve the resulting final effect as shown in video, which improves this kind of effect a lot. I've added lens dirt texture to bloom. We need to be careful with the actual core - as that needs to stay black (I intentionally let it stay black even through the bloom). You can do this either by using floating-point render target before the bloom and write some low value instead of black (careful with tone mapping though - yet you might want to go even for negative numbers), or just render the core after the bloom effect.

The resulting effect looks like:

And as promised - a video showing the effect:

Report Article

User Feedback

Posted (edited)

Nice work. Looks great!

Edited by nihiven
typo

Share on other sites

Really nice work. Now I just want you to put the black sphere in (or make it bigger if that's already there?), the little black dot in the middle is heavily aliased and letting your effect down imo.

Share on other sites

Anyone who can create a three js demo for this ?

Share on other sites

@DerekB It is up technically up to think off something with 'event horizon', Physically taken, with the amount of debris you wouldn't most likely see anything (it would just be too small). Using perfect sphere with ray tracer could be a way around (as it's quite easy to do nice antialiasing on it).

@yueyang liu I could build you one with Unity almost instantly. If you really wish for ThreeJS one, if I'm able to find some spare time it may be possible

Create an account

Register a new account

• 0
• 0
• 1
• 1
• 3

• 12
• 9
• 17
• 16
• 9
• Similar Content

• By trapazza
I'm trying to add some details like grass, rocks, trees, etc. to my little procedurally-generated planet. The meshes for the terrain are created from a spherified cube which is split in chunks (chunked LOD).
To do this I've wrote a geometry shader that takes a mesh as input and uses its vertex positions as locations where the patches of grass will be placed (as textured quads).
For an infinite flat world (not spherical) I'd use the terrain mesh as input to the geometry shader, but I've found that this won't work well on a sphere, since the vertex density is not homogeneous across the surface.
So the main question would be: How to create a point cloud for each terrain chunk whose points were equally distributed across the chunk?
Note: I've seen some examples where these points are calculated from intersecting a massive rain of totally random perpendicular rays from above... but I found this solution overkill, to say the least.
Another related question would be: Is there something better/faster than the geometry shader approach, maybe using compute shaders and instancing?
• By FedGuard
Hello all,

I would like to start off with thanking you all for this community. Without fora like these to assist people the already hard journey to making an own game would be exponentially more difficult. Next I would like to apologize for the long post, in advance...
I am contemplating making a game. There, now that's out of the way, maybe some further details might be handy.
I am not some youngster (no offence) with dreams of breaking into the industry, I am 38, have a full-time job, a wife, kid and dog so I think I am not even considered indie? However I recently found myself with additional time on my hands and decided I would try my hand at making a game.Why? Well mostly because I would like to contribute something, also because I think I have a project worth making (and of course some extra income wouldn't hurt either to be honest). The first thing I realized was, I have absolutely no relevant skill or experience. Hmm; ok, never mind, we can overcome that, right?
I have spent a few months "researching",meaning looking at YouTube channels, reading articles and fora. Needless to say, I am more confused now than when I started. I also bought some courses (Blender, Unity, C#) and set out to make my ideas more concrete.
I quickly discovered, I am definitely not an artist... So I decided, though I do plan to continue learning the art side eventually, I would focus on the design and development phase first. The idea being, if it takes me a year or more solely learning stuff and taking courses without actually working on my game, I would become demoralized and the risk of quitting would increase.
So I thought I would:
1: Keep following the courses Unity and C# while starting on the actual game development as the courses and my knowledge progress.
2: Acquire some artwork to help me get a connection with the game and main character, and have something to helm keep me motivated. (I already did some contacting and realized this will not be cheap...). Also try to have the main character model so I can use it to start testing the initial character and game mechanics. For this I have my first concrete question. I already learned that outsourcing this will easily run up in the high hundreds or thousands of dollars... (lowest offer so far being 220 USD) I am therefore playing with the idea of purchasing https://assetstore.unity.com/packages/3d/animations/medieval-animations-mega-pack-12141 with the intention of then have an artist alter and/or add to the animations (it is for a Roman character so some shield animations are not going to work the same way.). This way I could start  with the basic character mechanics. Is this a good idea, waste of money,...? Any suggestions? I then have a related but separate question. Is it a good idea to buy Playmaker (or some other similar software I haven't yet heard of like RPGAIO), and using this for initial build, then changing/adding code as the need arises?
3.Get a playable initial level ready as a rough demo and then starting to look for artist for level design and character/prop creation.
...

I would really appreciate some input from more experienced people, and especially answers to my questions. Of course any advice is extremely welcome.
• By GameTop
Dirt Bike Extreme - another game made with Unity. Took about 2 months to complete.
Take part in extreme motorcycle races across the dangerous and challenging tracks. Dirt Bike Extreme is easy to pick up but hard to master. Race, jump and crash your way and other mad rivals through the amazing tracks as you master the skills and physics of motocross in this high-speed racing adventure. Conquer challenging routes on 23 different runs, discover new bikes and become the best of the best! Over 257K downloads already!
Windows Version:

Mac Version:
https://www.macstop.com/games/dirt-bike-extreme/

• Continuing to work on “Eldest Souls” (first article here!), I’ve begun familiarising myself with the workflow between Fmod and Unity, and the integration system. I know much of this will be pretty obvious to most, but I thought I’d share my thoughts as a complete beginner learning the ropes of sound designing.
The library of sounds that Fmod provides has been very useful, at least as reference points. I’ve still kept to my ethos of producing the sounds myself as much as possible. Having said that, Fmod gives you 50 free sounds with your download, and I’ve used a wooden crate smash, a drawbridge and electricity sound you can hear in the foley video below.

The thing i found most useful was witnessing changes i made in Fmod being realised instantly in Unity. If a volume needed changing, or the timing of one of my effects was off, i can literally switch to Fmod and then back to Unity and immediately see the result of my alterations. It also seems apparent that using middleware such as this (or i've heard Wwise is also equally intuitive) grants the developer, and myself included, a great deal more flexibility and opportunity to edit sounds without going all the way back to a DAW, and bouncing down again. Needless to say, my workflow is so much faster because of it.
I've also loved the randomised feature of Fmod, whereby any sound can be made to sound slightly different each time it is heard. Taking a footstep recording i made for example, I was able to add further authenticity of uneven footsteps by randomising the pitch and volume of each playback.

I used this technique when creating footsteps for the first major boss in the game called "The Guardian". A big, over-encumbered husk of a monster. I also had fun rummaging through the garage for old tools and metal components for the “Guardian” (the first boss) footsteps. See below!

I also created a sword attack for our player, trying to sound different from the generic “woosh” I see in so many video games. I used a very “sharp” and abrasive sound to differentiate him from any enemies.

On another note, I recently upgraded my microphone to a Rode NTG2 shotgun, which has been phenomenal. I haven’t had to worry about noise interfering with the clarity of my objects, whereas before with the sm58 I had to be clever with my EQ and noise reduction plugins.
Important to note again that this still a “cheap” mic in comparison to most other products on the market, and all in all my entire setup is still very simple and affordable which I’m quite proud of. I’ve seen many musicians spend heaps of money on gear they don’t necessarily need. I much prefer being resourceful with less equipment, than to have more than I can understand or remember how to use.
It’s forced me to understand every aspect and capability of my tools, which I believe is a principal that can be applied to any discipline.

I have more fun little sound effect videos on my Instagram for those interested, where I post regular updates. Thanks for reading! (if you’ve made it this far)

www.sergioronchetti.com
INSTAGRAM
fallenflagstudio.com

• BASICS IN SOUND DESIGNING FOR VIDEO GAMES

Recently I joined the talented team at Fallen Flag Studio as the composer for their latest release "Eldest Souls" which consequently lead me into a field I have always dreamt of trying - sound design!
Having no prior experience, I began watching a few online tutorials (if you want to learn from anyone make it Akash Thakkar from "Hyper Light Drifter"... what a guy!) and basically just testing stuff out i found around the house. Luckily my dad has a garage FULL of random crap to use.
Before i continue, it's important to note that i DO NOT have fancy equipment, meaning anyone can try this. (my equipment is an sm58, focusrite scarlett interface and Logic Pro X plugins... that's it!)
I started basic with some footsteps, which weren't all too difficult. Then I moved on to projectiles and a spear attack one of the bosses has. Below are a couple super short videos on my resulting attempts.

Amazing how great a banjo sounds for that typical "woosh" sound! And if you're wondering, the paper was added to give some texture to the jab.
I could be finding a lot of these sounds in libraries online (like the built-in ones that come with Fmod and Unity) but I've chosen not to, in order to produce authenticity and hopefully a more unique gameplay experience for players when the final product is put together.

P.S. if you'd like to try the game and hear my hard work we'll be at EGX and several other conventions later this year, soon to be announced! Thanks for reading!
www.sergioronchetti.com
fallenflagstudio.com

To those interested, there's an Alpha trailer of the game in question below.