Thursday, February 19, 2015

2.5D Sun


A friend of mine is working on a Rouge-like game, which was explained to me as a type of game where you die...  Or something.  Here's the link to his games blog so I don't butcher the explanation of it: http://theheavensgame.tumblr.com/ 

Anyway it's set in space so he needs some spacey effects and I thought it was a good opportunity to make a good looking sun.  Usually things like planets and stars have layers of volume materials which give them different looks depending on the viewing angle.  Think about how the edge of the earth looks due to the layers of ozone and atmosphere.  These are tricky and sometimes expensive to render because they have to work when viewed from every angle, but in this situation the sun only needs to be viewed from the front so I can set up a minimum number of layers depending on where I want to see certain visual elements.


The meat and potatoes is a squashed hemisphere to give the sun a little depth, There's an image of the sun I picked off of google with flow map that slowly distorts some fire textures.  There's also a look up texture that moves through the z component of the flow map. (flow in xy, height in z)  There is a ring around the edge to give it that ozoney Fresnel look.  There's also some wave textures and ray textures that scroll outwards from this ring.  The solar flares are 1 mesh with a bunch of outward pointing quads.  There is a vertex shader on them that pushes them on their tangent (outwards because the tops of the texture are out and the bottoms of the texture are in) and fades them in and out.  The flare vertex code looks like this:

fracTime = frac( _Time.y * yourSpeed ) ;
position.xyz += fracTime * v.tangent.xyz * yourDistance; //push the flares outwards
color.w = smoothstep( 0.0, 0.2, fracTime ) * smoothstep( 1.0, 0.5, fracTime ); // fade the flares in and out over the cycle

The whole thing is covered by a heat haze and glow which ties everything together nicely!

The final result looks like this: Sun Demo


1 comment:

  1. This looks really nice! I'm fairly new to Unity and haven't worked with shaders. Would it be possible to get the Sun Demo as a project download for inspection? Thanks for the article!

    ReplyDelete