From 690dd7bf2803bb212c4973a10f6660c5e0464407 Mon Sep 17 00:00:00 2001 From: michael Date: Sat, 28 Feb 2015 13:40:10 +0100 Subject: [PATCH] Added Geometry and Tessellation Shader Tests --- gradle.properties | 4 +- .../jme3test/material/TestGeometryShader.java | 3 +- .../jme3test/material/TestTesselation.java | 73 ------------------- .../material/TestTessellationShader.java | 37 ++++++++++ .../resources/Materials/Tess/SimpleTess.frag | 3 + .../resources/Materials/Tess/SimpleTess.j3m | 4 + .../resources/Materials/Tess/SimpleTess.j3md | 19 +++++ .../Materials/Tess/SimpleTess.tsctrl | 13 ++++ .../Materials/Tess/SimpleTess.tseval | 17 +++++ .../resources/Materials/Tess/SimpleTess.vert | 5 ++ 10 files changed, 101 insertions(+), 77 deletions(-) delete mode 100644 jme3-examples/src/main/java/jme3test/material/TestTesselation.java create mode 100644 jme3-examples/src/main/java/jme3test/material/TestTessellationShader.java create mode 100644 jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.frag create mode 100644 jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.j3m create mode 100644 jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.j3md create mode 100644 jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.tsctrl create mode 100644 jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.tseval create mode 100644 jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.vert diff --git a/gradle.properties b/gradle.properties index 4d8b56aa7..739101b20 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,10 +6,10 @@ jmeMainVersion = 3.1 jmeVersionTag = snapshot-github # specify if JavaDoc should be built -buildJavaDoc = true +buildJavaDoc = false # specify if SDK and Native libraries get built -buildSdkProject = true +buildSdkProject = false buildNativeProjects = false # Path to android NDK for building native libraries diff --git a/jme3-examples/src/main/java/jme3test/material/TestGeometryShader.java b/jme3-examples/src/main/java/jme3test/material/TestGeometryShader.java index 6ccedd1c3..04c8223f1 100644 --- a/jme3-examples/src/main/java/jme3test/material/TestGeometryShader.java +++ b/jme3-examples/src/main/java/jme3test/material/TestGeometryShader.java @@ -3,7 +3,6 @@ package jme3test.material; import com.jme3.app.SimpleApplication; import com.jme3.bounding.BoundingBox; import com.jme3.material.Material; -import com.jme3.material.RenderState; import com.jme3.math.Vector3f; import com.jme3.scene.Geometry; import com.jme3.scene.Mesh; @@ -27,7 +26,7 @@ public class TestGeometryShader extends SimpleApplication { geometry.updateGeometricState(); geometry.setMaterial(new Material(assetManager, "Materials/Geom/SimpleGeom.j3md")); //geometry.getMaterial().getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off); - //geometry.setMaterial(assetManager.loadMaterial("Materials/Geom/SimpleGeom.j3md")); + //geometry.setMaterial(assetManager.loadMaterial("Materials/Geom/SimpleTess.j3md")); rootNode.attachChild(geometry); Geometry geometry1 = new Geometry("T1", new Sphere(10, 10, 1)); diff --git a/jme3-examples/src/main/java/jme3test/material/TestTesselation.java b/jme3-examples/src/main/java/jme3test/material/TestTesselation.java deleted file mode 100644 index 231eb5c41..000000000 --- a/jme3-examples/src/main/java/jme3test/material/TestTesselation.java +++ /dev/null @@ -1,73 +0,0 @@ -package jme3test.material; - -import com.jme3.app.SimpleApplication; -import com.jme3.light.DirectionalLight; -import com.jme3.material.Material; -import com.jme3.math.*; -import com.jme3.scene.Geometry; -import com.jme3.scene.Node; -import com.jme3.scene.shape.Quad; -import com.jme3.texture.Texture; -import com.jme3.util.SkyFactory; -import com.jme3.util.TangentBinormalGenerator; - - -/** - * Created by michael on 23.02.15. - */ -public class TestTesselation extends SimpleApplication { - private Vector3f lightDir = new Vector3f(-1, -1, .5f).normalizeLocal(); - DirectionalLight dl; - - public void setupSkyBox() { - rootNode.attachChild(SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", false)); - } - - - public void setupLighting() { - - dl = new DirectionalLight(); - dl.setDirection(lightDir); - dl.setColor(new ColorRGBA(.9f, .9f, .9f, 1)); - rootNode.addLight(dl); - } - - void setupParallax() { - Material mat; - mat = assetManager.loadMaterial("Textures/Terrain/BrickWall/BrickWall2.j3m"); - mat.getTextureParam("DiffuseMap").getTextureValue().setWrap(Texture.WrapMode.Repeat); - mat.getTextureParam("NormalMap").getTextureValue().setWrap(Texture.WrapMode.Repeat); - - // Node floorGeom = (Node) assetManager.loadAsset("Models/WaterTest/WaterTest.mesh.xml"); - //Geometry g = ((Geometry) floorGeom.getChild(0)); - //g.getMesh().scaleTextureCoordinates(new Vector2f(10, 10)); - - Node floorGeom = new Node("floorGeom"); - Quad q = new Quad(100, 100); - q.scaleTextureCoordinates(new Vector2f(1, 1)); - Geometry g = new Geometry("geom", q); - g.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X)); - floorGeom.attachChild(g); - - - TangentBinormalGenerator.generate(floorGeom); - floorGeom.setLocalTranslation(-50, 22, 60); - //floorGeom.setLocalScale(100); - - floorGeom.setMaterial(mat); - rootNode.attachChild(floorGeom); - } - - @Override - public void simpleInitApp() { - setupLighting(); - setupParallax(); - cam.setLocation(new Vector3f(-15.445636f, 30.162927f, 60.252777f)); - cam.setRotation(new Quaternion(0.05173137f, 0.92363626f, -0.13454558f, 0.35513034f)); - } - - public static void main(String[] args){ - TestTesselation app = new TestTesselation(); - app.start(); - } -} diff --git a/jme3-examples/src/main/java/jme3test/material/TestTessellationShader.java b/jme3-examples/src/main/java/jme3test/material/TestTessellationShader.java new file mode 100644 index 000000000..9d6762333 --- /dev/null +++ b/jme3-examples/src/main/java/jme3test/material/TestTessellationShader.java @@ -0,0 +1,37 @@ +package jme3test.material; + +import com.jme3.app.SimpleApplication; +import com.jme3.material.Material; +import com.jme3.scene.Geometry; +import com.jme3.scene.Mesh; +import com.jme3.scene.VertexBuffer; +import com.jme3.scene.shape.Quad; +import com.jme3.util.BufferUtils; + +/** + * Created by michael on 28.02.15. + */ +public class TestTessellationShader extends SimpleApplication { + @Override + public void simpleInitApp() { + Material material = new Material(getAssetManager(), "Materials/Tess/SimpleTess.j3md"); + material.setInt("TessellationFactor", 5); + material.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); + 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); + } + + public static void main(String[] args) { + new TestTessellationShader().start(); + } +} diff --git a/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.frag b/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.frag new file mode 100644 index 000000000..636af0c7e --- /dev/null +++ b/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.frag @@ -0,0 +1,3 @@ +void main(){ + gl_FragColor=vec4(1.0,0.0,1.0,0.5); +} \ No newline at end of file diff --git a/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.j3m b/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.j3m new file mode 100644 index 000000000..599a8c61c --- /dev/null +++ b/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.j3m @@ -0,0 +1,4 @@ +Material Pong Rock : Materials/Tess/SimpleTess.j3md { + MaterialParameters { + } +} \ No newline at end of file diff --git a/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.j3md b/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.j3md new file mode 100644 index 000000000..81813493d --- /dev/null +++ b/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.j3md @@ -0,0 +1,19 @@ +MaterialDef SimpleGeom { + + MaterialParameters { + Texture2D NormalDisplacementMap + Int TessellationFactor + } + + Technique { + VertexShader GLSL400: Materials/Tess/SimpleTess.vert + TessellationEvaluationShader GLSL400: Materials/Tess/SimpleTess.tseval + TessellationControlShader GLSL400: Materials/Tess/SimpleTess.tsctrl + FragmentShader GLSL400: Materials/Tess/SimpleTess.frag + + WorldParameters { + WorldViewProjectionMatrix + } + } + +} \ No newline at end of file diff --git a/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.tsctrl b/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.tsctrl new file mode 100644 index 000000000..445276e42 --- /dev/null +++ b/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.tsctrl @@ -0,0 +1,13 @@ +layout (quads,equal_spacing,cw) 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); +} + diff --git a/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.tseval b/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.tseval new file mode 100644 index 000000000..32600c6f2 --- /dev/null +++ b/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.tseval @@ -0,0 +1,17 @@ +layout(vertices=4) out; +out gl_PerVertex{ + vec4 gl_Position; +}gl_out[]; +uniform int mTessellationFactor; +void main(){ + if (gl_InvocationID == 0){ + gl_TessLevelOuter[0]=5; + gl_TessLevelOuter[1]=5; + gl_TessLevelOuter[2]=5; + gl_TessLevelOuter[3]=5; + + gl_TessLevelInner[0]=5; + gl_TessLevelInner[1]=5; + } + gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position; +} \ No newline at end of file diff --git a/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.vert b/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.vert new file mode 100644 index 000000000..f82ebb79b --- /dev/null +++ b/jme3-testdata/src/main/resources/Materials/Tess/SimpleTess.vert @@ -0,0 +1,5 @@ +attribute vec3 inPosition; + +void main(){ + gl_Position=vec4(inPosition,1); +} \ No newline at end of file