Create Sun or Lava shader using Unity's shader graph

Hello everyone, welcome back.

Intro

Today we will going to look at how to create the amazing sun shader in unity using shader graph.
For this I am using Unity version 2022.3 but it will work on any Unity LTS versions. I have a project in URP.
Then I have the post processing volume with modules Bloom and Tone mapping with the mode Aces.



Effect break down

To achieve our desired effect we will do the following.
  1. We will take a 3D sphere.
  2. We will add some simple noise to it.
  3. We will add some color to make it look like hot burning lava.
  4. We will distort it with some UV displacement.
  5. We will pan our noise to make it look like it is flowing.
For the visual representation check out the following video.

Creating shader graph

Let's create a shader graph, right click > create > shader graph > URP > Lit shader graph.

Let's call it SunShaderGraph.

Then we will create a material for that so keep our shader selected, right click > create > material.

Call it SunMaterial, and assign it to the sphere.

In our shader graph, let's set our Base color to black, set Metallic and Smoothness values to 0, just to avoid any possible specular highlights or reflections.

Let's create a Simple noise node. We will control the scale from the inspector, so let's create a float property, call it NoiseScale, give default value of like 100, drag it in, and assign it to the Scale.

We will take its output and feed it into Power node, Power node performs the mathematical power operation, but in our case it will darken the values which are less than 1 as we increase the power.

We will control the power from the inspector, so let's create another float property, call it NoisePower, give default value of like 5, drag it in and feed it into the Power node.

Let's also create a color property, call it BaseColor, set the mode HDR, give default value of some red high intensity color, drag it in and we will multiply it with our Power node's output.

Then, let's take our Multiply node's output and feed it into our Emission block.



Now we want to distort our noise, for that let's create a Twirl node. Twirl node will displace our UVs in the spiral like effect.

The Center and Offset inputs are pretty self explanatory. The Strength input determines how strong our effect will be.

We will control the strength from the inspector so, you guessed it, let's create a float property, call it TwirlStrength, give default value of 10, drag it in and feed it into Strength.

To further distort our UVs randomly I will use the Center input.

Let's create another Simple noise node, and then I will feed it into the Center. Then we will control the scale from the inspector so let's create another float property, call it DistortionScale, give default value of 10, drag it in and feed it into the Scale.

Then, take our Twirl node's output and feed it into Simple noise node's UVs.



At this point we will achieve the Lava like effect. Now let's just pan our noise over time.

For that let's create a Time node, then take our Time and feed it into Multiply node.

To control the speed of our panning, let's create a Vector2 property, call it PanSpeed, give default value of 0.1, 0.1, drag it in and feed it into Multiply node.

Finally, take our Multiply node's output and feed it into our Twirl node's Offset input.

That's it save our shader. It will look something like this at the end.




Bonus Tip

We can use our material to act as a lava by simply adding it to the plane or quad.



That's it!
Trouble following along? Check out this Video!


Thank you so much for reading!

Comments