Planetary atmosphere shader

It doesn’t work for me, it helps. the only thing I couldn’t copy was the first graph that is the output, I tried to alternate between translucent, deleted, opaque, but it didn’t work, besides not being able to leave the graph the same as his

I have ported over another shadertoy shader to ue4:
.shadertoy.com/view/XlXGzB

there are two custom nodes.
1.shader functions plugged in the ‘plug’ pin : see attahment
2.main shader function:

NUM_DENSITY_SAMPLES=8;
NUM_VIEW_SAMPLES=8;
INT_NUM_DENSITY_SAMPLES=8;
INT_NUM_VIEW_SAMPLES=8;
earthRadius = 6360.0;
atmoHeight =    60.0;
atmoRadius = earthRadius + atmoHeight;
earthCenter = float3(0.0, 0.0, 0.0);
sunIntensity = 100;

float4 col = inscatter(InCameraPosition, normalize(ScreenVector), View.AtmosphericFogSunDirection.xyz);

//col.xyz = pow(col.xyz, float3(1.0 / 2.2,1.0 / 2.2,1.0 / 2.2));
return col;

to use: apply the material to a 143.0143.0143.0 sphere.

Can you explain a bit more on how to use it? Do I use the .cpp-file? Why does it start with return 1;}? Where do I put it, and how do I reference it in blueprint? I see you say “the ‘plug’ pin”, but how do I instantiate/reference/find that asian thing?
Is the blueprint a Material, and what is the “Custom”-node? And what are the inputs/output type for the Custom-node?

Copying out the cpp file into a custom node on a material and the variables don’t seem to match your picture there.
There doesn’t seem to be any reference to the pin ‘plug’
Can you give a bit more direction on how this is setup?
Thanks!

If i copy the attached file into a custom node and connect it to that other custom node (main node, with that “plug” input), then i just get a lot errors, and it fails to compile.

Let’s revive this thread! :smiley:

First of all - Thank you so much @anonymous_user_54f049bb for sharing this magnificent shader! The moment I saw this, I kinda knew this will eventually get me where I wanted. I spend the last two days learning from and adding up to it.

There are probably a lot of people who search for this stuff and might be as disappointed as me - because as soon as it starts with lines of code I gotta bail out.

Second of all - if anyone needs a good tutorial on a decent planet shader - here it is: Planet Shader Tutorial by Brandon Gerzel
Thanks to the creator as well - it’s not perfect but you can also add up to it very easily once you’ve set it up and understood your parameters.
I added better masking, more parameters for control and a dark side & dawn color blend which gives me darker ground and red clouds on the edge of the eclipse. It can be very subtle but all the extra color gradients make a huge difference in realism!

Definitely look into this tutorial on how to put up a SunLocation_BP that interacts with your Planet Material. As you will see in the following screenshots, I changed JBaldwin’s material a bit. So, the SunLocation vector in a Material Parameter Collection is very important for that!

The SunLocation from JBaldwin’s material might be little weird. It basically worked in the Material Preview for me but not in Editor - as for most people, probably. I traded this part for my working dark side mask from the Planet shader and was about to try getting it back with another shader on another planet sized sphere. Notice that the Atmosphere mesh is 71.75% bigger than the Planet mesh. The results may very a lot from JBaldwin’s showcased results but it should work with just a second sphere mesh and the SunLocation_BP! And you can also fiddle with the parameters to make the atmosphere and the halo A LOT bigger. My settings aim for “artistic realism”.

I totally forgot to mention my Post Process settings! Was used to it so much already, that I forgot it plays a huge part in my final look. With the default PP in your scene, you should get a rather flat film camera look (before the post editing). Just find Contrast in the Global tab of your Post Process volume and crank up the Y value to max 2. That’s basically all I did. It gets you those very crisp spacey looking shadow edges. You aim for the complete opposite of a lush, hazy environment. No volumetric fog or anything that is tinting the air around the lens - because there is none!

Also on a short notice; I had very weird results with the PolarGlow. So you might want to leave it at zero.

If you haven’t already, go ahead and rebuild JBaldwin’s material from their screenshot - I basically did the same to start with. You can make out the bit that I replaced in the first screenshot. Also check for your Surface blend type to be Additive.

If you can’t find the blue node in the screenshots above framed in orange - it’s because you have to create it first. Create a new Material Function in your Material folder and drag it into your Material. Don’t worry about that green node yet - just put a Material Collection Parameter in there and set it later when you created the MPC.

Now, to make this work you’ll need to set up the SunLocation. Use the tutorial video above or the screenshots. I use a Directional SunLight at 2 Lux brightness in my scene to bump the Albedo and to have decent shadows interacting with the normals on the Planet sphere. Cloud shadows are Bump Offset (fake) - I personally like it, since you get a normal for the clouds which you can’t have with translucent or additive surface types.
Place the SunLocation_BP in your scene. The Material preview is useless at this point - give your MPC value any large vector other than 0,0,0 and you should regain a reliable result. (Forgot to put that in the screenshot)

And here is the new part! This kinda happened by accident, so this is the reason I wanted to share this and we might have a discussion on how to improve this even further.

I wanted to add back the cool effect when you look into the atmosphere from behind the planet against the sun - since I was trading the halo effect for reliable Sun direction. I added another sphere as big as the planet and made another Material.

Half way through this Material I just started to make wild connections on the Fresnel Normal pin. I tried a few direction inputs in combination with the SunDirection and suddenly I got this!
It’s also not the most perfect result, but it’s pretty close for the effort - I gotta say…

Let me share my Instance settings as well, so you get faster results. Most of the time it’s hard to guess the scale of all those numbers and you get almost irreversible results.

I hope this helps.
Cheers

3 Likes

Thank you so much for this. JBaldwin’s site is down leading to a godaddy domain purchasing page lol

I’ll follow the video and see what happens, did you also use JBaldwin’s nodes too or was the video enough?

No, I think the site was already down when I looked at it. I just rebuilt the nodes from Baldwin’s screenshot and tried some stuff. It was the perfect starting point to get an idea how this stuff works.