I've decided to play around with converting one of my existing shaders to make clouds on the planets in my game.
Here's what I'm doing so far.
The cloud sphere is slightly larger than the planet, and I use
SET OBJECT TRANSPARENCY obj, 3
SET ALPHA MAPPING ON obj, 30
to make the object transparent enough to see the planet behind it.
I'm using 3 textures for the clouds sphere
Normal map
Color map (256x256 image all 1 solid color)
Alpha map (256 color greyscale image, no alpha channel)
Here is the shader as I have modified it so far,
//------------------------------------------------
// By Evolved
// http://www.vector3r.com/
// Modified by Revenant_Chaos
// Modified more by KISTech and Green Gandalf
// Adapted for Planet Clouds by KISTech
//--------------------------------
//-----------------
// un-tweaks
//-----------------
matrix WorldVP : WorldViewProjection;
matrix World : World;
matrix ViewInv : ViewInverse;
//-----------------
// tweaks
//-----------------
float4 Ambient = {0.01f, 0.01f, 0.01f, 1.0f};
float4 LightPosition = {0.0f, 0.0f, 0.0f, 1.0f};
float4 LightColor = {1.0f, 1.0f, 1.0f, 1.0f};
float LightRange = 500000.0f;
float U = 1.0f;
float V = 1.0f;
//-----------------
// Textures
//-----------------
texture BaseTX
<
string Name="";
>;
sampler2D Base = sampler_state
{
texture = <BaseTX>;
};
texture AlphaTX
<
string Name="";
>;
sampler2D Alpha = sampler_state
{
texture = <AlphaTX>;
};
texture NormalTX
<
string Name="";
>;
sampler2D Normal = sampler_state
{
texture = <NormalTX>;
};
//-----------------
// structs
//-----------------
struct input
{
float4 Pos:POSITION;
float2 UV:TEXCOORD;
float3 Normal:NORMAL;
float3 Tangent:TANGENT;
float3 Binormal:BINORMAL;
};
struct output
{
float4 OPos:POSITION;
float2 Tex:TEXCOORD0;
float3 LightVec:TEXCOORD1;
float3 Attenuation:TEXCOORD2;
float3 ViewVec:TEXCOORD3;
};
//-----------------
// vertex shader
//-----------------
output VS_L1(input IN)
{
output OUT;
OUT.OPos=mul(IN.Pos,WorldVP);
OUT.Tex=IN.UV*float2(U,V);
float3 WNor=mul(IN.Normal,World); WNor=normalize(WNor);
float3 Wtan=mul(IN.Tangent,World); Wtan=normalize(Wtan);
float3 Wbin=mul(IN.Binormal,World); Wbin=normalize(Wbin);
float3 WPos=mul(IN.Pos,World);
float3x3 TBN={Wtan,Wbin,WNor}; TBN=transpose(TBN);
float3 LightPos=LightPosition-WPos;
float3 ViewPos=ViewInv[3].xyz-WPos;
OUT.LightVec=mul(LightPos,TBN);
OUT.Attenuation=-LightPos/LightRange;
OUT.ViewVec=mul(ViewPos,TBN);
return OUT;
}
//-----------------
// pixel shader
//-----------------
float4 PS_L1(output IN) : COLOR
{
float4 BaseColor=tex2D(Base,IN.Tex);
float4 AlphaMap=tex2D(Alpha,IN.Tex);
float3 NormalMap=tex2D(Normal,IN.Tex)*2-1;
NormalMap=normalize(NormalMap);
float3 LightV=normalize(IN.LightVec);
float3 View=normalize(IN.ViewVec);
float Normal=saturate(dot(NormalMap,LightV));
float4 Light=LightColor;
float4 AlphaBlend=(BaseColor*AlphaMap);
return AlphaBlend*((Normal*Light)+Ambient);
}
//-----------------
// techniques
//-----------------
technique CloudShader
{
pass p1
{
vertexShader = compile vs_2_0 VS_L1();
pixelShader = compile ps_2_0 PS_L1();
}
}
The resulting clouds are "ok" but I'm not happy with the edges of the clouds. They are to dark, and make the clouds look like things used to in movies where they used Blue Screen effects. (you know, where you could see a little bit of blue around the actors..)
Here's a piece of a screenshot to show what I mean.
Any idea how I can make the clouds all white to help reduce that nasty looking edge?
I tried making the alpha map black and white instead of greyscale, but that didn't help either.