Poor Performance With Framebuffer Heightmaps

Hello,
I am rendering a height map that is computed in a pixel shader to a texture. Althought it only takes a few milliseconds to compute the height map, I am getting very poor performance (single digit FPS). I am not sure why but if I had to guess I would say it is because the height map is being repeatedly recalculated every frame. Although this still shouldn’t cause the performance loss I am seeing. Here is the code that renders the texture:

[java]
Texture2D hm = new Texture2D(256,256,Format.RGBA32F);
Quad q = new Quad(2,2);
Camera c = new Camera(1024,1024);
c.setLocation(new Vector3f (0,0,1));
c.lookAt(new Vector3f(0,0,0), Vector3f.UNIT_Y);
FrameBuffer fbo = new FrameBuffer(1024,1024,1);
fbo.setColorTexture(hm);
ViewPort vp = renderManager.createPreView(“View”, c);
vp.setOutputFrameBuffer(fbo);
mat = new Material(assetManager, “material.j3md”);
Geometry ge = new Geometry(“Mesh”,q);
vp.attachScene(ge);
ge.setMaterial(mat);
mat.setTexture(“permuteTexture”, permutationTexture());
mat.setTexture(“gradTexture”, gradientTexture());
if(vp.isEnabled()){
ge.updateGeometricState();
}
[/java]
When I try calling vp.detachScene(ge); a very corrupted height map is obviously rendered based on the following image:

<img
src=“http://s18.postimg.org/i0j4omum1/Screen_Shot_2013_09_26_at_12_37_30_AM.png” alt="" />

Althought this does solve the framerate issue…
Any and all help is appreciated, thanks.

Allowing a key press to remove the quad geometry from the viewport allows for an increase in frame rates and does not result in any of the corruption pictured above. I don’t know how to automate this though. Any ideas?

Something like?
boolean doneAlready = false;
if( !doneAlready ) {
do the stuff
doneAlready = true;
}

Or probably better… the thing that captures the texture… make it an app state that removes itself once the image is rendered and then clean up the frame and stuff in AppState.cleanup().

@pspeed said: Something like? boolean doneAlready = false; if( !doneAlready ) { do the stuff doneAlready = true; }

Or probably better… the thing that captures the texture… make it an app state that removes itself once the image is rendered and then clean up the frame and stuff in AppState.cleanup().


Hmm well using a boolean does not change anything. I will try using an AppState.

@okelly4408 said: Hmm well using a boolean does not change anything. I will try using an AppState.

Then you may have to wait at least one frame first. At any rate, an app state is the proper way to go since once the image is rendered then you can detach it or disable it.

@pspeed said: Then you may have to wait at least one frame first. At any rate, an app state is the proper way to go since once the image is rendered then you can detach it or disable it.
How can I tell when one frame has appeared? Limit the frame rate and give it a rough estimate? I will definitely go with the app state when I add this to my main project; this is just for debugging though.

add a controll to something inside the node,and count to 2 in the update

or just use an app state that counts frames. Or just us an app state that waits until the frame is captured and then removes itself.

Or if you just want to try it then convert the boolean example into one that counts frames. I’m not entirely sure what is hard about this.

@pspeed said: or just use an app state that counts frames. Or just us an app state that waits until the frame is captured and then removes itself.

Or if you just want to try it then convert the boolean example into one that counts frames. I’m not entirely sure what is hard about this.


In concept it is not at all difficult. But there doesn’t seem to be a way of detecting when the frame has been captured. Also, what is the cause for the bad performance? When I make a regular quad, set it’s material to be the one where the noise calculation occur, and add it to the rootNode I get 200+ frames per second.

Well could be anything, from much switches in the shader, -gpus hate that somewhat-, to vram swapping.

Without a full testcase we can only guess.

So after a while of not being able to work on this, the furthest I have gotten is to wait one frame after the quad has been added to the viewport to disconnect it. This works well but I believe this wait is unnecessary due to the extremely short amount of time it takes for one height map to be generated. As far as I can tell the only way to combat this would be to detect when the frame was captured yet I cannot think of an elegant way to accomplish this. If this is possible than the rest should be easy…Thanks again.