Global Anisotropic Filtering

According to this page on the wiki: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:anisotropic_filtering you can set anisotropic filtering for all textures loaded by the AssetManager via an AssetEventListener. I’ve attempted to do this but it does not produce any results.

Here is a simple test program that I attempted to use (note: don’t forget town.zip if you try this)
[java]
import com.jme3.app.SimpleApplication;
import com.jme3.asset.AssetEventListener;
import com.jme3.asset.AssetKey;
import com.jme3.asset.TextureKey;
import com.jme3.asset.plugins.ZipLocator;
import com.jme3.light.AmbientLight;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Spatial;

@SuppressWarnings(“rawtypes”)
public class AnisotropicTest extends SimpleApplication {

public static void main(String[] args) {
    AnisotropicTest app = new AnisotropicTest();
    app.start();
}

@Override
public void simpleInitApp() {
    AssetEventListener asl = new AssetEventListener() {
        public void assetLoaded(AssetKey key) {

// throw new UnsupportedOperationException(“Not supported yet.”);
}

        public void assetRequested(AssetKey key) {
            if (key.getExtension().equals("png") || key.getExtension().equals("jpg") || key.getExtension().equals("dds")) {
                TextureKey tkey = (TextureKey) key;
                tkey.setAnisotropy(8);
            }
        }

        public void assetDependencyNotFound(AssetKey parentKey, AssetKey dependentAssetKey) {

// throw new UnsupportedOperationException(“Not supported yet.”);
}
};
assetManager.addAssetEventListener(asl);

AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.mult(4));
rootNode.addLight(al);

assetManager.registerLocator("town.zip", ZipLocator.class);
Spatial gameLevel = assetManager.loadModel("main.scene");
gameLevel.setLocalTranslation(0, -5.2f, 0);
gameLevel.setLocalScale(2);
rootNode.attachChild(gameLevel);
}

}
[/java]

Here are the results for running that program (left = code above, right = forcing 8x anisotropic filtering in graphics control panel)

I am unsure if this functionality has been removed or if there is a bug or if I’m maybe adding the listener in the wrong place or what.

I’m using the latest build from the svn. I appreciate any help. :slight_smile:

Have you verified that the code is running and the extension is one of the ones you expect? A System.out.println could tell you this.

@Clifton said: According to this page on the wiki: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:anisotropic_filtering you can set anisotropic filtering for all textures loaded by the AssetManager via an AssetEventListener. I've attempted to do this but it does not produce any results.

Here is a simple test program that I attempted to use (note: don’t forget town.zip if you try this)

I am unsure if this functionality has been removed or if there is a bug or if I’m maybe adding the listener in the wrong place or what.

I’m using the latest build from the svn. I appreciate any help. :slight_smile:

Hello. I wrote this test. It works fine for me. Here is the screenshot:

Left screen Anisotropy=0(default). Right screen Anisotropy=32(stress case).

My Code for testing
[java]
package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.asset.AssetEventListener;
import com.jme3.asset.AssetKey;
import com.jme3.asset.TextureKey;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.collision.shapes.MeshCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.input.ChaseCamera;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.niftygui.NiftyJmeDisplay;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Sphere;
import com.jme3.system.AppSettings;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;

public class test extends SimpleApplication {

public static void main(String[] args) {
    test app = new test();
    AppSettings aps = new AppSettings(true);
    aps.setVSync(true);
    app.setSettings(aps);
    app.start();
}

@Override
public void simpleInitApp() {

// inputManager.setCursorVisible(true);
// flyCam.setDragToRotate(true);
flyCam.setEnabled(false);

    assetManager.addAssetEventListener(asl);
    
    
    Sphere sph = new Sphere(20, 10, 1);
    Spatial geom = assetManager.loadModel("test/untitled.j3o");

    Material mat = assetManager.loadMaterial("test/newMaterial.j3m");

// mat.setColor(“Color”, ColorRGBA.Blue);
geom.setMaterial(mat);

    rootNode.attachChild(geom);

    int numClones = 70;

    ChaseCamera chCam = new ChaseCamera(cam, geom, inputManager);

}



    AssetEventListener asl = new AssetEventListener() {
        public void assetLoaded(AssetKey key) {

// throw new UnsupportedOperationException(“Not supported yet.”);
}

        public void assetRequested(AssetKey key) {
            if (key.getExtension().equals("png") || key.getExtension().equals("jpg") || key.getExtension().equals("dds")) {
                System.out.println(key.getExtension());
                TextureKey tkey = (TextureKey) key;
                tkey.setAnisotropy(32);
            }
        }

        public void assetDependencyNotFound(AssetKey parentKey, AssetKey dependentAssetKey) {

// throw new UnsupportedOperationException(“Not supported yet.”);
}

    };
        
        
        
@Override
public void simpleUpdate(float tpf) {
    //TODO: add update code
}

}

[/java]

EDITED: possbly extensions of files in town.zip are DDS, JPG, PNG. But in my case they are only dds, png, jpg.

Ok, i downloaded the town.zip and i found the issue. Generated Materials (which are stored in j3o) override parameters of TextureKey.
But if you create your own j3m Material there will be no issue.

Here is my screenshot (left-gernerated materials. right-converted to j3o and created j3m materials):

@pspeed , @Momoko-Fan is there a way not to override parameters of TextureKey for Generated Materials?
Or apply AssetEventListener after generated j3o materials?

Or in other way, i need to get all TextureKeys from MaterialKey. Is it possible?

Like this:

[java]

        public void assetRequested(AssetKey key) {
           if (key.instanceOf(MaterialKey.class)) {
           MaterialKey mk = (MaterialKey) key;

           List allTextures = mk.getAllTextureKeys; // I NEED SUCH A METHOD!

}

[/java]

Thanks.

2 Likes
<cite>@mifth said:</cite> Ok, i downloaded the town.zip and i found the issue. Generated Materials (which are stored in j3o) override parameters of TextureKey. But if you create your own j3m Material there will be no issue.

Here is my screenshot (left-gernerated materials. right-converted to j3o and created j3m materials):

@pspeed , @Momoko_Fan is there a way not to override parameters of TextureKey for Generated Materials?
Or apply AssetEventListener after generated j3o materials?

Or in other way, i need to get all TextureKeys from MaterialKey. Is it possible?

Like this:

[java]

        public void assetRequested(AssetKey key) {
           if (key.instanceOf(MaterialKey.class)) {
           MaterialKey mk = (MaterialKey) key;

           List allTextures = mk.getAllTextureKeys; // I NEED SUCH A METHOD!

}

[/java]

Thanks.


This would be helpful, anyone who knows what they are doing who can help here? :slight_smile:

@mifth said: @pspeed , @Momoko_Fan is there a way not to override parameters of TextureKey for Generated Materials? Or apply AssetEventListener after generated j3o materials?

Or in other way, i need to get all TextureKeys from MaterialKey. Is it possible?

Thanks.

Is there an update on this? @pspeed @Momoko_Fan @mifth
I tried to use anisotropic filtering as well, but I can’t use it on the terrain.
I generate the terrain inside the SDK, so I don’t set any materials myself.

Thanks in advance.

I wasn’t aware of this issue.

@mifth said: Ok, i downloaded the town.zip and i found the issue. Generated Materials (which are stored in j3o) override parameters of TextureKey.
What do you mean by generated materials and "override parameters"?

@m41q @nehon i guess we talk about this code https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:anisotropic_filtering
I think we need to change it. We need to get all loaded n\models, then get all their materials and set the anisotropy to the textures.
i’ll try to make some tests. Just give me some days.

@nehon said: I wasn't aware of this issue.

What do you mean by generated materials and “override parameters”?

The issue is with materials which are stored in j3o (not in j3m). I’ll try to change my example of the AssetListener.

@m41q said: Is there an update on this? @pspeed @Momoko_Fan @mifth I tried to use anisotropic filtering as well, but I can't use it on the terrain. I generate the terrain inside the SDK, so I don't set any materials myself.

Thanks in advance.

It seems there is really no way to get TextureKey of GeneratedMaterial(inside of j3o) in the AssetListener. The only way is to set a j3m for the terrain.

1 Like
@mifth said: It seems there is really no way to get TextureKey of GeneratedMaterial(inside of j3o) in the AssetListener. The only way is to set a j3m for the terrain.

Hm, when I assign a material manually I’ll have to define the textures myself and can’t use the the terrain editor anymore for that. Too bad.
Thanks for your efforts tough.