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);