Skip to content

Instantly share code, notes, and snippets.

@merpnderp
Last active December 14, 2015 08:49
Show Gist options
  • Save merpnderp/5060297 to your computer and use it in GitHub Desktop.
Save merpnderp/5060297 to your computer and use it in GitHub Desktop.
How to project spherical clipmaps onto a sphere and apply texture heightmaps.
  • Based on the distance between the camera and planet determine how many clipmaps will be created and at what detail level.

  • Get camera vector in planet's local space.

  • Find point planet where the line between the camera and planet's center intersects its surface.

  • Convert that point into phi and theta.

  • Based on phi and theta generate metatextures for each clipmap level.

    • The top level clipmap will simply be the coarsest texture, with a x axis twice as wide as the y. The x axis will be mapped from -PI to PI with 0 at the prime meridian. The y axis will be mapped from 0 to PI with 0 at the N. Pole.
    • Need a way to determine how wide the metatextures will be based on their theta. A texture at PI/2 theta will only need to be as wide and tall as the diameter of the circle. But if the circle's diameter encompasses a pole, it needs to be as wide as the top level texture.
  • Update the material for the circle.

  • On the GPU rotate the vertex to its correct phi and theta and displace it along its normals by the amount in the texture.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment