**A hybrid approach for procedural planets**

**Part five - Airless rocks**

Airless rocks create an entirely different problem. The lack of an atmosphere means they get hit by space debris, and with no atmosphere to move the surface around the craters that form last a hell of a long time.

So we are going to have to come up with a new solution for this one, just playing with simplex noise on it's own won't handle it.

There is one structure that we can use though, cellular noise.

Copy Water.fx again and rename it Rock.fx, then insert this code after the simplex noise.

So we are going to have to come up with a new solution for this one, just playing with simplex noise on it's own won't handle it.

There is one structure that we can use though, cellular noise.

Copy Water.fx again and rename it Rock.fx, then insert this code after the simplex noise.

float4 gpuGetCell3D(int x, int y, int z) { float u = (x + y * 3) / 128.0; float v = (z - x * 31) / 128.0; float4 c1 =tex2D(ColorMapSampler, float2(u, v)); return c1; } float2 gpuCellNoise3D(float3 xyz) { int xi = int(floor(xyz.x)); int yi = int(floor(xyz.y)); int zi = int(floor(xyz.z)); float xf = xyz.x - float(xi); float yf = xyz.y - float(yi); float zf = xyz.z - float(zi); float dist1 = 9999999.0; float dist2 = 9999999.0; float3 cell; for (int z = -1; z <= 1; z++) { for (int y = -1; y <= 1; y++) { for (int x = -1; x <= 1; x++) { cell = gpuGetCell3D(xi + x, yi + y, zi + z).xyz; cell.x += (float(x) - xf); cell.y += (float(y) - yf); cell.z += (float(z) - zf); float dist = dot(cell, cell); if (dist < dist1) { dist2 = dist1; dist1 = dist; } else if (dist &t; dist2) { dist2 = dist; } } } } return float2(sqrt(dist1), sqrt(dist2)); }

Running this noise on it's own will produce a heightmap something like this.

These are our craters. On their own they don't really work though, we need to add in some more noise. So we will use simplex noise again and mix the two results.

Again, exactly how you do this is up to you, but my pixel shader looks like this.

Again, exactly how you do this is up to you, but my pixel shader looks like this.

PS_OUT PS_ColorMap(VS_OUT input) { PS_OUT output = (PS_OUT)0; float amp=2; float freq=1; float2 y=float2(0,0); for (int i=0; i<2; i++) { freq = (2*pow(2,i))-1; amp=pow(0.7,i); y+=gpuCellNoise3D(input.WP*freq).x*amp; } float h=snoise(input.WP*10); float3 dr = float3(h,h*4,h); h = snoise(input.WP*dr); y*=3; y+=(h+1)/3; y=(y/3); output.Color = float4(y.x,y.x,y.x,1); //texCol; return output; }

Play around with the bit of code that mixes the cell noise and the simplex noise, until

you get a result you are happy with. Of course you will need a grayscale texture as well,

it's in the zip if you don't have one.

Also enhance the bump mapping by making Nz smaller, in the demo I have used 50.

you get a result you are happy with. Of course you will need a grayscale texture as well,

it's in the zip if you don't have one.

Also enhance the bump mapping by making Nz smaller, in the demo I have used 50.

The last planet type I will be considering is molten planets.

In the next episode of course

In the next episode of course

part5.zip | |

File Size: | 49 kb |

File Type: | zip |