Skip to main content
added 1066 characters in body
Source Link
opatut
  • 291
  • 1
  • 6

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.

Update due to more information from comment below:

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?

Depends on what you need the slope calculations for. If you require them for your simulation (e.g. driving physics), it won't help you if you have them in the shader only. Then you will need them in the program anyway, so you can implement your calculations once and store them in the vertex data - if the mesh does not get too high-resolution, it should be fine.

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.

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.

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.

Update due to more information from comment below:

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?

Depends on what you need the slope calculations for. If you require them for your simulation (e.g. driving physics), it won't help you if you have them in the shader only. Then you will need them in the program anyway, so you can implement your calculations once and store them in the vertex data - if the mesh does not get too high-resolution, it should be fine.

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.

Source Link
opatut
  • 291
  • 1
  • 6

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.