Sky Shader

I hate making skybox textures. That’s probably why GMod has been using HL2’s cloudy, stormy skyboxes since it was born. With the new flatgrass I decided to make a new skybox.

This works – but it’s not without its problems. The biggest problem is that the corners of the skybox are clearly visible when you spin around. You can tell the skybox is a skybox. That ain’t good.

So instead of making another texture I started to think.. this is just a simple gradient. I can do that in a shader. And make it configurable.

When I looked into it there’s some really complicated shaders around that simulate the atmosphere to give accurate looking sky. But I’m not patient or smart enough to do anything like that. So I decided it would be a good idea if I just kept it as simple as possible – that way it could be used for unrealistic alien skies and stuff too.

This is what I got.

In the screenshot above there’s two effects. First we have the sky colour gradient – which is deep blue to a light weak cyan colour. Then we have the horizon effect – which is orange/red. This effect hugs the horizon – but intensifies near the sun. You can see that effect on the screenshot below.. the horizon effect is stronger on the right.

In the screenshot above you can also see a star weak effect (you might need to open it in a tab and zoom in). The stars are just a texture you choose (any texture) – which gets scrolled across the sky. In flatgrass we use them for subtle clouds, like this.

But of course you can make the clouds look as awful as you want by controlling scale, fade and position.

Or change them to stars, and change the colour of the sky. This would obviously look a lot better if the map used night-time fog and lighting.

Or use clouds and colour to make it look stormy!

Here’s a video of the cloud movement:

The important thing to keep in mind with this stuff is that it’s all totally dynamic, on the fly. It’s all controlled using a material proxy. So even though by default there’s no transitions – a good gamemode coder could use this system to make a really nice day/night cycle, or a weather mod.

If you’re making a map and want to try it out – the entity is in the fgd in the next GMod Beta update – it’s called env_skypaint. I’m hoping to get an in-game tool to fiddle with the settings done.

2 thoughts on “Sky Shader

  1. Cool! How did you figure out the color weighting based upon the “sun” position? I’m having a major brain fart trying to write this myself.

    I’ve got the position of the sun and the gradient shader working fine (based upon the height but not the sun) but the shader is for the skybox and I’m not sure how to translate in the shader between the absolute distance between the sun and the skybox vertex/pixel versus a relative distance so that I can use that for the lerp weighting.

    Any advice? This should be super easy but I’ve been coding all day and my brain is like soup now.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s