Is there any free shader to make planets look more real?
Kind regards
Is there any free shader to make planets look more real?
Kind regards
Here’s the code for a planet shader for Unity : Entity Crisis: Unity3D 3.0 Planet Shader
There are others out there, as can be seen in this Google search: site:unity3d.com planet shader - Google Search
Hi,
what’s missing in all These examples are outer glow / shine effects.
Is there any way to achieve this?
Thx for replying!
Currently I’m using this shader here (first on page):
http://wiki.unity3d.com/index.php?title=Planet
If I rotate the camera around a planet it really looks great, but if I rotate the planet, the outer glow transforms into something really really terrible.
It’s more like an outline, will post screenshots asap.
Anyone has an idea why?
Okay here are the screenshots:
This is how it should look like (with an outer glow where the light is incoming)
It works fine if I rotate the camera around that object!
This is how it looks like if I rotate the object (not the camera)
Another problem is if I have more objects that overlay (it looks like the more distant one is not beeing rendered)
To sum up again:
I wanted to achieve a planet look-alike effect with outerglow.
It works fine if the local euler angles of the object is 0/0/0 but not if they are changed…
Here is the shader-code I use:
Shader "SlinDev/Planet"
{
Properties
{
_MainTex("Texture (RGB)", 2D) = "black" {}
_Color("Color", Color) = (0, 0, 0, 1)
_AtmoColor("Atmosphere Color", Color) = (0.5, 0.5, 1.0, 1)
_Size("Size", Float) = 0.1
_Falloff("Falloff", Float) = 5
_FalloffPlanet("Falloff Planet", Float) = 5
_Transparency("Transparency", Float) = 15
_TransparencyPlanet("Transparency Planet", Float) = 1
}
SubShader
{
Pass
{
Name "PlanetBase"
Tags {"LightMode" = "Always"}
Cull Back
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_fog_exp2
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform float4 _MainTex_ST;
uniform float4 _Color;
uniform float4 _AtmoColor;
uniform float _FalloffPlanet;
uniform float _TransparencyPlanet;
struct v2f
{
float4 pos : SV_POSITION;
float3 normal : TEXCOORD0;
float3 worldvertpos : TEXCOORD1;
float2 texcoord : TEXCOORD2;
};
v2f vert(appdata_base v)
{
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.normal = v.normal;
o.worldvertpos = mul(_Object2World, v.vertex).xyz;
o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
float4 frag(v2f i) : COLOR
{
i.normal = normalize(i.normal);
float3 viewdir = normalize(_WorldSpaceCameraPos-i.worldvertpos);
float4 atmo = _AtmoColor;
atmo.a = pow(1.0-saturate(dot(viewdir, i.normal)), _FalloffPlanet);
atmo.a *= _TransparencyPlanet*_Color;
float4 color = tex2D(_MainTex, i.texcoord)*_Color;
color.rgb = lerp(color.rgb, atmo.rgb, atmo.a);
return color*dot(normalize(i.worldvertpos-_WorldSpaceLightPos0), i.normal);
}
ENDCG
}
Pass
{
Name "AtmosphereBase"
Tags {"LightMode" = "Always"}
Cull Front
Blend SrcAlpha One
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_fog_exp2
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
uniform float4 _Color;
uniform float4 _AtmoColor;
uniform float _Size;
uniform float _Falloff;
uniform float _Transparency;
struct v2f
{
float4 pos : SV_POSITION;
float3 normal : TEXCOORD0;
float3 worldvertpos : TEXCOORD1;
};
v2f vert(appdata_base v)
{
v2f o;
v.vertex.xyz += v.normal*_Size;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.normal = v.normal;
o.worldvertpos = mul(_Object2World, v.vertex);
return o;
}
float4 frag(v2f i) : COLOR
{
i.normal = normalize(i.normal);
float3 viewdir = normalize(i.worldvertpos-_WorldSpaceCameraPos);
float4 color = _AtmoColor;
color.a = pow(saturate(dot(viewdir, i.normal)), _Falloff);
color.a *= _Transparency*_Color*dot(normalize(i.worldvertpos-_WorldSpaceLightPos0), i.normal);
return color;
}
ENDCG
}
}
FallBack "Diffuse"
}
Thx in advance!
This is probably an old thread, but here’s my two cents:
For rotation, you could use a texture offset, and for those planets using heightmaps, you could then offset the heightmap too, so the planet looks right. this won’t work right for fixed geometry however, as the baked heightmap would be disjointed for obvious reasons… ![]()
as for the weird drawing issues with objects in front of each other, it looks like the Z-Buffer isn’t properly done in the shader. I also noticed how the culling has a back and front side in each pass, so this could be the issue. (I am assuming the glow around the object is done with a mesh extrusion that goes out of place when you rotate it, so this could potentially be un-fixable due to this…)
a slightly older thread, but in case anyone would be interested I made a corrected version for unity 5
it’s a 2 pass vertex+surface shader

Shader "Custom/Planet" {
Properties {
_MainTex("Texture (RGB)", 2D) = "black" {}
_Color("Color", Color) = (0, 0, 0, 1)
_AtmoColor("Atmosphere Color", Color) = (0.5, 0.5, 1.0, 1)
_Size("Atmosphere Size", Range(0, 5)) = 0.12
_Falloff("Falloff", Float) = 2
_Transparency("Transparency", Float) = 1
}
SubShader {
Pass {
Name "AtmosphereBase"
Tags { "Queue" = "Transparent" "IgnoreProjector"="True" "RenderType" = "Transparent" }
Cull Back
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform float4 _Color;
uniform float4 _AtmoColor;
uniform float _Size;
uniform float _Falloff;
uniform float _Transparency;
struct v2f {
float4 pos : SV_POSITION;
float3 normal : TEXCOORD0;
float2 atmofalloff : TEXCOORD1;
};
v2f vert(appdata_base v) {
v2f o;
v.vertex.xyz += v.normal * _Size;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.normal = v.normal;
float3 viewDir = normalize(ObjSpaceViewDir(v.vertex));
o.atmofalloff = float2( pow(saturate(dot(viewDir, v.normal)), _Falloff), 0.5);
return o;
}
float4 frag(v2f i) : COLOR {
i.normal = normalize(i.normal);
float4 color = _AtmoColor;
color.a = i.atmofalloff.x * _Transparency * _Color;
return color;
}
ENDCG
}
// *** surface shader to render the planet itself ***
Name "PlanetBase"
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Lambert
#pragma target 3.0
uniform sampler2D _MainTex;
uniform float4 _Color;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
// *** surface shader end ***
}
FallBack "Diffuse"
}
I know this thread is old af, but this is the perfect shader I 've been searching for, any idea why it only shows in the editor?