<p>So I went onto a different forum and I asked this question, and somebody helped me solve it. It turns out that the coordinates for the octahedron were wrong. The problematic ones were top-north-east and bottom-south-east. I'll give a list of the new and improved coordinates as well as the output of it.</p>
<pre><code>    float vertices[] = {
    //top-north-east
     0.0f, 1.0f,  0.0f,
     0.0f,  0.0f,  1.0f,
     1.0f,  0.0f,  0.0f,

    //top-north-west
     0.0f,  1.0f,  0.0f,
    -1.0f,  0.0f,  0.0f,
     0.0f,  0.0f,  1.0f,

    //top-south-west
     0.0f,  1.0f,  0.0f,
     0.0f,  0.0f, -1.0f,
    -1.0f,  0.0f,  0.0f,

    //top-south-east
     0.0f, -1.0f,  0.0f,
     1.0f,  0.0f,  0.0f,
     0.0f,  0.0f, -1.0f,

    //bottom-north-east
     0.0f, -1.0f,  0.0f,
     1.0f,  0.0f,  0.0f,
     0.0f,  0.0f,  1.0f,

    //bottom-north-west
     0.0f, -1.0f,  0.0f,
     0.0f,  0.0f,  1.0f,
    -1.0f,  0.0f,  0.0f,

    //bottom-south-west
     0.0f, -1.0f,  0.0f,
    -1.0f,  0.0f,  0.0f,
     0.0f,  0.0f, -1.0f,

    //bottom-south-east
     0.0f, 1.0f,  0.0f,
     0.0f,  0.0f, -1.0f,
     1.0f,  0.0f,  0.0f
};
</code></pre>
<p><a href="https://i.sstatic.net/sfoAk.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/sfoAk.png" alt="enter image description here" /></a></p>
<p>Finally solved after two months...</p>

CC BY-SA 4.0
2023-04-17T14:25:05.547Z
2023-04-17T14:25:05.547Z
Chillzy
<p>I'm working on a program where I need to draw spheres. The method I'm using is creating an octahedron</p>
<p><a href="https://i.sstatic.net/xHpcm.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/xHpcm.png" alt="enter image description here" /></a>
And using tessellation shaders to subdivide it into a sphere, however there is a patch of the sphere that is not being rendered, and I don't know what's causing it. Keep in mind, this is the same when I stop normalizing the UVW coordinates through the evaluation shader</p>
<p><a href="https://i.sstatic.net/v1SB0.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/v1SB0.png" alt="enter image description here" /></a></p>
<p><a href="https://i.sstatic.net/BXmpD.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/BXmpD.png" alt="enter image description here" /></a>
Here is my tessellation evaluation shader</p>
<pre><code>#version 450 core

// from control shader
layout(triangles, equal_spacing, cw) in;

// input from control shader
in vec3 vertex_coord[];
// output vec
out vec3 vert;

// allows for object transformations and for movement
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

void main()
{
    // get / make the barycentric coordinates of the octahedron
    vec3 u = gl_TessCoord.x * vertex_coord[0];
    vec3 v = gl_TessCoord.y * vertex_coord[1];
    vec3 w = gl_TessCoord.z * vertex_coord[2];
    // normalizing the positions of the triangles allows for every point to be
    // the same distance away from the center, forming a sphere
    vec3 pos = normalize(u + v + w);
    // output patch point position in clip space
    gl_Position = projection * view * model * vec4(pos, 1.0);
}
</code></pre>
<p>Here is my tessellation control shader</p>
<pre><code>#version 450 core

// specify control points per output per patch
// control size of input and output arrays
layout(vertices=3) out;
// input from vertex shader
in vec3 vert_coord[];
// output to evaluation shader
out vec3 vertex_coord[];

// for tessellation
uniform mat4 view;
uniform mat4 model;

void main()
{
    // pass attributes through
    gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
    vertex_coord[gl_InvocationID] = vert_coord[gl_InvocationID];

    // control tessellation
    if(gl_InvocationID==0)
    {
        // dynamic LOD step by step
        // first: define rendering constants to control tessellation
        const float MIN_TESS_LEVEL = 4;
        const float MAX_TESS_LEVEL = 64;
        const float MIN_DISTANCE = 20;
        const float MAX_DISTANCE = 800;
        // second: transform each vertex into each eye
        vec4 eye_space_pos_1 = view * model * gl_in[0].gl_Position;
        vec4 eye_space_pos_2 = view * model * gl_in[1].gl_Position;
        vec4 eye_space_pos_3 = view * model * gl_in[2].gl_Position;
        // third: distance from camera scaled between 0 and 1
        float distance_1 = clamp((abs(eye_space_pos_1.z)-MIN_DISTANCE)/(MAX_DISTANCE-MIN_DISTANCE), 0.0, 1.0);
        float distance_2 = clamp((abs(eye_space_pos_2.z)-MIN_DISTANCE)/(MAX_DISTANCE-MIN_DISTANCE), 0.0, 1.0);
        float distance_3 = clamp((abs(eye_space_pos_3.z)-MIN_DISTANCE)/(MAX_DISTANCE-MIN_DISTANCE), 0.0, 1.0);
        // fourth: interpolate edge tessellation level based on closer vertex
        float tess_level_1 = mix(MAX_TESS_LEVEL, MIN_TESS_LEVEL, min(distance_3, distance_1));
        float tess_level_2 = mix(MAX_TESS_LEVEL, MIN_TESS_LEVEL, min(distance_1, distance_2));
        float tess_level_3 = mix(MAX_TESS_LEVEL, MIN_TESS_LEVEL, min(distance_2, distance_1));
        // fifth: set the corresponding outer tessellation levels
        gl_TessLevelOuter[0] = tess_level_1;
        gl_TessLevelOuter[1] = tess_level_2;
        gl_TessLevelOuter[2] = tess_level_3;
        // sixth: set the inner tessellation levels
        gl_TessLevelInner[0] = tess_level_1;
        gl_TessLevelInner[1] = tess_level_2;
    }
}
</code></pre>
<p>Here is my vertex shader</p>
<pre><code>#version 450 core

// position of the object
layout (location = 0) in vec3 pos;
layout (location = 1) in vec3 vert;

// vertices to make the sphere
out vec3 vert_coord;

void main()
{
    // position object
    gl_Position = vec4(pos, 1.0f);
    // put the vertices into a different vector
    vert_coord = vert;
}
</code></pre>
<p>And finally, here are my octahedron vertices and buffers and draw call</p>
<pre><code>    float vertices[] = {
    //top-north-east
     0.0f, -1.0f,  0.0f,
     0.0f,  0.0f,  1.0f,
     1.0f,  0.0f,  0.0f,

    //top-north-west
     0.0f,  1.0f,  0.0f,
    -1.0f,  0.0f,  0.0f,
     0.0f,  0.0f,  1.0f,

    //top-south-west
     0.0f,  1.0f,  0.0f,
     0.0f,  0.0f, -1.0f,
    -1.0f,  0.0f,  0.0f,

    //top-south-east
     0.0f,  -1.0f,  0.0f,
     1.0f,  0.0f,  0.0f,
     0.0f,  0.0f, -1.0f,

    //bottom-north-east
     0.0f, -1.0f,  0.0f,
     1.0f,  0.0f,  0.0f,
     0.0f,  0.0f,  1.0f,

    //bottom-north-west
     0.0f, -1.0f,  0.0f,
     0.0f,  0.0f,  1.0f,
    -1.0f,  0.0f,  0.0f,

    //bottom-south-west
     0.0f, -1.0f,  0.0f,
    -1.0f,  0.0f,  0.0f,
     0.0f,  0.0f, -1.0f,

    //bottom-south-east
     0.0f, 1.0f,  0.0f,
     0.0f,  0.0f, -1.0f,
     1.0f,  0.0f,  0.0f
};

unsigned int indices[] = {
    // first triangle
    0, 1, 2,
    // second triangle
    3, 4, 5,
    // third triangle
    6, 7, 8,
    // fourth triangle
    9, 10, 11,
    // fifth triangle
    12, 13, 14,
    // sixth triangle
    15, 16, 17,
    // seventh triangle
    18, 19, 20,
    // eighth triangle
    21, 22, 23
};

unsigned int vbo, vao, ebo;
glGenVertexArrays(1, &amp;vao);
glGenBuffers(1, &amp;vbo);
glGenBuffers(1, &amp;ebo);

glBindVertexArray(vao);

// upload vertex data to gpu
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices) * sizeof(float), &amp;vertices[0], GL_STATIC_DRAW);

// upload index data to gpu
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices) * sizeof(unsigned int), &amp;indices[0], GL_STATIC_DRAW);

// position attribute
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);

// normal attribute
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)(3 * sizeof(float)));
glEnableVertexAttribArray(1);

// max tessellation points / patches
glPatchParameteri(GL_PATCH_VERTICES, 3);
glDrawElements(GL_PATCHES, 24, GL_UNSIGNED_INT, 0);
</code></pre>
<p>As a bonus, if it's helpful, this is where the tutorial where I adapted my code from. The guy making it uses an icosahedron, which did not work when I tried it <a href="https://prideout.net/blog/old/blog/index.html@p=48.html" rel="nofollow noreferrer">https://prideout.net/blog/old/blog/index.html@p=48.html</a></p>

CC BY-SA 4.0
2023-03-31T06:39:32.907Z
there are a few things which look a bit strange to me... 1: you are defining 3 vec3 values for each vertex but only use 2 vertexAttributePointers. 2: you are using `GL_ELEMENT_ARRAY_BUFFER ` with `glDrawArrays` command instead of `glDrawElements`. Are there 3 vertices in your vertices list per block? have you tried to disable culling `glDisable(GL_CULL_FACE);`? maybe one of the patches is oriented the wrong way
Thomas
CC BY-SA 4.0
2023-03-31T13:26:14.523Z
@pmw1234 my max is 64
Chillzy
CC BY-SA 4.0
2023-03-31T13:27:11.617Z
@Thomas i'll try that right now and going back to you
Chillzy
CC BY-SA 4.0
2023-03-31T13:28:53.877Z
@pmw1234 yeah i'll get that fixed real quick
Chillzy
CC BY-SA 4.0
2023-03-31T14:18:52.713Z
Ok, I implemented the changes / suggestions you suggested, but it still didn't change the sphere. One thing I did notice though, when I changed the stride of `glVertexAttribPointer` from 3 to 0, it did cause the patch missing to switch from the back to the front, so that might be where the problem is it too, but it led to some distortions in the shape so that's probably not the solution.
Chillzy
CC BY-SA 4.0
2023-04-01T13:59:58.513Z
Ok I'll go try that real quick, never thought about that before
Chillzy
CC BY-SA 4.0
2023-04-01T14:12:49.710Z
Alright, so I tried it and unfortunately that didn't work. What happened was the sphere got some tessellation distortions / glitches and it removed the two base triangles that was on the bottom of the missing patch.
Chillzy
CC BY-SA 4.0
2023-04-01T14:25:04.060Z
There are multiple bugs in the code, fixing one is just causing another to become obvious. Trying a change that is clearly a bug isn't the way to go about fixing it. Identify bugs like the one I just pointed, fix it, then find the next one.
pmw1234
<opengl><shader><glsl><tesselation>
Having trouble rendering entire sphere
Chillzy
# Having trouble rendering entire sphere

(Asked by: username_0 on 2023-03-30)

I'm working on a program where I need to draw spheres. The method I'm using is creating an octahedron

[![enter image description here](https://i.sstatic.net/xHpcm.png)](https://i.sstatic.net/xHpcm.png)
And using tessellation shaders to subdivide it into a sphere, however there is a patch of the sphere that is not being rendered, and I don't know what's causing it. Keep in mind, this is the same when I stop normalizing the UVW coordinates through the evaluation shader

[![enter image description here](https://i.sstatic.net/v1SB0.png)](https://i.sstatic.net/v1SB0.png)

[![enter image description here](https://i.sstatic.net/BXmpD.png)](https://i.sstatic.net/BXmpD.png)
Here is my tessellation evaluation shader

```
#version 450 core

// from control shader
layout(triangles, equal_spacing, cw) in;

// input from control shader
in vec3 vertex_coord[];
// output vec
out vec3 vert;

// allows for object transformations and for movement
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

void main()
{
    // get / make the barycentric coordinates of the octahedron
    vec3 u = gl_TessCoord.x * vertex_coord[0];
    vec3 v = gl_TessCoord.y * vertex_coord[1];
    vec3 w = gl_TessCoord.z * vertex_coord[2];
    // normalizing the positions of the triangles allows for every point to be
    // the same distance away from the center, forming a sphere
    vec3 pos = normalize(u + v + w);
    // output patch point position in clip space
    gl_Position = projection * view * model * vec4(pos, 1.0);
}

```

Here is my tessellation control shader

```
#version 450 core

// specify control points per output per patch
// control size of input and output arrays
layout(vertices=3) out;
// input from vertex shader
in vec3 vert_coord[];
// output to evaluation shader
out vec3 vertex_coord[];

// for tessellation
uniform mat4 view;
uniform mat4 model;

void main()
{
    // pass attributes through
    gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
    vertex_coord[gl_InvocationID] = vert_coord[gl_InvocationID];

    // control tessellation
    if(gl_InvocationID==0)
    {
        // dynamic LOD step by step
        // first: define rendering constants to control tessellation
        const float MIN_TESS_LEVEL = 4;
        const float MAX_TESS_LEVEL = 64;
        const float MIN_DISTANCE = 20;
        const float MAX_DISTANCE = 800;
        // second: transform each vertex into each eye
        vec4 eye_space_pos_1 = view * model * gl_in[0].gl_Position;
        vec4 eye_space_pos_2 = view * model * gl_in[1].gl_Position;
        vec4 eye_space_pos_3 = view * model * gl_in[2].gl_Position;
        // third: distance from camera scaled between 0 and 1
        float distance_1 = clamp((abs(eye_space_pos_1.z)-MIN_DISTANCE)/(MAX_DISTANCE-MIN_DISTANCE), 0.0, 1.0);
        float distance_2 = clamp((abs(eye_space_pos_2.z)-MIN_DISTANCE)/(MAX_DISTANCE-MIN_DISTANCE), 0.0, 1.0);
        float distance_3 = clamp((abs(eye_space_pos_3.z)-MIN_DISTANCE)/(MAX_DISTANCE-MIN_DISTANCE), 0.0, 1.0);
        // fourth: interpolate edge tessellation level based on closer vertex
        float tess_level_1 = mix(MAX_TESS_LEVEL, MIN_TESS_LEVEL, min(distance_3, distance_1));
        float tess_level_2 = mix(MAX_TESS_LEVEL, MIN_TESS_LEVEL, min(distance_1, distance_2));
        float tess_level_3 = mix(MAX_TESS_LEVEL, MIN_TESS_LEVEL, min(distance_2, distance_1));
        // fifth: set the corresponding outer tessellation levels
        gl_TessLevelOuter[0] = tess_level_1;
        gl_TessLevelOuter[1] = tess_level_2;
        gl_TessLevelOuter[2] = tess_level_3;
        // sixth: set the inner tessellation levels
        gl_TessLevelInner[0] = tess_level_1;
        gl_TessLevelInner[1] = tess_level_2;
    }
}

```

Here is my vertex shader

```
#version 450 core

// position of the object
layout (location = 0) in vec3 pos;
layout (location = 1) in vec3 vert;

// vertices to make the sphere
out vec3 vert_coord;

void main()
{
    // position object
    gl_Position = vec4(pos, 1.0f);
    // put the vertices into a different vector
    vert_coord = vert;
}

```

And finally, here are my octahedron vertices and buffers and draw call

```
    float vertices[] = {
    //top-north-east
     0.0f, -1.0f,  0.0f,
     0.0f,  0.0f,  1.0f,
     1.0f,  0.0f,  0.0f,

    //top-north-west
     0.0f,  1.0f,  0.0f,
    -1.0f,  0.0f,  0.0f,
     0.0f,  0.0f,  1.0f,

    //top-south-west
     0.0f,  1.0f,  0.0f,
     0.0f,  0.0f, -1.0f,
    -1.0f,  0.0f,  0.0f,

    //top-south-east
     0.0f,  -1.0f,  0.0f,
     1.0f,  0.0f,  0.0f,
     0.0f,  0.0f, -1.0f,

    //bottom-north-east
     0.0f, -1.0f,  0.0f,
     1.0f,  0.0f,  0.0f,
     0.0f,  0.0f,  1.0f,

    //bottom-north-west
     0.0f, -1.0f,  0.0f,
     0.0f,  0.0f,  1.0f,
    -1.0f,  0.0f,  0.0f,

    //bottom-south-west
     0.0f, -1.0f,  0.0f,
    -1.0f,  0.0f,  0.0f,
     0.0f,  0.0f, -1.0f,

    //bottom-south-east
     0.0f, 1.0f,  0.0f,
     0.0f,  0.0f, -1.0f,
     1.0f,  0.0f,  0.0f
};

unsigned int indices[] = {
    // first triangle
    0, 1, 2,
    // second triangle
    3, 4, 5,
    // third triangle
    6, 7, 8,
    // fourth triangle
    9, 10, 11,
    // fifth triangle
    12, 13, 14,
    // sixth triangle
    15, 16, 17,
    // seventh triangle
    18, 19, 20,
    // eighth triangle
    21, 22, 23
};

unsigned int vbo, vao, ebo;
glGenVertexArrays(1, &vao);
glGenBuffers(1, &vbo);
glGenBuffers(1, &ebo);

glBindVertexArray(vao);

// upload vertex data to gpu
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices) * sizeof(float), &vertices[0], GL_STATIC_DRAW);

// upload index data to gpu
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices) * sizeof(unsigned int), &indices[0], GL_STATIC_DRAW);

// position attribute
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);

// normal attribute
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)(3 * sizeof(float)));
glEnableVertexAttribArray(1);

// max tessellation points / patches
glPatchParameteri(GL_PATCH_VERTICES, 3);
glDrawElements(GL_PATCHES, 24, GL_UNSIGNED_INT, 0);

```

As a bonus, if it's helpful, this is where the tutorial where I adapted my code from. The guy making it uses an icosahedron, which did not work when I tried it <https://prideout.net/blog/old/blog/index.html@p=48.html>

**Tags:** opengl, shader, glsl, tesselation

> **Comments:**
> **username_1**: there are a few things which look a bit strange to me... 1: you are defining 3 vec3 values for each vertex but only use 2 vertexAttributePointers. 2: you are using `GL_ELEMENT_ARRAY_BUFFER ` with `glDrawArrays` command instead of `glDrawElements`. Are there 3 vertices in your vertices list per block? have you tried to disable culling `glDisable(GL_CULL_FACE);`? maybe one of the patches is oriented the wrong way  
> **username_0**: @username_2 my max is 64  
> **username_0**: @username_1 i'll try that right now and going back to you  
> **username_0**: @username_2 yeah i'll get that fixed real quick  
> **username_0**: Ok, I implemented the changes / suggestions you suggested, but it still didn't change the sphere. One thing I did notice though, when I changed the stride of `glVertexAttribPointer` from 3 to 0, it did cause the patch missing to switch from the back to the front, so that might be where the problem is it too, but it led to some distortions in the shape so that's probably not the solution.  
> **username_0**: Ok I'll go try that real quick, never thought about that before  
> **username_0**: Alright, so I tried it and unfortunately that didn't work. What happened was the sphere got some tessellation distortions / glitches and it removed the two base triangles that was on the bottom of the missing patch.  
> **username_2**: There are multiple bugs in the code, fixing one is just causing another to become obvious. Trying a change that is clearly a bug isn't the way to go about fixing it. Identify bugs like the one I just pointed, fix it, then find the next one.  

---

## 1 answers

### Answer by username_0 on 2023-04-17. Score: -1 | Accepted answer

So I went onto a different forum and I asked this question, and somebody helped me solve it. It turns out that the coordinates for the octahedron were wrong. The problematic ones were top-north-east and bottom-south-east. I'll give a list of the new and improved coordinates as well as the output of it.

```
    float vertices[] = {
    //top-north-east
     0.0f, 1.0f,  0.0f,
     0.0f,  0.0f,  1.0f,
     1.0f,  0.0f,  0.0f,

    //top-north-west
     0.0f,  1.0f,  0.0f,
    -1.0f,  0.0f,  0.0f,
     0.0f,  0.0f,  1.0f,

    //top-south-west
     0.0f,  1.0f,  0.0f,
     0.0f,  0.0f, -1.0f,
    -1.0f,  0.0f,  0.0f,

    //top-south-east
     0.0f, -1.0f,  0.0f,
     1.0f,  0.0f,  0.0f,
     0.0f,  0.0f, -1.0f,

    //bottom-north-east
     0.0f, -1.0f,  0.0f,
     1.0f,  0.0f,  0.0f,
     0.0f,  0.0f,  1.0f,

    //bottom-north-west
     0.0f, -1.0f,  0.0f,
     0.0f,  0.0f,  1.0f,
    -1.0f,  0.0f,  0.0f,

    //bottom-south-west
     0.0f, -1.0f,  0.0f,
    -1.0f,  0.0f,  0.0f,
     0.0f,  0.0f, -1.0f,

    //bottom-south-east
     0.0f, 1.0f,  0.0f,
     0.0f,  0.0f, -1.0f,
     1.0f,  0.0f,  0.0f
};

```

[![enter image description here](https://i.sstatic.net/sfoAk.png)](https://i.sstatic.net/sfoAk.png)

Finally solved after two months...


---

