Can't get alpha blending to work properly  

Appearance texturedAppearance = new Appearance();
TextureLoader textureLoader = new TextureLoader();
Texture2D texture = (Texture2D)textureLoader.getMinMapTexture(“Data\Star.PNG”);

  /*TextureAttributes textureAttributes = new TextureAttributes();
textureAttributes.setPerspectiveCorrectionMode(textureAttributes.NICEST);
textureAttributes.setTextureMode(textureAttributes.MODULATE);*/

TransparencyAttributes transparencyAttributes = new TransparencyAttributes();
transparencyAttributes.setTransparencyMode(transparencyAttributes.BLENDED);
transparencyAttributes.setDstBlendFunction(transparencyAttributes.BLEND_ONE);
transparencyAttributes.setSrcBlendFunction(transparencyAttributes.BLEND_SRC_ALPHA);

texturedAppearance.setTexture(texture);

// texturedAppearance.setTextureAttributes(textureAttributes);
texturedAppearance.setTransparencyAttributes(transparencyAttributes);

try MipMapAlphaTexture, or using a loader that passes in a boolean for specifying alpha.

Nope, didn’t help :frowning:
Also the color when set comes up all screwed up at rendering time. For example I would set Color4f to red, and all what gets displayed is a rainbow of other colors…

i’m doing the following and get proper blending:


    RenderingAttributes renderAttr = new RenderingAttributes();
    renderAttr.setDepthBufferEnable(false);
    appear.setRenderingAttributes(renderAttr);

     TransparencyAttributes transAttr =
      new TransparencyAttributes(
        TransparencyAttributes.BLENDED,
        0f,
        TransparencyAttributes.BLEND_ONE,
        TransparencyAttributes.BLEND_SRC_ALPHA);
    appear.setTransparencyAttributes(transAttr);

    TextureAttributes texAttr = new TextureAttributes();
    texAttr.setTextureMode(TextureAttributes.MODULATE);
    texAttr.setPerspectiveCorrectionMode(TextureAttributes.FASTEST);
    appear.setTextureAttributes(texAttr);

Yup that extra line fixed it :slight_smile:
Thank you

new TriangleStripArray(numberOfParticles*4,
GeometryArray.TEXTURE_COORDINATE_2 |
GeometryArray.COORDINATES |
GeometryArray.COLOR_4,
strips);

I feel there is a bug with the way Xith3D sets colors with an alpha component.
Instead of having the apperance coming up with the unique color I assigned to it, it comes with all different shades and what not.
Makes me think that the current implementation looks at Color4f just as Color3f…

Nope nope nope, got it to work after setting things up individually…
Looks like Xith3D manages things around a bit diffrent than Java3D…

Hey what method do you use to load your textures?
Same question targets David Yazel :slight_smile:

http://www.realityflux.com/abba/sun.jpg

10000 particles running on 2.0 Ghz Athlon + Radeon 9500 pro on an Nforce2 mobo.
That thing wipes the floor with Java3D, I almost feel bad for the latter :stuck_out_tongue:


  public Appearance getAppearance(){

    TextureLoader textureLoader      = new TextureLoader();
    Appearance    texturedAppearance = new Appearance();
    Texture2D     texture            = (Texture2D)textureLoader.getTexture("Data\\Star.jpg");

    RenderingAttributes renderingAttributes = new RenderingAttributes();
    renderingAttributes.setDepthBufferEnable(false);

    TextureAttributes textureAttributes = new TextureAttributes();
    textureAttributes.setTextureMode(textureAttributes.MODULATE);
    textureAttributes.setPerspectiveCorrectionMode(textureAttributes.FASTEST);

    TransparencyAttributes transparencyAttributes = new TransparencyAttributes();
    transparencyAttributes.setTransparencyMode(transparencyAttributes.BLENDED);
    transparencyAttributes.setDstBlendFunction(transparencyAttributes.BLEND_ONE);
    transparencyAttributes.setSrcBlendFunction(transparencyAttributes.BLEND_SRC_ALPHA);

    texturedAppearance.setTexture(texture);
    texturedAppearance.setTextureAttributes(textureAttributes);
    texturedAppearance.setRenderingAttributes(renderingAttributes);
    texturedAppearance.setTransparencyAttributes(transparencyAttributes);

    return texturedAppearance;
  }

Would be nice to know which code works differently in Java3D and Xith3D, so either we can fix this, or add to docs. Unfortunately, I can not test everything myself…

Yuri

I’ll see if I can write a little tutorial about particles in Java3D and Xith3D and publish the entire source as well.

To load textures, I use something like

BufferedImage bi;
...
texture = TextureLoader.getInstance().constructTexture(DirectBufferedImage.make(bi), "RGB", mipmap, magFilter, minFilter, Texture.WRAP, false, TextureLoader.SCALE_DRAW_BEST);

This works fine with both RGB and RGBA textures.

Yuri

Thanks to your help loading and using RGBA texture PNGs work fine. So finally I’ve got alpha transparency textures on screen. :slight_smile:

On a similar topic: is it possible to render a Shape3d with x % transpareny without using an alpha channeled texture? (Ie by using a normal RGB texture)?

[quote]is it possible to render a Shape3d with x % transpareny without using an alpha channeled texture? (Ie by using a normal RGB texture)?
[/quote]
Yes, sure. And even there is a test/demo named Xith3DTransparencyAlphaTest.bat - check it for details.

Yuri

My question has been fuzzy, sorry. I forgot to mention that currently I am always using light. :slight_smile: The AlphaTest I’ve read and using


appeareance.setTransparencyAttributes(new TransparecnyAttributes(TransparencyAttributes.BLENDED, 0.5f);

without light works well.
However what if there’s light in the scene?

Hi
It should work fine with lighting on too, always worked under java3d, and should under xith, though i’ve not tested it.

Endolf

[quote]It should work fine with lighting on too, always worked under java3d, and should under xith, though i’ve not tested it.
[/quote]
Hi too.
I can’t get it to work - but since I am so new to Xith3d it could well be my fault.
As soon as I enable the Shape3d’s lighting by using a Material() the 50% transparency doesn’t work.
For the following example I used an ambient and a diffuse light source in the scenegraph:

If I comment out the ape.setMaterial(…) line, so no lighting applies to the Shap3D, the same code works well with 50% transparency.

Hi
I just tested this with my AC3D loader (in the resources section, source included), and it seemed to work ok, i’ve dumped here the code I use below, I’m wondering if you need to set teh material, and then set the transparency attributes.

HTH

Endolf

         Appearance appearance = new Appearance();
        Material material = new Material();
        TransparencyAttributes transparency;
        TextureAttributes textureAttributes = new TextureAttributes();
        ColoringAttributes colouringAttributes = new ColoringAttributes();
        PolygonAttributes polyAttributes = new PolygonAttributes();

        material.setLightingEnable(true);
        material.setAmbientColor(ac3dMaterial.getAmbience());
        material.setDiffuseColor(ac3dMaterial.getColour());
        material.setEmissiveColor(ac3dMaterial.getEmissive());
        material.setSpecularColor(ac3dMaterial.getSpecular());
        material.setShininess(ac3dMaterial.getShininess());


        <snip> (just working out if our textures has alpha too)

            transparency = new TransparencyAttributes(TransparencyAttributes.BLENDED,<INSERT TRANSPARENCY HERE>,
                                                      TransparencyAttributes.BLEND_SRC_ALPHA,
                                                      TransparencyAttributes.BLEND_ONE_MINUS_SRC_ALPHA);
        
        textureAttributes.setTextureMode(TextureAttributes.MODULATE);

        colouringAttributes.setShadeModel(ColoringAttributes.NICEST);

[quote]Hi
I just tested this with my AC3D loader (in the resources section, source included), and it seemed to work ok, i’ve dumped here the code I use below, I’m wondering if you need to set teh material, and then set the transparency attributes.
[/quote]
Hi Endolf. Thanks for your help. Unfortunately I can’t get it to work. No matter if I set the material before the transparency or the other way round. I’ve included the same lines of code as yours in my programm but still as soon as i swtich on lightning in the Shape3D it’s not transparent any more. No matter if I use a RGB or RGBA texture. Btw I create this texture with Yuri’s mentioned way: TextureLoader.tf.constructTexture(DirectBufferedImage.make(bufferedimage), …) but this should make no difference…

Are my light sources a problem? However the scene looks to be lit correctly:


DirectionalLight dirLight = new DirectionalLight(new Color3f(1, 1, 1), new Vector3f(0, 0, -1));
mSceneBg.addChild(dirLight);

AmbientLight ambLigth = new AmbientLight(true, new Color3f(0.5f, 0.5f, 0.5f));
mSceneBg.addChild(ambLigth);

Which version of Xith3d do you use? For me it’s the community build from 2003-11-13_cvs.

I guess I do something silly, but I’ve to find out what.

Hi
I admit I wasn’t testing with a directional light turned on at all, but I just tested that. The one thing I did note is that the back faces arn’t being lit, I vaugly remebre reading something about that being a known unfinished bit of code. The object remained transparent however.

The version of Xith I’m using is one I checked out of cvs, on the 12th of october apparently.

I’ve tried the 13th November build, and get teh same problem as you, i’m just trying to track down from the community builds wen it got broken.

Endolf