From 1cce72cd0a92d82cd289a94271a63ab8c087f67e Mon Sep 17 00:00:00 2001 From: michael Date: Sat, 28 Feb 2015 13:53:36 +0100 Subject: [PATCH] Allow modifing of the tess factor with keys a and y --- .../material/TestTessellationShader.java | 45 ++++++++++++++++--- .../Materials/Tess/SimpleTess.tseval | 14 +++--- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/jme3-examples/src/main/java/jme3test/material/TestTessellationShader.java b/jme3-examples/src/main/java/jme3test/material/TestTessellationShader.java index 9d6762333..f7557ca83 100644 --- a/jme3-examples/src/main/java/jme3test/material/TestTessellationShader.java +++ b/jme3-examples/src/main/java/jme3test/material/TestTessellationShader.java @@ -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() { + @Override + public Boolean call() throws Exception { + tessellationMaterial.setInt("TessellationFactor",tessFactor); + return true; + } + }); + } + if(name.equals("TessDo")){ + tessFactor--; + enqueue(new Callable() { + @Override + public Boolean call() throws Exception { + tessellationMaterial.setInt("TessellationFactor",tessFactor); + return true; + } + }); + } + } + },"TessUp","TessDo"); } public static void main(String[] args) { diff --git a/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.tseval b/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.tseval index 32600c6f2..3f7074642 100644 --- a/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.tseval +++ b/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.tseval @@ -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; } \ No newline at end of file