0

I am trying to create an example of an interpolated surface. First I created an example of an interpolated trefoil. enter image description here

Here the source of my example. Then I had to noticed that the animation is pretty slow, around 20-30FPS. After some papers, I know that have to "move" the evaluation of the trefoil into the GPU. Thus I studied some papers about tessellation shaders. At the moment I bind following simply vertex shader:

#version 130
in vec4 Position;
in vec3 Normal;

uniform mat4 Projection;
uniform mat4 Modelview;
uniform mat3 NormalMatrix;
uniform vec3 DiffuseMaterial;

out vec3 EyespaceNormal;
out vec3 Diffuse;

void main()
{
    EyespaceNormal = NormalMatrix * Normal;
    gl_Position = Projection * Modelview * Position;
    Diffuse = DiffuseMaterial;
}

Now I have multiply questions:

  • Do I use an array of vertices to pass GL_PATCHES like I already did with Triangle_Strips ? Which way is faster? DrawElements?

glDrawElements(GL_TRIANGLE_STRIP, Indices.Length, OpenGL.GL_UNSIGNED_SHORT, IntPtr.Zero);

or should I use

glPatchParameteri(GL_PATCH_VERTICES,16);
glBegin(GL_PATCHES);
   glVertex3f(x0,y0,z0)
   ...
glEnd();
  • What about the array of indices? How can I determine the path means in which order the patches will be passed.

  • Do I calculate the normals in the Shader as well?

  • I found some examples of tessellation shader but in #version400 Can I use this version on mobile devices as well?(OpenGL ES)

  • Can I pass multiple Patches to the GPU by Multithreading?

Many many thanks in advance.

Community
  • 1
  • 1
TimDor
  • 49
  • 1
  • 8
  • 1
    @Rabbid76: "*OpenGL ES doesn't provide geometry or tessellation shaders.*" Nonsense. ES 3.2 certainly does. – Nicol Bolas Dec 11 '17 at 21:03
  • @Rabbid76 yes the mesh itself should be animated as well. At the moment I create the VBO and VAO once but unfortunately the trefoil mesh data on the CPU. Thus I am planning to create the mesh data on the GPU but I don't know what to use for best performance achievements. – TimDor Dec 12 '17 at 00:11

1 Answers1

1

In essence I don't believe you have to send anything to the GPU in terms of indices (or vertices) as everything can be synthesized. I don't know if the evaluation of the trefoil knot directly maps onto the connectivity of the resulting tessellated mesh of a bilinear patch, but this could work.

You could do with a simple vertex buffer where each vertex is the position of a single trefoil knot. Set glPatchParameteri(GL_PATCH_VERTICES​, 1). Then you could draw multiple knots with a single call to glDrawArrays:

glDrawArrays(GL_PATCHES, 0, numKnots);

The tessellation control stage can be a simple pass through stage. Then in the tessellation evaluation shader you can use the abstract patch type of quads. Then move the evaluation of the trefoil knot, or any other biparametric shape, into the tessellation evaluation shader, using the supplied [u, v] coordinates. Then you could translate every trefoil by the input vertex. The normals can be calculated in the shader as well.

Alternatively, you could use the geometry shader to synthesize the trefoil just from one input vertex position using points as input primitive and triangle strip as output primitive. Then you could just call again

glDrawArrays(GL_POINTS, 0, numKnots);

and create the trefoil in the geometry shader using the function for the generation of the indices to describe the order of evaluation and translating the generated vertices with the input vertex.

In both cases there would be no need to multithread draw calls, which is ineffective with OpenGL anyways. You are limited by the number of vertices that can be generated maximum per-patch which should be 64 times 64 for tessellation and GL_MAX_GEOMETRY_OUTPUT_VERTICES for geometry shaders.

Reynolds
  • 161
  • 2
  • 9
  • Thanks for your help. After more papers it is clear, I want to use a tessellation shader since I found more simple examples in order to tessellate a surface which is divided into multiple bezier patches. I just don't find a way to use glPatchParameteri(GL_PATCH_VERTICES​, 1) in SharpGL or OpenTK. I have to find it as I need to develop in WPF. Do you know a way or a good example of how to divide a surface into multiple bezierpatches? – TimDor Dec 29 '17 at 03:36