sphere

Defines the geometry of an approximate sphere, whose mesh comprises of a given number of meridians (horizontal steps) and parallels (vertical steps). Use SPHERE_PRIMITIVES vertex configuration with SPHERE_VERTEX_COUNT(MERIDIANS, PARALLELS) vertices.

See also icosphere for an alternate sphere mesh with more uniform geometry and no discernible poles.

Get the coordinate of vertex i

template <MERIDIANS, PARALLELS>
vec3 sphereCoord(int i);

Get the normal vector of vertex i

template <MERIDIANS, PARALLELS>
vec3 sphereNormal(int i);

Get the texture coordinate of vertex i

template <MERIDIANS, PARALLELS>
vec2 sphereTexCoord(int i);

Get the tangent space transformation matrix of vertex i

template <MERIDIANS, PARALLELS>
mat3 sphereTangentSpace(int i);

The sphereVertex function can be used directly as the vertex shader if no coordinate transformation is needed.

Example

vec4 vertexShader(out vec3 normal, int index) {
    vec3 coord = sphereCoord<128, 64>(index);
    normal = sphereNormal<128, 64>(index);
    coord = transformCoord(coord);
    normal = transformNormal(normal);
    return projectCoord(coord);
}

vec4 fragmentShader(in vec3 normal) {
    return computeLighting(normal);
}

model Sphere :
    fragment_data(vec3),
    vertex(vertexShader, SPHERE_PRIMITIVES, SPHERE_VERTEX_COUNT(128, 64)),
    fragment(fragmentShader);