Help with a NURBS / B-Spline / Bezier patch shader.
I have a spline surface that I want to render in Unity. The spline is composed of a set of Nu*Nv
control points where Nu
and Nv
are the number of control points in each parametric direction. These are runtime variables.
In the figure above, there's an example of a NURBS surface. The black dots are its control points. The surface should be able to rendered with just these control points.
If you know anything about NURBS surfaces, then you know that they are technically a collection of bezier patches. Each bezier patch requires (p+1)*(q+1)
control points where p
and q
are the polynomial degrees in each parametric direction. Its safe to assume that p
and q
are constants such as 2 in the example above (bi-quadratic surface).
The highlighted section in the figure above corresponds to a bezier patch, and the highlighted control points are the control points that contribute to the patch. So each patch should be able to rendered just from knowing the (p+1)*(q+1)
control points corresponding to that patch.
In order to render the full NURBS surface, each patch must be rendered. In order to do this, each patch should be tessellated. More tessellation = smoother.
Now how do we do this in Unity?
Well.. without much knowledge of shaders, I'm hoping someone can guide here, but this is what needs to happen:
1. create a mesh that contains the control points - this won't actually correspond to the actual surface, but simply contains the data that the GPU will be able to use in order to construct it. So this mesh really only represents the "control mesh" which is the black dots + dashed lines in the image above.
2. When this mesh goes through the rendering pipeline, it first must be tessellated to a given tolerance.
3. with all the additional triangles / verts from the tessellation, a vertex shader is used to calculate the actual position on the surface by using the control point data from the mesh.
The issue is that in the vertex shader you don't actually have access to all the control points, just the one you are currently processing. Which is why I was thinking that if we render the surface patch-wise, then we can set a float3[(p+1)*(q+1)]
fixed length array containing the control points in the shader. But, this introduces a new issue which is how do we process the mesh patchwise? The GPU would need to know the topology of the control points and patches.
I'm stuck here.
Thanks!
Your answer
Follow this Question
Related Questions
Surface shader, too many samplers workaround 1 Answer
How to access shader graph property values through C# script? 0 Answers
Is it possible to blend 2 different materials via the shader graph? 0 Answers
Is it possible to apply a dissolve shader created with shader graph to a UI button? 0 Answers
Extrude texture blocks to mesh? 0 Answers