Xith3D performance

Hi !

First I’d like to say that I am a true beginner in the 3D world :slight_smile: I have coded a small terrain test. It’s very basic ; it’s loads a bitmap and creates for each pixel a square made of two triangles. Every cell shares its normal with the neighbours so the (gouraud) rendering looks smooth.
It looks fine but i got a 25fps for a 4040 map, ie 4040*2=3200 triangles… on a Athlon2000+, GeForce4200, 1Go RAM :’( I started from the cubetest and testutils classes.
So i’d like to know if i am really bad (probably) or if the performance of Xith are not so good ???
Or maybe i miss some configuration point because the xith terrain demo is hanging the whole PC when launched…

Thanks
A pure beginner

Perhaps a source code of your test class could tell more of the possible bottlenecks?

Please search your code for Thread.sleep(…) code. Quite a few of test classes use it and it will for sure kill your fps (it is acceptable in test classes, because they test features, not speed).

Thanks for quickly answering. I put some code below. It is very long and quite unoptimized for the triangles generation. But even if the generation is badly coded, does it impact the performance (since the data are created just once) ???

And as i said, the XithTerrainDemo is hanging my PC (and another too which is a Athlon550,GeForce256,512Mo RAM)


public class TerrainRenderer2
{
    Transform3D testRotateY = new Transform3D();
    TransformGroup testRotateYGroup = new TransformGroup();
    Material material = new Material();
    boolean play = true;
    boolean pause = false;
    TerrainData terrainMap = null;
    View view = new View();

    public static void main(String[] args)
    {
            <load image in map>
            final TerrainRenderer2 test = new TerrainRenderer2(map, panel);
            ...
            test.start();
    }

    public TerrainRenderer2(TerrainData terrainMap, Component ccc)
        throws Exception
    {
        this.terrainMap = terrainMap;

        // Prepare full-screen canvas adapted for current resolution
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

        VirtualUniverse universe = new VirtualUniverse();

        view.setBackClipDistance(100f);
        view.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
        new Vector3f(0, 1, 0));
    view.getTransform().lookAt(
            new Vector3f(0, 3.5f, 3),
            new Vector3f(0, 0, 0),
        
        Locale locale = new Locale();
        universe.addLocale(locale);
        universe.addView(view);

        RenderPeer renderPeer = new RenderPeerImpl();
        CanvasPeer canvasPeer =
            renderPeer.makeCanvas(
                ccc,
                screenSize.width - 200,
                screenSize.height - 200,
                16,
                true);
        //canvasPeer.getWindow().setLocation(100, 100);
        Canvas3D canvas = new Canvas3D();
        canvas.set3DPeer(canvasPeer);
        view.addCanvas3D(canvas);

        BranchGroup scene = this.createSceneGraph();
        locale.addBranchGraph(scene);

        class KeyboardEventListener implements AWTEventListener{...}
        Toolkit.getDefaultToolkit().addAWTEventListener(
            new KeyboardEventListener(),
            AWTEvent.KEY_EVENT_MASK);
    }

    public void start()
    {
        <classical loop with view.renderOnce()>
    }

    public void stop()
    {
        play = false;
    }

    protected BranchGroup createSceneGraph() throws Exception
    {
        BranchGroup objRoot = new BranchGroup();

        AmbientLight light =
            new AmbientLight(true, new Color3f(0.25f, 0.25f, 0.25f));
        DirectionalLight dlight =
            new DirectionalLight(
                true,
                new Color3f(0.75f, 0.75f, 0.75f),
                new Vector3f(-1, -1, -1));
        objRoot.addChild(light);
        objRoot.addChild(dlight);

        // Add animation TransformGroup
        testRotateYGroup.setTransform(testRotateY);
        objRoot.addChild(testRotateYGroup);

        // Make extra transfrom we may want to play with (scale etc.)
        TransformGroup sceneRootTransform = new TransformGroup();
        Transform3D t = new Transform3D();
        t.setIdentity();
        t.setTranslation(new Vector3f(-2, 0, -2));
        sceneRootTransform.setTransform(t);
        testRotateYGroup.addChild(sceneRootTransform);

        material.setEmissiveColor(0.0f, 0f, 0f);
        material.setSpecularColor(0.5f, 0.5f, 0.5f);
        material.setAmbientColor(10.0f, 0.0f, 0.0f);
        material.setDiffuseColor(0.75f, 0.0f, 0.0f);
        material.setLightingEnable(true);

        int width = terrainMap.getSize().width;
        int height = terrainMap.getSize().height;
        int cellHeight = 0;

        //interpolatedHeightfield 
        float[][] ihf = new float[width - 1][height - 1];

        for (int i = 0; i < ihf.length; i++)
        {
            for (int j = 0; j < ihf[0].length; j++)
            {
                <much much (too much ?) lines to generate the triangles >
                <looks like xith examples>
            }
        }

                int flags = GeometryArray.COORDINATES;
                flags |= GeometryArray.NORMALS;

                TriangleArray qa = new TriangleArray(coords.length, flags);
                qa.setCoordinates(0, coords);
                qa.setNormals(0, normals);

                Appearance a = new Appearance();
                a.setPolygonAttributes(
                    new PolygonAttributes(
                        PolygonAttributes.POLYGON_FILL,
                        PolygonAttributes.CULL_NONE,
                        0));
                a.setColoringAttributes(
                    new ColoringAttributes(
                        new Color3f(1, 0, 0),
                        ColoringAttributes.SHADE_GOURAUD));
                a.setMaterial(material);

                Shape3D shape = new Shape3D();
                shape.setAppearance(a);
                shape.setGeometry(qa);
                sceneRootTransform.addChild(shape);
            }
        }

        return objRoot;
    }
}

Hi,

I just tested Xith3DTerrainTest on my PC and got 90-95 FPS.

The exact system configuration is:

WinXP Home
P4-1.8GHz, 512 Mb RAM
GeForce 440Go (32 Mb)
1600x1200 LCD, 32bpp color depth, 60 Hz refresh
Vertical Sync OFF
Drivers 2846 (Toshiba does not have newer drivers)
All windows except Xith3D window minimized, no other window overlap Xith3D window.

FPS measured using FRAPS 1.9D.

Yuri

Well, Xith3d is fast. David, Yuri and the other few maintainers say it’s not fully optimized yet and there will be done more in the future, but it’s already pretty fast and very usable IMHO.

Currently with a GF4 4200 I’ve got a scenery with about five moving/rotating objects with about 43000 polygons in total, @ 85 to 90 FPS on a 1024x768x32bpp screen. The (<2 GHz) CPU is idling at below 30% load, so actually it’s just up to the graphics card.

Of course, fewer (geometry static) objects with many polygons render better than many objects with fewer polygons, but still it gives a hint.