I am sorry for the vague title, but i could not think of anything better.
My Problem is as follows:
I am rendering a bunch of voxels. Everything runs with acceptable fps. But, if the front, bottom left corner of the entire landscape comes into view or even the viewing frustum (covered my some other geometry), the “uniforms” count increases dramastically and the fps go down quiet a bit.
@zarch said:
I thought that, but look at the figures. Triangles and vertices both actually go down but FPS drops by over 100....
I think you are mistaken.
At 1341 FPS, he has 56 objects and 109k triangles
At 263 FPS, he has 161 objects and 380k triangles
The bad view has almost 3 times ad many objects and almost 4 times as many triangles. Something is going on at 0,0,0 and my guess is that there is a ton of bad geometry there.
If it were me, I'd probably dump the scene graph to logs and see what's what.
The fact that the uniforms shoot up says something about what’s in the scene there, though. When the object counts go down then the uniform count shoots up as the OP mentions.
That’s not normal and I suspect if the OP reduced it to a simple test case that the problem wouldn’t show… and if it did then that would be something to look into for sure.
Ok, i have come closer to the problem. I’ll try to explain a bit more what is going on.
The terrain consists of voxels. For faster modification, it is divided into smaller chunks of a given size. Every chunk is added to the map node as a child (the map node itself does not contain the geometry). Since a lot of the terrain is air, half or more of the chunks are going to be empty. The high uniform count is usually equal to the amount of uniforms i get when i fill the entire terrain with blocks.
Long story short: I don’t add empty chunks anymore and the problem is gone.
Sorry for your troubles.
If it is still of interest to you, here is a (not entirely simple, sorry about that) class which should replicate the effect. The red box is the danger point.
[java]package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.Node;
import com.jme3.scene.VertexBuffer;
import com.jme3.scene.shape.Box;
import com.jme3.util.BufferUtils;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
public class Main extends SimpleApplication {
public static final int MAP_SIZE_X = 128;
public static final int MAP_SIZE_Y = 128;
public static final int MAP_SIZE_Z = 128;
public static final int CHUNK_SIZE_X = 16;
public static final int CHUNK_SIZE_Y = 16;
public static final int CHUNK_SIZE_Z = 16;
public static final int NUM_CHUNKS_X = MAP_SIZE_X / CHUNK_SIZE_X;
public static final int NUM_CHUNKS_Y = MAP_SIZE_Y / CHUNK_SIZE_Y;
public static final int NUM_CHUNKS_Z = MAP_SIZE_Z / CHUNK_SIZE_Z;
Creates the vertices, etc. for one voxel directly into the provided lists.
*/
public void createCube(int i, int j, int k, short data[][][], List<Vector3f> vertice, List<Vector2f> texcoord, List<Integer> indices, List<Vector3f> normals) {