How do you get 16 vertices which are control points of surface into the Geometry Shader in OpenGL?

406 views Asked by At

I'm trying to render a cubic bezier surface with geometry shader so i have 16 control points which are all vec3s i change them to vec4s with w = 1 added in vertex shader

and here's the problem:

the geometry shader takes an array of vertices in form of primitives right?(such as points, lines, triangles) and they only can get max of 6 vertices (case of triangles adjacency) each time BUT i have to know all of 16 vertices (which are control points of a cubic bezier surface) before i draw anything.

how can i solve this problem? is glDrawArrays() not the function I should use?

1

There are 1 answers

0
Spektre On

For simple curve its doable like this rendering 2D cubic BEZIER with GLSL

So maybe you could try to do something similar. For example:

  1. on CPU pass a polygon with 16 points per patch to GPU

    the points must have specific topology/order so you know which points are which. (however I am not sure if 16 vertexes is inside geometry shader limit)

  2. in geometry shader emit BBOX + coefficient matrices

    so you emit single QUAD or few triangles or whatever covering the area of patch... But instead of original 16 points you pass pre-computed matrices of coefficients.

  3. in fragment shader

    compute closest distance to surface and either render or discard.

However closest distance to surface requires 2D search/fitting which will be much slower than 1D search/fitting for curves. So if too slow you can emit quad grid in geometry and fragment will just render the quad (approximating the surface with squares which with lighting would look ok for most cases)