@Override
    public void simpleInitApp() {
        filterPostProcessor = new FilterPostProcessor(assetManager);
        getViewPort().addProcessor(filterPostProcessor);

        addDirectionalLight();
        addAmbientLight();

        Material instancingMaterial = createLightingMaterial(true, ColorRGBA.LightGray);

        instancedNode = new InstancedNode("theParentInstancedNode");
        instancedNode.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
        rootNode.attachChild(instancedNode);

        // create 10 spheres & boxes, along the z-axis, successively further from the camera
        Mesh sphereMesh = new Sphere(32, 32, 1f);
        Mesh boxMesh = new Box(0.7f, 0.7f, 0.7f);
        for (int z = 0; z < 10; z++) {
            Vector3f location = new Vector3f(0, -3, -(z * 4));
            locations[z] = location;

            Geometry sphere = new Geometry("sphere", sphereMesh);
            sphere.setMaterial(instancingMaterial);
            sphere.setLocalTranslation(location);
            instancedNode.attachChild(sphere);       // initially just add the spheres to the InstancedNode
            spheres[z] = sphere;

            Geometry box = new Geometry("box", boxMesh);
            box.setMaterial(instancingMaterial);
            box.setLocalTranslation(location);
            boxes[z] = box;
        }

        instancedNode.instance();


        Geometry floor = new Geometry("floor", new Box(20, 0.1f, 40));
        floor.setMaterial(createLightingMaterial(false, ColorRGBA.Yellow));
        floor.setLocalTranslation(5, -5, 0);
        floor.setShadowMode(RenderQueue.ShadowMode.Receive);
        rootNode.attachChild(floor);

        flyCam.setMoveSpeed(30);
    }
A test case for using instancing with shadow filter.

Based on distance from camera, swap in/out more/less detailed geometry to/from an InstancedNode.

@author duncanj
jme3-examples/src/main/java/jme3test/scene/instancing/TestInstancedNodeAttachDetachWithShadowFilter.java