Can't get alpha blending to work properly  

[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

Hi
Ok, some time between the 16th october build and the 1st of november build is when it broke, I don’t know if we need some new flags or anything. For now you might have to try an older build.
I am now waiting for all the ‘I told you so’ comments in this thread :slight_smile:

HTH

Endolf.

Well, some points on alpha blending.

There is no bug in this functionality, but this is a bit incompatible with Java3D. I just committed new test - Xith3DTransparencyAlphaTestLight.java - to CVS.

You should use setColorTarget(…) on your material to get transparency working in some (most) cases. The reason for this is that Java3D-style material accepts 3-component colors only, so for now material shader sets alpha to opaque. If you specify color target, appropriate material color will be replaced with color from coloring attributes/vertex colors/transparency attributes.

This is still not clear of what to do with this incompatibility, and I personally prefer to go to more advanced Material that will support different front/back materials and 2-sided lighing model, as well as more sophisticated light control.

Yuri

Hi
Adding

mat.setColorTarget(Material.AMBIENT_AND_DIFFUSE);

to my ac3d loader fixed it. I’ll upload a new version at some point.

Thanks Yuri

Endolf

Quick related question.
What are the different options, AMBIENT_AND_DIFFUSE, DIFFUSE, AMBIENT and SPECULAR all seem to be options, but what do each mean and what does that call do, does this mean that with transparent objects you can’t have all 2 types of material colour in effect?

Confused

Endolf

From Java3D docs:

[quote]public void setColorTarget(int colorTarget)

Sets the color target for per-vertex colors. When lighting is enabled and per-vertex colors are present (and not ignored) in the geometry for a given Shape3D node, those per-vertex colors are used in place of the specified material color(s) for this Material object.
[/quote]
In Xith3D, if no vertex colors present, the color combined from ColoringAttributes and TransparencyAttributes used as a vertex color and set to be same for all vertices.

Also note that default color target in Java3D is DIFFUSE and in Xith3D is NONE.

Yuri

P.S. There is also JavaDoc comments for this method/constants in Xith3D Material.java

Thanks Endolf and Yuri. This helped my much.

[quote]From Java3D docs:

In Xith3D, if no vertex colors present, the color combined from ColoringAttributes and TransparencyAttributes used as a vertex color and set to be same for all vertices.

Also note that default color target in Java3D is DIFFUSE and in Xith3D is NONE.

Yuri

P.S. There is also JavaDoc comments for this method/constants in Xith3D Material.java
[/quote]
Hi
Thanks Yuri, I should have checked the docs, I assumed from your previous comment that this was a new method, not one from java3d, rather that it just being a default that was inconsistant with java3d. I was reluctant to check out xith again as my old version worked. Tonight I will get the latest xith and recompile it all, including the javadoc :slight_smile:

Cheers

Endolf

Hi,

(Edit: sorry to dig this old thread up, I didn’t notice the date on it.)

I’m having a “windowing” transparency problem.

What happens is that I’m drawing 2 textured quads with alpha channels, one in front of the other, for a HUD. The quads are non-intersecting, perpendicular to the camera.

I’ve given both of them the following TransparencyAttributes:

TransparencyAttributes blendedTA = new TransparencyAttributes(TransparencyAttributes.BLENDED, 0.001f, TransparencyAttributes.BLEND_SRC_ALPHA, TransparencyAttributes.BLEND_ONE_MINUS_SRC_ALPHA);

Texture mode has been set to MODULATE.

However, when Xith draws the foreground texture, it does not blend with the background texture. Instead, it blends with the geometry behind the background quad. (So it appears to “cut a hole” in the background quad.)
I have attempted to use RenderingAttributes to fix this, but it seems to make the problem worse. Using a vanilla RenderingAttributes() with depth buffer writes enabled causes the background quad to disappear completely. Conversely, using RenderingAttributes(true,false,0.01f,RenderingAttributes.GREATER_OR_EQUAL) to disable depth buffer writes causes the foreground quad to disappear.

I’m at the end of my rope again. This is driving me crazy (and what’s worse, it was working just this morning without any RenderingAttributes, and predictably I FORGOT TO BACK UP AGAIN.) Help!

Perhaps my “Fun with textures”, splat shapes, example from the xith.org site might help.

http://xith.org/tutes/GettingStarted/html/more_fun_with_textures.html#SECTION00073000000000000000

(edit: deleted my stupid question ^^; - I somehow thought that tutorial was about multi-texturing on single geometry, until I took a closer look!)

Thanks! It works now - easiest fix ever. (4 lines of code!)

Uh, two questions:

  • What’s the functional difference between DecalGroup and OrderedGroup? They look the same in javadoc.

  • Am I correct in assuming that both of these group types work by directly re-adjusting the order of stuff in the depth buffer? (Sorry, I’m not a 3D expert.)

Err… it really works ?
I haven’t got it to work, What did I do wrong I wonder? There’s nothing more then adding the Shapes ??? Or does this only work, if I don’t use opaque planes?

uncertain without seeing your code. Opaque planes??? What do you mean here??

You wanted to see the code. Here is it (I tried to remove unimportant stuff, because then it would be even more, the code is from my terrain-loader. It splits the terrain in many different pieces).
I marked the areas bold, where I set Transparency Attributes , cause I believe there could lie the problem)

         // g is the Geometry
            for(int i = 0; i < texTypeSplit.length; i++) {
            	System.out.println("----------------------------- "+ i);
                AppearanceResult res = getAppearance(texTypeSplit[i], x, y, x+SEGMENT_LENGTH, y+SEGMENT_WIDTH);
                if(res != null) {
                    Shape3D shape = new Shape3D(g,res.getAppearance());
                    og.addChild(shape);
                 }
             }



public AppearanceResult getappearance(String type, int start_x, int start_y, int end_x, int end_y) {
 ....
    Texture tiles = texloader.loadTexture(tilePath,"RGB",true,Texture.BASE_LEVEL,Texture.BASE_LEVEL_LINEAR,Texture.WRAP);
    states[0] = new TextureUnitState();
    states[0].setTexture(tiles);
    TextureAttributes texAttrib = new TextureAttributes();
    texAttrib.setTextureMode(TextureAttributes.DECAL);
    states[0].setTextureAttributes(texAttrib);
    if(checkoutBelow) { // For the purely opaque level at the ground, I don't have an alpha layer, so I skip setting the alpha
        Texture alphamap = texloader.getMinMapAlphaTexture(alphaPath);


        states[1] = new TextureUnitState();
        states[1].setTexture(alphamap);
        TextureAttributes alphaAttrib = new TextureAttributes();
        alphaAttrib.setTextureMode(TextureAttributes.MODULATE);

states[1].setTextureAttributes(alphaAttrib);
TransparencyAttributes transAttr = new TransparencyAttributes( // These Transparency Attributes are for the Layers,
TransparencyAttributes.BLENDED, // that get layed over others, so they are more
0f, // transparent in some places than in others.
TransparencyAttributes.BLEND_SRC_ALPHA,
TransparencyAttributes.BLEND_ONE_MINUS_SRC_ALPHA);
transAttr.setSortEnabled(true);
a.setTransparencyAttributes(transAttr);
}
else {
TransparencyAttributes transAttr = new TransparencyAttributes(); // that’s for layer at the bottom, which is fully
transAttr.setSortEnabled(true); // opaque
a.setTransparencyAttributes(transAttr);
}
a.setTextureUnitState(states);
AppearanceResult res = new AppearanceResult(a, checkoutBelow);
return(res);
}

Note, that it works, if I don’t use the DecalGroup, but Transformgroups, that moves the alpha-layers a bit up, so they get shown over the opaque layer.

Arne