Here's a better version of that if you want
(you're free to use it in any way you want as long as you don't say you made it and you promise to send me a box of bacon):
float4x4 worldViewProjection : WorldViewProjection;
float4x4 world : World;
float planetRadius;
float planetPenumbraRecip = 0.05f; // 1.0f / penumbra size
float3 atmoColour = { 1.0f, 0.0f, 0.0f };
float atmoRadius;
float atmoPenumbraRecip = 0.02f; // 1.0f / penumbra size
float3 lightToPlanet;
float lenLightToPlanet;
float3 lightPosition;
float3 lightColour;
float3 sceneAmbient = { 0.2, 0, 0 };
texture Texture0
<string resourceName = "";>;
sampler2D diffuseSampler = sampler_state
{
texture = <Texture0>;
mipFilter = linear; magFilter = linear; minFilter = linear;
addressU = clamp; addressV = clamp;
};
//---------------------------------------------------------
// Planet Rings - ( Shader 0 )
//
// Planet Rings.
//---------------------------------------------------------
void S0_VertexShader( float4 iPos : POSITION,
float2 iUV0 : TEXCOORD0,
float2 iNormal : NORMAL,
out float4 oPos : POSITION,
out float2 oUV0 : TEXCOORD0,
out float3 oWPos : TEXCOORD1,
out float3 oColour : COLOR )
{
oPos = mul( iPos, worldViewProjection );
oUV0 = iUV0;
oWPos = mul( iPos, world );
oColour = lightColour;
}
float4 S0_PixelShader( float2 iUV0 : TEXCOORD0,
float3 iWPos : TEXCOORD1,
float3 iVToP : COLOR ) : COLOR
{
float4 diffuseMap = tex2D( diffuseSampler, iUV0 );
float3 pxToLight = iWPos - lightPosition;
float lenPxToLight = length( pxToLight );
// Only check pen/umbra if this pixel is on the planet's far side
if ( lenPxToLight > lenLightToPlanet )
{
float lengthRatio = lenPxToLight / lenLightToPlanet;
float3 newPlanetPos = lightPosition + lightToPlanet * lengthRatio;
float3 newPlanetToPx = newPlanetPos - iWPos;
float lenNewPlanetToPx = length( newPlanetToPx );
float planetOver = saturate( ( planetRadius - lenNewPlanetToPx ) * planetPenumbraRecip );
diffuseMap.rgb *= lerp( 1.0f, 0.0f, planetOver );
}
return diffuseMap;
}
technique tech_Planet
{
pass p0
{
cullMode = none;
alphaBlendEnable = true;
alphaTestEnable = false;
srcBlend = srcAlpha;
destBlend = invSrcAlpha;
zWriteEnable = false;
vertexShader = compile vs_2_0 S0_VertexShader();
pixelShader = compile ps_2_0 S0_PixelShader();
}
}
float4 S0_1_PixelShader( float2 iUV0 : TEXCOORD0,
float3 iWPos : TEXCOORD1,
float3 iVToP : COLOR ) : COLOR
{
float4 diffuseMap = tex2D( diffuseSampler, iUV0 );
float3 pxToLight = iWPos - lightPosition;
float lenPxToLight = length( pxToLight );
// Only check pen/umbra if this pixel is on the planet's far side
if ( lenPxToLight > lenLightToPlanet )
{
float lengthRatio = lenPxToLight / lenLightToPlanet;
float3 newPlanetPos = lightPosition + lightToPlanet * lengthRatio;
float3 newPlanetToPx = newPlanetPos - iWPos;
float lenNewPlanetToPx = length( newPlanetToPx );
float planetOver = saturate( ( planetRadius - lenNewPlanetToPx ) * planetPenumbraRecip );
diffuseMap.rgb *= lerp( 1.0f, 0.0f, planetOver );
float atmoOver = saturate( ( atmoRadius - lenNewPlanetToPx ) * atmoPenumbraRecip );
diffuseMap.rgb *= lerp( 1.0f, atmoColour, atmoOver );
}
return diffuseMap;
}
technique tech_PlanetWithAtmo
{
pass p0
{
cullMode = none;
alphaBlendEnable = true;
alphaTestEnable = false;
srcBlend = srcAlpha;
destBlend = invSrcAlpha;
zWriteEnable = false;
vertexShader = compile vs_2_0 S0_VertexShader();
pixelShader = compile ps_2_0 S0_1_PixelShader();
}
}
It looks much better now, though if you linked to some bigger images that'd be more awesome :p.