# Spherical procedural terrain shader based on slope

I've created a spherical terrain object out of 6 sphere projected (normalised) planes, each plane has been heightmapped post to being normalised. I'm looking to create a CG shader which will firstly calculate the slope of the heightmapped terrain, I understand this will need to look at the normals to calculate this can anyone elaborate on this for me? The next problem is that I want to do the slope calculations based upon the terrain "flat" rather than normalised.

Would it be best to either reverse the normalisation of the vertices during the slope calculations, or pre calculate and store the vertices slope data (on the flat plane) during the mesh generation?

This is an example of what I want to achieve with the shader: Any suggestions would be brilliant.

Thanks, C.

Update in response to opatut answer:

I've output the current slope data based of how I "think" was suggested and these were the results: I think my issue is that as each plane begins to curve that curve is includes as a slope which is the obvious thing to happen. I want to "flatten" out each of the 6 planes again for the slope calculations.

Why does it have to be 6 height-mapped planes? It would probably be a lot easier if you geometry-shaded a sphere and did all your calculations based on that sphere - you can easily compare the normal vector to the radius vector (basically the location of the vertex relative to the sphere center) to get your slope angle.

Also, I think it'd be easier to generate the heigh maps, or at least you could cubemap the sphere as well... Also, you will definitely get higher resolution heightmaps, since you don't have to use part of the value range (0..255) to achieve the sphere shape.

But if you just want to apply the slope-based texture effect, calculating them in the shader should be fine. You should have the exact (heightmap-transformed) vertex position in the shader, so you can just take that position, calculate the radius vector from that (i.e. just normalize the vertex position since your sphere center is 0,0,0) and calculate the angle to the normal vector. No need to transform the vertex position again.