Procedural Skybox

From Shader Forge Wiki
Jump to: navigation, search
SkyboxThumb.png

In this article, I'll try to explain how I created this node tree.

My implementation is directed towards NPR but realism can easily be achieved by changing the node tree a bit.

This shader contains the following :

Controlled Day-Night cycle

"Ground" color

Horizon with intensity based on light direction

Sun disk with controllable size and sharpness

Gradient dithering with screen-space noise or UV/model space noise

Horizontal UV mapping for a star/space texture map


Before you can start designing your node tree, you'll have to change the inspector preview mode to "Sky" in your shader settings, the material can now be assigned as a skybox. You might want to change the light mode on the lighting tab to "Unlit/Custom", we don't really want the GI to affect the skybox. The shader is now correctly setup.


1. Normals Direction

The most usefull input on this specific tree are normals direction, getting that by using the "Normals" node wont give you anything usefull but thankfully the "World Pos." node does work and since the skybox is actually a sphere, taking the vertices position in world space and normalizing them means that we actually get the same thing as their normal direction.

2. Horizon

From that we'll find where to put the horizon simply by taking the green channel of n.1. The green channel tells us where the fragment is facing compared to up, this gives us a nice gradient from top at 1 to bottom at -1. The abs node is used here to mirror the gradient in the middle (-1 -> 1), one minus will invert the colors and then the "Power" node squeezes the gradient down.

3. UVs

We'll use the X and Z channel of n.1 to map the texture horizontally, this alone wont give us an acceptable result since the texture will be compressed/stretched across the curvature of the surface so we'll have to reduce that by offsetting the UVs more where it is compressed. The "Comp. Mask" G shows us exactly where compression/stretching happens, "One Minus", "Multiply" and "Add" relaxes the UVs. That last multiply node is used to constrain the stars on the upper side of our sky.

4. Base sky color

We take back the horizon gradient (Relay node in the corner) and plug it into the lerp node to create a gradient from the night color to a clearer nigth color(you can replace the power node with a custom color, it's just easier to manage like that by using only the alpha channel). We again use a Power node, putting it here before the Lerp looks a bit better when interpolating. Multiplying the night color with the stars and adding the result gives us slightly tinted stars which, to me, looks a lot better than just adding them directly to the sky. We'll then just lerp between day and night using the Cycle variable.

5. Ground

We use the top to bottom gradient to compress it a lot depending on the variable, multiplying by 0.5 offsets the gradient to recenter it after the division. We then lerp that with the sky and a ground color to create the ground.

6. Horizon color

This part take the base Light Color and saturate it more towards the end of the horizon gradient, this creates a fringe with more saturation to the gradient.

7. Sun shape

This one is pretty easy, it takes the sun direction, creates a gradient and scales it to create a disk.

8. Horizon intensity based on sun direction

We reuse the dot between light and normal direction, remap it between 0 and 1((1+NdotL)*0.5), create a second closer to the sun more intense layer with the pow node and add them together and then multiply this whole thing by n.2

9. Sun color

Same as n.6.

10. Everything

Adds the sun to the rest of the scene, it might be nicer to use an "add" between the sun color multiplied by the sun shape and the rest of the sky. The max node clamps back everything above 0, this is necessary since anything below 0 will change the GI to full-black.

11. Dithering

Creates a noise in screen-space or uses standard UVs and dither based on that. Smoother gradient but textures doesn't seem to like it that much, you might want to put the texture out of it.


--Eideren (talk) 08:05, 28 July 2015 (UTC)