Tessellation Shader confusion

I’m pretty sure that the SimpleTessellation Shader is more of a WIP vs something that should be utilized fully. But I could be wrong.

The issue I’m running into is a bit of a lack of understanding (I know. What a shocker.) of the Index buffer as it’s used in Tessellation.

If you follow the custom mesh tutorial here: https://jmonkeyengine.github.io/wiki/jme3/advanced/custom_meshes.html

And apply it to the test tessellation code here: jmonkeyengine/TestTessellationShader.java at 445f7ed010199d30c484fe75bacef4b87f2eb38e · jMonkeyEngine/jmonkeyengine · GitHub

Stuff seems to end up twisted.

If you use the code as is below everything is fine. You’ll note the number order for the second set of indexes (marked as “Odd order to work.”)

If you don’t clear the indexes and the marked line (just comment out those 2 lines) you get a triangle. Not a quad.

Or am I missing something as to how this works?

Here’s the code I’m using in 1 function:

        int tessFactor = 6;
        
        Material tessellationMaterial = new Material(getAssetManager(), "Materials/Tess/SimpleTess.j3md");
        tessellationMaterial.setInt("TessellationFactor", tessFactor);
        tessellationMaterial.getAdditionalRenderState().setWireframe(true);
        
        Mesh mesh = new Mesh();
        Vector3f [] vertices = new Vector3f[4];
        vertices[0] = new Vector3f(0,0,0);
        vertices[1] = new Vector3f(3,0,0);
        vertices[2] = new Vector3f(0,3,0);
        vertices[3] = new Vector3f(3,3,0);
        
        Vector2f[] texCoord = new Vector2f[4];
        texCoord[0] = new Vector2f(0,0);
        texCoord[1] = new Vector2f(1,0);
        texCoord[2] = new Vector2f(0,1);
        texCoord[3] = new Vector2f(1,1);
        
        int [] indexes = { 2,0,1, 1,3,2 };
        
        mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
        mesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
        
        mesh.setBuffer(Type.Index, 3, BufferUtils.createIntBuffer(indexes));        
        mesh.clearBuffer(VertexBuffer.Type.Index);
        mesh.setBuffer(VertexBuffer.Type.Index, 4, BufferUtils.createIntBuffer(1, 3, 2, 0)); //Odd order to work.
        mesh.setMode(Mesh.Mode.Patch);
        mesh.setPatchVertexCount(4);
        mesh.updateBound();
        
        Geometry geo = new Geometry("OurMesh", mesh); // using our custom mesh object
        geo.setMaterial(tessellationMaterial);
        rootNode.attachChild(geo);

Oh well. nvm. I’ll go off and attempt a tessellation shader as outlined here: http://prideout.net/blog/?p=49

Needed to learn how to do this anyways :slight_smile: Wish me luck!

1 Like

Sorry for the late reply.

Yeah SimpleTess is only a test shader to verify that the engine side features work as they should.

When using tessellation you have to think a bit different. You could say that instead of processing vertex positions in your vertex shader you actually pass control points to the tessellation control shader.
This stage then can compute additional control points and sets the tessellation level for each edge. In the tessellation evaluation shader you then calculate the vertex positions, texture coordinates and all that stuff you need.

Now, it depends on the tessellation shader stages how many control points you need to draw a primitive.
If the tess eval stage requires 4 control points you have to (HAVE TO!) set Mesh.patchCount to 4

The SimpleTessellation shader uses 4 control point as input. Mainly because that is what i have used at that time for my terrain.

One of the bigger problems is, that you cannot draw a model in blender, enable tessellation and the model looks good. It might work on some models, but it requires a few things to work.

On my personal list (which is probably not complete) is:

  1. All triangles must share the vertex data. (only soft mode in blender)
  2. Stuff like separate eyes, might not give good results.
  3. Any little error in the normal calculations shows up as very strange distortion
1 Like

Ah. Cool. Thanks for the heads up.

For my case I was going to sorta redo my procedural asteroids from this post: (September 2017) Monthly WIP screenshot thread - #17 by thecyberbob

To use a tessellation shader instead of my Catmull-Rom madness that I did. Figure it might be better up front for performance and simplicity’s sake.

1 Like