Just curious about the coding of the projected grid… It seems the vertical height changes with the movement of my camera, which seems very odd. I even overided the "WaterHeightGenerator" "public float getHeight(…)" method.
I just want it to be vertically static, tried making a fake camera, but it didn't work out so well…
Seems to work now that I added:
ZBufferState zState = (ZBufferState)wm.getRenderManager().createRendererState(RenderState.StateType.ZBuffer);
zState.setEnabled(true);
zState.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
projectedGrid.setRenderState(zState);
Not sure exactly what this does though.
New Problem: Okay, adding a reflection terrain seems to remove my projectedgrid (water) and skybox with it…?
Creation of reflection Terrain (I think standard code, from test packages)?
public Spatial createReflectionTerrain() {
RawHeightMap heightMap = new RawHeightMap(this.getClass().getResourceAsStream(
"lib/data/heights.raw"),129, RawHeightMap.FORMAT_16BITLE, false);
Vector3f terrainScale = new Vector3f(5, 0.003f, 6);
heightMap.setHeightScale(0.001f);
TerrainPage page = new TerrainPage("Terrain", 33, heightMap.getSize(),
terrainScale, heightMap.getHeightMap());
page.getLocalTranslation().set(0, verticalDisplacement-1, 0);
page.setDetailTexture(1, 1);
// create some interesting texturestates for splatting
TextureState ts1 = (TextureState) wm.getRenderManager().createRendererState(RenderState.StateType.Texture);
Texture t0 = TextureManager.loadTexture(this.getClass().getResource("lib/data/terrainlod.jpg"),
Texture.MinificationFilter.Trilinear,
Texture.MagnificationFilter.Bilinear);
t0.setWrap(Texture.WrapMode.Repeat);
t0.setApply(Texture.ApplyMode.Modulate);
t0.setScale(new Vector3f(1.0f, 1.0f, 1.0f));
ts1.setTexture(t0, 0);
// //////////////////// PASS STUFF START
// try out a passnode to use for splatting
PassNode splattingPassNode = new PassNode("SplatPassNode");
splattingPassNode.attachChild(page);
PassNodeState passNodeState = new PassNodeState();
passNodeState.setPassState(ts1);
splattingPassNode.addPass(passNodeState);
// //////////////////// PASS STUFF END
// lock some things to increase the performance
splattingPassNode.lockBounds();
splattingPassNode.lockTransforms();
splattingPassNode.lockShadows();
ZBufferState buf = (ZBufferState) wm.getRenderManager().createRendererState(RenderState.StateType.ZBuffer);
buf.setEnabled(true);
buf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
splattingPassNode.setRenderState(buf);
CullState cs = (CullState) wm.getRenderManager().createRendererState(RenderState.StateType.Cull);
cs.setCullFace(CullState.Face.Back);
splattingPassNode.setRenderState(cs);
splattingPassNode.setCullHint(Spatial.CullHint.Never);
splattingPassNode.updateGeometricState(0.0f, true);
splattingPassNode.updateRenderState();
return splattingPassNode;
}
my create Water Pass code....:
waterEffectRenderPass = new WaterRenderPass(wm.getRenderManager().getCurrentScreenCamera(),6, true, true);
waterEffectRenderPass.setSpeedReflection(0.005f);
waterEffectRenderPass.setSpeedRefraction(-0.0025f);
waterEffectRenderPass.setWaterPlane(new Plane(new Vector3f(0.0f, 1.0f,0.0f), 0f));
waterEffectRenderPass.setClipBias(0.5f);
waterEffectRenderPass.setWaterMaxAmplitude(1.0f);
WaterHeightGenerator whg = new WaterHeightGenerator();
projectedGrid = new ProjectedGrid("ProjectedGrid", wm.getRenderManager().getCurrentScreenCamera(), 50, 35, 0.01f, whg);
waterEffectRenderPass.setWaterEffectOnSpatial(projectedGrid);
this.attachChild(projectedGrid);
waterEffectRenderPass.setReflectedScene(reflectedNode);
//waterEffectRenderPass.addReflectedScene(reflectionTerrain);
waterEffectRenderPass.setSkybox(skybox);
this.setRenderQueueMode(com.jme.renderer.Renderer.QUEUE_OPAQUE);
ZBufferState zState = (ZBufferState) wm.getRenderManager().createRendererState(RenderState.StateType.ZBuffer);
zState.setEnabled(true);
zState.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
projectedGrid.setRenderState(zState);
Entity e = new Entity("Water");
FrontLineWorld.singleton().addNode(this);
PassComponent pass = wm.getRenderManager().createPassComponent(waterEffectRenderPass);
e.addComponent(PassComponent.class, pass);
wm.addEntity(e);
anyone notice something obvious thats wrong?
I'm not quite sure I understand what you're trying to get the grid to do. Do you want the heights to be dependent on the grid itself instead of the camera?
I think the HeightGenerator is what you want to look at, it uses trig to make the waves appear (it's much faster than using some physics formula to simulate waves). I just reinstalled windows and I don't have my projects in eclipse yet, so I can't look at the source to help you out, but check out HeightGenerator.java and see if you find your problem.