[alpha-texture] Problem with Transparent textures

Hey,



i have a texture which has an alpha-channel; sometimes from a perspective i can see the transparency, but when i look in an other angle i can only see the background color of my viewport…



I’m using queque bukkit and blend mode…



thanks for help…

@tommy5696 said:
Hey,

i have a texture which has an alpha-channel; sometimes from a perspective i can see the transparency, but when i look in an other angle i can only see the background color of my viewport...

I'm using queque bukkit and blend mode....

thanks for help...


Can you be more specific about what you mean by a "queque bukkit"?

[java]



gl.setQueueBucket(Bucket.Transparent); //Geometry

lablogo.setWrap(Texture.WrapMode.Repeat); //texture

m2.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); //Material

[/java]

@tommy5696 said:
i have a texture which has an alpha-channel; sometimes from a perspective i can see the transparency, but when i look in an other angle i can only see the background color of my viewport...


What do you expect to see in the last case? Is there some other geometry?

Please provide most information. It sounds like a rendering order issue and might be solved with setting the alpha test and alpha cuttoff on the additional render state. Or it might be that you've put geometry in the transparent bucket that shouldn't be, etc.

It's hard to say because we have no information about your scene.

[java]

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

Texture lablogo = assetManager.loadTexture("Images/Logos/sp01.png");

lablogo.setMagFilter(Texture.MagFilter.Nearest);

lablogo.setWrap(Texture.WrapMode.Repeat);

m2.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

m2.setTexture("DiffuseMap", lablogo);



wallCreator.createWall(m0, new Vector2f(32,18), new Vector3f(0,0,0), new Vector3f(0,0,0), true);



<strong><em>(WALLCREATOR)</em></strong>

public static void createWall(Material m, Vector2f size, Vector3f translation, Vector3f rotation, boolean repeat ) {





Quad ql = new Quad(size.x, size.y);

Geometry gl = new Geometry("wall", ql);



gl.setLocalTranslation(new Vector3f(translation));

gl.rotate(rotation.xFastMath.DEG_TO_RAD, rotation.yFastMath.DEG_TO_RAD, rotation.z*FastMath.DEG_TO_RAD);



if(repeat) ql.scaleTextureCoordinates(new Vector2f(ql.getWidth(),ql.getHeight()));

gl.setMaterial(m);

gl.setQueueBucket(Bucket.Transparent);

gl.setShadowMode(ShadowMode.CastAndReceive);

node.attachChild(gl);

}

[/java]



the node will be attached to scene (rootNode.attachChild(node) )…

So there is just one wall in your scene? Where does m0 get defined? There has to be some other geometry in your scene also or " but when i look in an other angle i can only see the background color of my viewport" makes no sense because there is no other color to see.



These will be the last questions I ask… so please provide all of the information necessary to solve the problem. Alternately, you can just use:

http://hub.jmonkeyengine.org/javadoc/com/jme3/material/RenderState.html#setAlphaTest(boolean)

http://hub.jmonkeyengine.org/javadoc/com/jme3/material/RenderState.html#setAlphaFallOff(float)

gamerunning:

[java]package net.wronguniverse.src.AppStates;



import com.jme3.material.RenderState.BlendMode;

import com.jme3.light.SpotLight;

import com.jme3.scene.control.LightControl;

import com.jme3.light.PointLight;

import net.wronguniverse.src.Utilities.WallCreator;

import com.jme3.light.AmbientLight;

import com.jme3.scene.shape.Quad;

import com.jme3.math.Vector2f;

import com.jme3.scene.Mesh;

import com.jme3.math.Quaternion;

import com.jme3.math.FastMath;

import com.jme3.math.Matrix3f;

import com.jme3.font.BitmapText;

import com.jme3.input.FlyByCamera;

import de.lessvoid.nifty.screen.Screen;

import de.lessvoid.nifty.screen.ScreenController;

import de.lessvoid.nifty.controls.Console;

import net.wronguniverse.src.Utilities.ViewStats;

import com.jme3.input.controls.KeyTrigger;

import com.jme3.input.KeyInput;

import com.jme3.bullet.util.CollisionShapeFactory;

import com.jme3.bullet.collision.shapes.CollisionShape;

import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;

import com.jme3.bullet.control.CharacterControl;

import com.jme3.bullet.control.RigidBodyControl;

import com.jme3.bullet.BulletAppState;

import com.jme3.input.controls.ActionListener;

import com.jme3.terrain.geomipmap.TerrainLodControl;

import com.jme3.renderer.Camera;

import com.jme3.math.Vector3f;

import com.jme3.light.DirectionalLight;

import com.jme3.scene.Spatial;

import com.jme3.app.Application;

import com.jme3.app.SimpleApplication;

import com.jme3.app.state.AbstractAppState;

import com.jme3.app.state.AppStateManager;

import com.jme3.asset.AssetManager;

import com.jme3.input.InputManager;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.niftygui.NiftyJmeDisplay;

import com.jme3.renderer.ViewPort;

import com.jme3.scene.Geometry;

import com.jme3.scene.Node;

import com.jme3.scene.shape.Box;



import com.jme3.audio.plugins.;

import com.jme3.audio.
;

import com.jme3.texture.Texture;



import de.lessvoid.nifty.Nifty;



import net.wronguniverse.src.WrongUniverseCoreClass;



import static net.wronguniverse.src.WrongUniverseCoreClass.*;

/**

  • @author Tom Schneider

    /

    public class GameRunning extends AbstractAppState implements ActionListener, ScreenController{



    //Nifty Variablen laden

    private Nifty nifty;

    private NiftyJmeDisplay niftyDisplay;







    private int fps = 0;

    BitmapText hudText;

    float scounter = 0f;





    private SimpleApplication app;

    private Node rootNode;

    private AssetManager assetManager;

    private AppStateManager stateManager;

    private InputManager inputManager;

    private ViewPort viewPort;

    private ViewPort guiViewPort;

    private AudioRenderer audioRenderer;

    private Node guiNode;

    private Camera cam;

    private FlyByCamera flyCam;







    private Node stateNode = new Node(“State root-Node to be added to root-node”);

    private WallCreator wallCreator = new WallCreator(stateNode);



    private BulletAppState bulletAppState;

    private RigidBodyControl landscape;

    private CharacterControl player;

    private Vector3f walkDirection = new Vector3f();

    private boolean left = false, right = false, up = false, down = false, jump=true;

    Geometry g;

    ViewStats stats;

    public static boolean pause = false;

    DirectionalLight sun;



    private Screen screen;



    public static Vector3f camloc = new Vector3f(16,10,16);

    public static Vector3f look = Vector3f.ZERO;

    private Console console;

    private PointLight spot;





    public GameRunning(SimpleApplication app) {

    this.app = app; // can cast Application to something more specific

    this.rootNode = this.app.getRootNode();

    this.assetManager = this.app.getAssetManager();

    this.stateManager = this.app.getStateManager();

    this.inputManager = this.app.getInputManager();

    this.viewPort = this.app.getViewPort();

    this.guiViewPort = this.app.getGuiViewPort();

    this.audioRenderer = this.app.getAudioRenderer();

    this.guiNode = this.app.getGuiNode();

    this.cam = this.app.getCamera();

    this.flyCam = this.app.getFlyByCamera();



    }



    @Override

    public void initialize(AppStateManager stateManager, Application app) {

    super.initialize(stateManager, app);



    pause = false;

    rootNode.attachChild(stateNode);





    niftyDisplay = new NiftyJmeDisplay(assetManager,

    inputManager,

    audioRenderer,

    guiViewPort);



    nifty = niftyDisplay.getNifty();

    nifty.registerScreenController(this);

    nifty.addXml(“Interface/GUI_02.xml”);

    nifty.gotoScreen(“gamehud”);



    guiNode.detachAllChildren();



    guiViewPort.addProcessor(niftyDisplay);



    inputManager.setCursorVisible(false);



    //STATS AND GUI



    //guiNode.attachChild(hudText);

    stats = new ViewStats(app, guiNode);







    // PHYSICS // PHYSICS // PHYSICS // PHYSICS // PHYSICS //

    bulletAppState = new BulletAppState();

    stateManager.attach(bulletAppState);

    //bulletAppState.getPhysicsSpace().enableDebug(assetManager);











    // TERRAIN // TERRAIN // TERRAIN // TERRAIN // TERRAIN //





    Node mainScene = new Node(“mainScene’s Node”);

    Spatial scn = assetManager.loadModel(“Scenes/freeWorld.j3o”);

    //mainScene.attachChild(scn);



    Material m0 = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);

    Texture textile = assetManager.loadTexture(“Textures/black_tile.png”);

    textile.setMagFilter(Texture.MagFilter.Nearest);

    textile.setWrap(Texture.WrapMode.Repeat);

    m0.setTexture(“DiffuseMap”, textile);



    Material m1 = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);

    Texture toplight = assetManager.loadTexture(“Textures/Light.png”);

    toplight.setMagFilter(Texture.MagFilter.Nearest);

    toplight.setWrap(Texture.WrapMode.Repeat);

    m1.setTexture(“DiffuseMap”, toplight);



    Material m2 = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);

    Texture lablogo = assetManager.loadTexture(“Images/Logos/sp01.png”);

    lablogo.setMagFilter(Texture.MagFilter.Nearest);

    lablogo.setWrap(Texture.WrapMode.Repeat);

    m2.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

    m2.setTexture(“DiffuseMap”, lablogo);



    Material m3 = new Material(assetManager, “Common/MatDefs/Light/Lighting.j3md”);

    Texture emergency = assetManager.loadTexture(“Images/Logos/emergency.png”);

    emergency.setMagFilter(Texture.MagFilter.Nearest);

    emergency.setWrap(Texture.WrapMode.Repeat);

    m3.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

    m3.setTexture(“DiffuseMap”, emergency);





    wallCreator.setNode(mainScene);



    wallCreator.createWall(m0, new Vector2f(32,18), new Vector3f(0,0,0), new Vector3f(0,0,0), true);

    wallCreator.createWall(m0, new Vector2f(32,18), new Vector3f(32,0,0), new Vector3f(0,-90,0), true);

    wallCreator.createWall(m0, new Vector2f(32,18), new Vector3f(0,0,32), new Vector3f(0,90,0), true);

    wallCreator.createWall(m0, new Vector2f(32,18), new Vector3f(32,0,32), new Vector3f(0,180,0), true);





    wallCreator.createWall(m0, new Vector2f(32,32), new Vector3f(32,0,0), new Vector3f(90,0,180), true);

    wallCreator.createWall(m0, new Vector2f(32,32), new Vector3f(0,16,0), new Vector3f(90,0,0), true);



    wallCreator.createWall(m1, new Vector2f(6,2), new Vector3f(13,16-.5f,15), new Vector3f(90,0,0), true);



    wallCreator.createWall(m2, new Vector2f(8,5), new Vector3f(5,7,0.3f), new Vector3f(0,0,10), false);

    wallCreator.createWall(m3, new Vector2f(2,1), new Vector3f(32-0.1f,7,15), new Vector3f(0,-90,0), false);



    stateNode.attachChild(mainScene);

    stateNode.attachChild(guiNode);











    TerrainLodControl lodControl = ((Node)scn).getControl(TerrainLodControl.class);

    if (lodControl != null)

    lodControl.setCamera(app.getCamera());





    AmbientLight al = new AmbientLight();

    al.setColor(ColorRGBA.White.mult(1.3f));



    stateNode.addLight(al);













    CollisionShape sceneShape = CollisionShapeFactory.createMeshShape(mainScene);

    landscape = new RigidBodyControl(sceneShape, 0);

    scn.addControl(landscape);



    CapsuleCollisionShape cs = new CapsuleCollisionShape(1.5f, 6f, 1);

    player = new CharacterControl(cs, 0.05f);

    player.setJumpSpeed(15);

    player.setFallSpeed(20);

    player.setGravity(40);

    player.setPhysicsLocation(camloc);





    bulletAppState.getPhysicsSpace().add(landscape);

    bulletAppState.getPhysicsSpace().add(player);











    Box b = new Box(0.2f,0.2f,0.2f);

    g = new Geometry(“Box”, b);

    Material m = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

    m.setColor(“Color”, ColorRGBA.Blue);

    g.setMaterial(m);

    g.setLocalTranslation(player.getPhysicsLocation());

    mainScene.attachChild(g);













    setUpKeys();



    cam.lookAt(new Vector3f(0, -2f, 0), Vector3f.UNIT_Y);

    //stateManager.detach(bulletAppState);

    //stateManager.detach(bulletAppState);



    }







    private void setUpKeys() {



    inputManager.addMapping(“Left”, new KeyTrigger(KeyInput.KEY_A));

    inputManager.addMapping(“Right”, new KeyTrigger(KeyInput.KEY_D));

    inputManager.addMapping(“Up”, new KeyTrigger(KeyInput.KEY_W));

    inputManager.addMapping(“Down”, new KeyTrigger(KeyInput.KEY_S));

    inputManager.addMapping(“Jump”, new KeyTrigger(KeyInput.KEY_SPACE));

    inputManager.addMapping(“PauseGame”, new KeyTrigger(KeyInput.KEY_ESCAPE));

    inputManager.addListener(this, “Left”);

    inputManager.addListener(this, “Right”);

    inputManager.addListener(this, “Up”);

    inputManager.addListener(this, “Down”);

    inputManager.addListener(this, “Jump”);

    inputManager.addListener(this, “PauseGame”);



    //inputManager.addListener(this, new String[]{“Jump”});

    }



    @Override

    public void update(float tpf) {



    if(pause == false) {



    stats.updateStats();



    Vector3f pl = player.getPhysicsLocation();



    Vector3f camDir = cam.getDirection().clone().multLocal(0.4f);

    Vector3f camLeft = cam.getLeft().clone().multLocal(0.3f);



    walkDirection.set(0,0,0);



    if(left) walkDirection.addLocal(camLeft);

    if(right) walkDirection.addLocal(camLeft.negate());

    if(up) walkDirection.addLocal(new Vector3f(camDir.x,0,camDir.z));

    if(down) walkDirection.addLocal(new Vector3f(camDir.negate().x,0,camDir.negate().z));



    player.setWalkDirection(walkDirection);



    //reset position if y less than -100

    if(player.getPhysicsLocation().getY() <= -100) {

    player.setPhysicsLocation(new Vector3f(0, 10f, 0));

    }



    cam.setLocation(player.getPhysicsLocation());

    g.setLocalTranslation(player.getPhysicsLocation());





    camloc = cam.getLocation();

    look = cam.getDirection();



    app.getListener().setLocation(cam.getLocation());

    app.getListener().setRotation(cam.getRotation());

    flyCam.setEnabled(true);



    System.out.println(cam.getDirection());





    } else if(pause == true) {

    WrongUniverseCoreClass.pauseGame(stateManager);

    }





    }



    public void cleanup() {

    stats.removeStats();

    stateManager.detach(bulletAppState);

    stateNode.detachAllChildren();

    stateNode.removeLight(sun);

    rootNode.detachChild(stateNode);



    nifty.removeScreen(“gamehud”);



    guiViewPort.removeProcessor(niftyDisplay);



    }



    public void onAction(String binding, boolean value, float tpf) {

    if (binding.equals(“Left”)) {

    left = value;

    } if (binding.equals(“Right”)) {

    right = value;

    } if (binding.equals(“Up”)) {

    up = value;

    } if (binding.equals(“Down”)) {

    down = value;

    }

    if(binding.equals(“Jump”)) player.jump();





    else if (binding.equals(“PauseGame”)) {

    pause = true;



    }



    }



    public void bind(Nifty nifty, Screen screen) {

    this.screen=screen;

    this.nifty = nifty;

    }



    public void onStartScreen() {

    }



    public void onEndScreen() {

    }









    }

    [/java]



    wallcreator:

    [java]/

  • To change this template, choose Tools | Templates
  • and open the template in the editor.

    */

    package net.wronguniverse.src.Utilities;



    import com.jme3.material.Material;

    import com.jme3.math.FastMath;

    import com.jme3.math.Vector2f;

    import com.jme3.math.Vector3f;

    import com.jme3.renderer.queue.RenderQueue.Bucket;

    import com.jme3.renderer.queue.RenderQueue.ShadowMode;

    import com.jme3.scene.Geometry;

    import com.jme3.scene.Node;

    import com.jme3.scene.shape.Quad;



    /**

    *
  • @author tom

    /

    public class WallCreator {



    private static Node node;



    public WallCreator(Node node) {

    this.node = node;

    }



    public static void setNode(Node node) {

    WallCreator.node = node;

    }



    public static void createWall(Material m, Vector2f size, Vector3f translation, Vector3f rotation, boolean repeat ) {





    Quad ql = new Quad(size.x, size.y);

    Geometry gl = new Geometry("wall", ql);



    gl.setLocalTranslation(new Vector3f(translation));

    gl.rotate(rotation.x
    FastMath.DEG_TO_RAD, rotation.yFastMath.DEG_TO_RAD, rotation.zFastMath.DEG_TO_RAD);



    if(repeat) ql.scaleTextureCoordinates(new Vector2f(ql.getWidth(),ql.getHeight()));

    gl.setMaterial(m);

    gl.setQueueBucket(Bucket.Transparent);

    gl.setShadowMode(ShadowMode.CastAndReceive);

    node.attachChild(gl);

    }

    }

    [/java]



    thats the important code



    images:

    http://imgur.com/a/NS9q2



    thats all what seems to be useful…



    tom

Why are the walls in the transparent bucket if they aren’t transparent?



This is a classic sorting issue, though. The transparent bucket is sorted from back to front so that transparency works properly… but sometimes this sorting can’t be done correctly and it will create visual artifacts.



If the walls must be in the transparent bucket then if you do what I said with the alpha test stuff on your floating text then it will fix your problem.