Allow modifing of the tess factor with keys a and y

experimental
michael 10 years ago
parent 273ad711bf
commit 1cce72cd0a
  1. 45
      jme3-examples/src/main/java/jme3test/material/TestTessellationShader.java
  2. 14
      jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.tseval

@ -1,6 +1,9 @@
package jme3test.material;
import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.material.Material;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
@ -8,27 +11,55 @@ import com.jme3.scene.VertexBuffer;
import com.jme3.scene.shape.Quad;
import com.jme3.util.BufferUtils;
import java.util.concurrent.Callable;
/**
* Created by michael on 28.02.15.
*/
public class TestTessellationShader extends SimpleApplication {
Material tessellationMaterial;
int tessFactor=5;
@Override
public void simpleInitApp() {
Material material = new Material(getAssetManager(), "Materials/Tess/SimpleTess.j3md");
material.setInt("TessellationFactor", 5);
material.getAdditionalRenderState().setWireframe(true);
tessellationMaterial = new Material(getAssetManager(), "Materials/Tess/SimpleTess.j3md");
tessellationMaterial.setInt("TessellationFactor", tessFactor);
tessellationMaterial.getAdditionalRenderState().setWireframe(true);
Quad quad = new Quad(10, 10);
quad.clearBuffer(VertexBuffer.Type.Index);
quad.setBuffer(VertexBuffer.Type.Index, 4, BufferUtils.createIntBuffer(0, 1, 2, 3));
quad.setMode(Mesh.Mode.Patch);
quad.setPatchVertexCount(4);
Geometry geometry = new Geometry("tessTest", quad);
geometry.setMaterial(material);
geometry.setMaterial(tessellationMaterial);
rootNode.attachChild(geometry);
Geometry geometry1 = new Geometry("Demo", new Quad(2, 2));
geometry1.setMaterial(new Material(getAssetManager(),"Common/MatDefs/Misc/Unshaded.j3md"));
rootNode.attachChild(geometry1);
getInputManager().addMapping("TessUp", new KeyTrigger(KeyInput.KEY_A));
getInputManager().addMapping("TessDo", new KeyTrigger(KeyInput.KEY_Y));
getInputManager().addListener(new AnalogListener() {
@Override
public void onAnalog(String name, float value, float tpf) {
if(name.equals("TessUp")){
tessFactor++;
enqueue(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
tessellationMaterial.setInt("TessellationFactor",tessFactor);
return true;
}
});
}
if(name.equals("TessDo")){
tessFactor--;
enqueue(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
tessellationMaterial.setInt("TessellationFactor",tessFactor);
return true;
}
});
}
}
},"TessUp","TessDo");
}
public static void main(String[] args) {

@ -2,16 +2,16 @@ layout(vertices=4) out;
out gl_PerVertex{
vec4 gl_Position;
}gl_out[];
uniform int mTessellationFactor;
uniform int m_TessellationFactor;
void main(){
if (gl_InvocationID == 0){
gl_TessLevelOuter[0]=5;
gl_TessLevelOuter[1]=5;
gl_TessLevelOuter[2]=5;
gl_TessLevelOuter[3]=5;
gl_TessLevelOuter[0]=m_TessellationFactor;
gl_TessLevelOuter[1]=m_TessellationFactor;
gl_TessLevelOuter[2]=m_TessellationFactor;
gl_TessLevelOuter[3]=m_TessellationFactor;
gl_TessLevelInner[0]=5;
gl_TessLevelInner[1]=5;
gl_TessLevelInner[0]=m_TessellationFactor;
gl_TessLevelInner[1]=m_TessellationFactor;
}
gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
}
Loading…
Cancel
Save