I’m currently trying to both develop a game and in the process learn something about tessellation. In relation to this I got JME3.1 alpha to check out if I could make sense of the tessellation.
I like to get something simple working from an example, and then twiddle with it as I go along, however I’m having problems with the tessellation sample supplied with JME3.1 alpha.
I have based both my triangles and quad tessellation on the example source from:
The vertex and fragment shader I will leave out since they are the same as from the above link.
First, a screenshot of my problem (left triangle, right quad)
As shown above I seem to be having some problems with the quad tessellation. The source code for adding the two cubes is as follow:
Node models = (Node) assetManager.loadModel(“Models/dice_simple.blend”);
//TRIANGLES
Node triModel = (Node) models.getChild("d6").deepClone();
triModel.setLocalTranslation(-2, 2, 0);
Geometry triGeom = (Geometry) triModel.getChild("d6Geometry1");
Material triMaterial = new Material(getAssetManager(), "Materials/TriTess.j3md");
triMaterial.setInt("TessellationFactor", 5);
triGeom.getMesh().setMode(Mesh.Mode.Patch);
triGeom.getMesh().setPatchVertexCount(3);
triGeom.setMaterial(triMaterial);
rootNode.attachChild(triModel);
//QUADS
Node quadModel = (Node) models.getChild("d6").deepClone();
quadModel.setLocalTranslation(2, 2, 0);
Geometry quadGeom = (Geometry) quadModel.getChild("d6Geometry1");
Material quadMaterial = new Material(getAssetManager(), "Materials/QuadTess.j3md");
quadMaterial.setInt("TessellationFactor", 5);
quadGeom.getMesh().setMode(Mesh.Mode.Patch);
quadGeom.getMesh().setPatchVertexCount(4);
quadGeom.setMaterial(quadMaterial);
rootNode.attachChild(quadModel);
Below are the two eval and control shaders for triangles and quads.
Triangles
//TriTess.tsctrl
layout(vertices=3) out;
uniform int m_TessellationFactor;
void main(void)
{
if (gl_InvocationID == 0)
{
gl_TessLevelInner[0] = m_TessellationFactor;
gl_TessLevelOuter[0] = m_TessellationFactor;
gl_TessLevelOuter[1] = m_TessellationFactor;
gl_TessLevelOuter[2] = m_TessellationFactor;
}
gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
}
//TriTess.tseval
layout (triangles) in;
uniform mat4 g_WorldViewProjectionMatrix;
void main(){
gl_Position = (gl_TessCoord.x * gl_in[0].gl_Position) +
(gl_TessCoord.y * gl_in[1].gl_Position) +
(gl_TessCoord.z * gl_in[2].gl_Position);
gl_Position = g_WorldViewProjectionMatrix * gl_Position;
}
Quads
//QuadTess.tsctrl
layout(vertices=4) out;
uniform int m_TessellationFactor;
void main(void)
{
if (gl_InvocationID == 0)
{
gl_TessLevelInner[0] = m_TessellationFactor;
gl_TessLevelInner[1] = m_TessellationFactor;
gl_TessLevelOuter[0] = m_TessellationFactor;
gl_TessLevelOuter[1] = m_TessellationFactor;
gl_TessLevelOuter[2] = m_TessellationFactor;
gl_TessLevelOuter[3] = m_TessellationFactor;
}
gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
}
//QuadTess.tseval
layout (quads) in;
uniform mat4 g_WorldViewProjectionMatrix;
void main(){
vec3 p0 = mix(gl_in[0].gl_Position.xyz, gl_in[3].gl_Position.xyz, gl_TessCoord.x);
// interpolate in horizontal direction between vert. 1 and 2
vec3 p1 = mix(gl_in[1].gl_Position.xyz, gl_in[2].gl_Position.xyz, gl_TessCoord.x);
// interpolate in vert direction
vec3 tePosition = mix(p0, p1, gl_TessCoord.y);
gl_Position = g_WorldViewProjectionMatrix * vec4(tePosition, 1);
}
Any help or guidance would be appreciated, even if it is just a link to some place I can read up on why I might be doing something wrong.
You might be able to notice that I have tried to keep the quad tessellation as close to the source material from JME3.1alpha just to try and get something working.
If needed I can provide more sourcecode or information regarding the model (which is just a cube made in blender).
I hope someone has some insight to give in regards to my problem.