Silly question about optimization

So I have a node that contains a lot of geometries. The geoms are not static and change colors, so using Batch Node and Texture Atlas I managed to batch the parent node (let’s call it nParent) and then attach it to the rootNode. It works fine and all the geoms get batched, however I don’t see any significant improvement in my fps… is there anything I am missing? is there anyuthing more I could do?

what FPS are you getting, and is there any improvement with using batchnode? how many objects do you have

I am getting FPS = 4



Objs= 42453

Triangles = 2986514

Vertices = 5967772



update:



if I don’t do batchNode, then I get:



FPS = 2

Objects = 66453

Triangles = 2986514

Vertices = 5967772

42453 is still a high object count, it seems they are not properly batched.



How many different materials do you have (by different i mean materials with different parameters)?

I only have one type of objects created with one mesh, one material (hence one color) thats about it…

do you call .batch() after you have attached all the geometries?

here’s my method:



[java] if (optimizeTag) {



// remove node from rootNode

getnParent().removeFromParent();



// add nParent to geomBatch

geomBatch.attachChild(getnParent()); // geomBatch is a BatchNode



// batch parent node

geomBatch.batch();

rootNode.attachChild(geomBatch);



}

[/java]

In your stats, how many materials did it say you have?

Texutres(M) ? its 3

I think it’s listed as shaders but may not be what I wanted to know. Worth posting though. All of those stats are meaningful.

Shaders (M) is also 3

Yeah, unfortunately, I think that 42,000 Materials might show up as just one shader if they all have the same shader code.



I think we need to know more about how you are creating your geometry and assigning materials. Are you loading a new material for each one or reusing material instances? From the stats so far, it seems like you have 42,000+ material instances.

I am using Eclipse so I have a method that gets called each time I need to create an object (I am creating an animation from a trace file), that goes lke this:



[java]create obj1 x y z at time 0.00

create obj2 x y z at time 1.34

etc[/java]



so



1- I import the object to my assets: Spatial sp = assetManager.loadModel("/Models/" + type + “.j3o”);

2- I set ots name and translation

[java]

sp.setLocalTranslation(x, y, z);

sp.setName(id);[/java]



3- I set material via texture atlas



[java]

if(!(sp instanceof Geometry))

{

throw new IllegalArgumentException(“Object being imported is a Node. The object imported must be a Geometry.”);

}



// pMaterial is a predefined material (gloval variable in my main class that is not being recreated)

pMaterial.setTexture(“DiffuseMap”, getAssetManager().loadTexture("/Materials/TextureAtlas/atlasColors.png"));

pMaterial.setFloat(“Shininess”, 2f); // activate shininess

pMaterial.setColor(“Specular”, ColorRGBA.White); // activate specularity



// point to the bottom right texture in the texture atlas

// uv map to color texture atlas

float[] texCoord = new float[((Geometry)sp).getMesh().getVertexCount() * 2];



float yTexel = AnimationUVMappingEnum.DARKBLUE.getV(); // just sets the color to blue from an ENUm



for(int i=0; i<texCoord.length; i++) {

texCoord = yTexel;

}



// clear texture coordinates buffer

((Geometry)sp).getMesh().clearBuffer(Type.TexCoord);



// fill buffer with new texture coordinates from atlas file

((Geometry)sp).getMesh().setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));

((Geometry)sp).getMesh().updateBound();



// set material on the geometry

((Geometry)sp).setMaterial(pMaterial);



getnParent().attachChild(sp); // attach it to the parent node of these geoms

[/java]

Do this only once:

pMaterial.setTexture(“DiffuseMap”, getAssetManager().loadTexture("/Materials/TextureAtlas/atlasColors.png"));



And then reuse the instance. See if that helps.

I like that approach but I did , and unfortunately I get the same stats , same fps :s - not sure if the materials are being created several times.

can you create a testcase?

@nightwolf911 said:
I like that approach but I did , and unfortunately I get the same stats , same fps :s - not sure if the materials are being created several times.


Then show us that version.

testCase would be really complicated as I have so many classes and the project is huge.



In my global variables I have



[java] // default pMaterial

public Material pMaterial;





// as advised I moved up the material setTexture to be called only once at initialization

simpleInit()

{



pMaterial = new Material(assetManager,"Common/MatDefs/Light/Lighting.j3md");

pMaterial.setTexture("DiffuseMap", assetManager.loadTexture("/Materials/TextureAtlas/atlasColors.png"));

}



[/java]



in another class I call the code I showed u above without setTexture.

this might be a very silly question about if instead of adding the node of geoms to the batchNode and then batching, if I added the geoms directly (without their parent node) to the batch node and batched, would it make any difference? I’m hopeless thats why I’m saying this :s

No, a test case makes it easier. If you cannot pull out the problem with a test case then you don’t have any overview over your source anymore it seems. No part of the engine is so complicated you couldn’t create a test case.

1 Like