Can't get alpha blending to work properly  

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