• Register

Retro games on a procedurally generated icosphere, built in Unity. More details coming soon!

Here's a short article to show you how I added dynamic skybox tinting in Onasphere.

Posted by on

I wanted the skybox to reflect the planet but since they are random the skybox needed to be dynamic. This can be done by tinting the textures in the shader. The default Unity shader tints the entire texture but I wanted a bit more complexity. I accomplished this by splitting the texture into 3 parts, tinting each one separately, and then combining them all into the final texture.

Spacescape is a really cool program for generating space skyboxes. You can add layers for stars and nebulae and generate a 6-sided skybox for Unity. I made sure to colour each layer as red, green, or blue so that they could be split up properly in my shader.

Spacescape

This generates a pretty cool looking background but it's a little too realistic for the art style that Onasphere is using. I found a nifty tool online at DX Interative to generate a hexagonal mosaic.

Mosaic Tool


I combine all of the separate channels together with a custom tint value in the shader.

half4 skybox_frag (v2f i, sampler2D smp)
{
half3 tint1 = tex2D (smp, i.texcoord).r * _Tint1.rgb;
half3 tint2 = tex2D (smp, i.texcoord).g * _Tint2.rgb;
half3 tint3 = tex2D (smp, i.texcoord).b * _Tint3.rgb;
half4 result;
result.rgb = (tint1 + tint2 + tint3);
result.a = 1;
return result;
}

These tint values are set in my planet generating code.

RenderSettings.skybox.SetColor("_Tint1", color1);

The first tint is for the star colour, second is for the primary tint, and the third is for a complimentary colour tint. It gives me some nice results without needing any complicated skybox shaders.

Skybox Samples

Post comment Comments
SpaceMammoth
SpaceMammoth - - 64 comments

nice, this could be useful for me ...

Reply Good karma Bad karma+1 vote
Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: