parent
58bcb39a2d
commit
690dd7bf28
@ -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(); |
|
||||||
} |
|
||||||
} |
|
@ -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(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,3 @@ |
|||||||
|
void main(){ |
||||||
|
gl_FragColor=vec4(1.0,0.0,1.0,0.5); |
||||||
|
} |
@ -0,0 +1,4 @@ |
|||||||
|
Material Pong Rock : Materials/Tess/SimpleTess.j3md { |
||||||
|
MaterialParameters { |
||||||
|
} |
||||||
|
} |
@ -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 |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -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); |
||||||
|
} |
||||||
|
|
@ -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; |
||||||
|
} |
@ -0,0 +1,5 @@ |
|||||||
|
attribute vec3 inPosition; |
||||||
|
|
||||||
|
void main(){ |
||||||
|
gl_Position=vec4(inPosition,1); |
||||||
|
} |
Loading…
Reference in new issue