algorithmopenglsurfacenurbs

Understanding of NurbsSurface


I want to create a NurbsSurface in OpenGL. I use a grid of control points size of 40x48. Besides I create indices in order to determine the order of vertices.

enter image description here

In this way I created my surface of triangles. Just to avoid misunderstandings. I have float[] vertices=x1,y1,z1,x2,y2,z2,x3,y3,z3....... and float[] indices= 1,6,2,7,3,8.... Now I don't want to draw triangles. I would like to interpolate the surface points. I thought about nurbs or B-Splines.

The clue is: In order to determine the Nurbs algorithms I have to interpolate patch by patch. In my understanding one patch is defined as for example points 1,6,2,7 or 2,7,3,8(Please open the picture).

First of all I created the vertices and indices in order to use a vertexshader. But actually it would be enough to draw it on the old way. In this case I would determine vertices and indices as follows:

float[] vertices= v1,v2,v3... with v=x,y,z 

and

float[] indices= 1,6,2,7,3,8....

In OpenGL, there is a Nurbs function ready to use. glNewNurbsRenderer. So I can render a patch easily. Unfortunately, I fail at the point, how to stitch the patches together. I found an explanation Teapot example but (maybe I have become obsessed by this) I can't transfer the solution to my case. Can you help?


Solution

  • You have set of control points from which you want to draw surface.

    There are two ways you can go about this

    1. Which is described in Teapot example link you have provided. Calculate the vertices from control points and pass then down the graphics pipeline with GL_TRIANGLE as topology. Please remember graphics hardware needs triangulated data in order to draw. Follow this link which shows how to evaluate vertices from control points http://www.glprogramming.com/red/chapter12.html

    2. You can prepare path of your control points and use tessellation shaders to triangulate and stitch those points.

      For this you prepare set of control points as patch use GL_PATCH primitive and pass it to tessellation control shader. In this you will specify what tessellation level you want. Depending on that your patch will be tessellated by another fixed function stage known as Primitive Generator. Then your generated vertices will be pass to tessellation evaluation shader in which you can fine tune. Here you can specify outer or inner tessellation level which will further subdivide your patch.

      I would suggest you put your VBO and IBO like you have with control points and when drawing use GL_PATCH primitive. Follow below tutorial about how to use tessellation shader to draw nurb surfaces.

    Note : Second method I have suggested is kind of tricky and you will have to read lot of research papers.

    I think if you dont want to go with modern pipeline then I suggest go with option 1.