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:
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);
ViewPort vp = renderManager.createPreView(“View”, c);
mat = new Material(assetManager, “material.j3md”);
Geometry ge = new Geometry(“Mesh”,q);
When I try calling vp.detachScene(ge); a very corrupted height map is obviously rendered based on the following image:
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?
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.
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.
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.