There is an fantastic answer by DMGregory here where he explains how to calculate and generate the vertices of an UV Sphere: OpenGL calculate UV sphere vertices

Based on his code, how can we change the "altitude" of each individual vertex?

To create something like this:

enter image description here

  • 1
    \$\begingroup\$ Hint: the secret is already in that answer. Look at the radius parameter. That determines the "altitude" from the center of the sphere. Vary that, and you get mountains and valleys. Can you show us how you've tried to vary the radius in your code so far? \$\endgroup\$ – DMGregory May 28 '20 at 23:15

As DMGregory said, I just had to vary the radius variable.

// You simply have to multiply radius by any kind of random value
// I'm using perlin noise in this example
positions[v] = vec3(
                  c * cos(theta),
                  c * sin(theta)
               ) * radius * noiseValue(latitude, longitude)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.