A hybrid approach for procedural planets
Part six - Molten planets
When I generate solar systems, I often come across planets which do not fit conventional classes. They are simply too extreme.
When things like this occur, I always go back to the bible, Starflight. Starflight had molten planets, and even though we don't currently have any proof that they exist, it will do for me.
Molten planets bring up a new set of problems. We need something like this in our universe, but what are they like? We just don't know.
So this is a guess, it's one that looks quite nice, and has potential when we get down in the dirt of the planets, but I am still not happy with it.
Misgivings aside, lets get on with it.
As usual create a new class Molten and copy the code from WaterPlanet. We are going to use the same terrain generation shader as the water planets for this one, so that is already done. However we are going to need a new display shader so copy ColorMap.fx and name it molten.fx.
Add a new texture sampler Lava and change the pixel shader to this.
When things like this occur, I always go back to the bible, Starflight. Starflight had molten planets, and even though we don't currently have any proof that they exist, it will do for me.
Molten planets bring up a new set of problems. We need something like this in our universe, but what are they like? We just don't know.
So this is a guess, it's one that looks quite nice, and has potential when we get down in the dirt of the planets, but I am still not happy with it.
Misgivings aside, lets get on with it.
As usual create a new class Molten and copy the code from WaterPlanet. We are going to use the same terrain generation shader as the water planets for this one, so that is already done. However we are going to need a new display shader so copy ColorMap.fx and name it molten.fx.
Add a new texture sampler Lava and change the pixel shader to this.
float4 PS_Molten(VS_OUT input):Color { float4 output; float4 texCol; float3 Normal = (2 * (tex2D(BumpMapSampler,input.TexCoord))) - 1.0; float3 LightDir = normalize(input.Light); float Diffuse = saturate(dot(LightDir,Normal)); float4 height = tex2D(ColorMapSampler,input.TexCoord); if (height.x==0) { texCol = tex2D(LavaSampler,input.TexCoord); Diffuse*=2; }else{ texCol = tex2D(PallSampler,float2(0,height.x)); } texCol *= Diffuse; output = AmbientColor + texCol; return output; }
The idea is simple, where we had water on the water planet, we now have molten lava. So the pixel shader uses an extra texture
We are going to have to supply the texture, so add a new public Texture2D to the planet base class and alter the draw routine to this.
We are going to have to supply the texture, so add a new public Texture2D to the planet base class and alter the draw routine to this.
public void Draw(Matrix View, Matrix World, Matrix Projection) { Matrix wvp = World * View * Projection; draw.Parameters["wvp"].SetValue(wvp); draw.Parameters["Palette"].SetValue(Palette); draw.Parameters["ColorMap"].SetValue(Mercator); draw.Parameters["BumpMap"].SetValue(normalmap); draw.Parameters["world"].SetValue(World); if (draw.Parameters["Lava"]!=null) draw.Parameters["Lava"].SetValue(lava); for (int pass = 0; pass < draw.CurrentTechnique.Passes.Count; pass++) { for (int msh = 0; msh < Game1.sphere.Meshes.Count; msh++) { ModelMesh mesh = Game1.sphere.Meshes[msh]; for (int prt = 0; prt < mesh.MeshParts.Count; prt++) mesh.MeshParts[prt].Effect = draw; mesh.Draw(); } } }
All this does is set up the texture if required.
So we need two textures, one to do the conversion from height to colour, and one for the
lava. For the lava I used a noise function and coloured it with a flame palette.
So we need two textures, one to do the conversion from height to colour, and one for the
lava. For the lava I used a noise function and coloured it with a flame palette.
For the height map I used black to grey.
Dropping this into the code with a Nz of 90 gives a pretty nice result.
You may want to animate the lava texture, that's up to you. I prefer it like this.
Since this is the last planet type I will be considering, I have added some code to the
demo so you can play with various parameters.
Using the game pad dpad, up and down change the seed.
Left and right change the type of the planet.
And xOvercast is on the right thumb stick.
I have also done a bit of cleaning, so delete the old version and replace it with this
when you are ready.
Next a few improvements and bug fixes.
Since this is the last planet type I will be considering, I have added some code to the
demo so you can play with various parameters.
Using the game pad dpad, up and down change the seed.
Left and right change the type of the planet.
And xOvercast is on the right thumb stick.
I have also done a bit of cleaning, so delete the old version and replace it with this
when you are ready.
Next a few improvements and bug fixes.
part6.zip | |
File Size: | 102 kb |
File Type: | zip |