Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (117)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  Can't get alpha blending to work properly    (Read 4367 times)
0 Members and 1 Guest are viewing this topic.
Offline Java Cool Dude

Senior Member




Java forever


« Posted 2003-11-04 18:30:26 »

   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);
Offline DavidYazel

Junior Member




Java games rock!


« Reply #1 - Posted 2003-11-04 20:32:28 »

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

David Yazel
Xith3D Project Founder
http://xith3d.dev.java.net

It may look complicated, but in the end it is just a bunch of triangles
Offline Java Cool Dude

Senior Member




Java forever


« Reply #2 - Posted 2003-11-04 20:55:20 »

Nope, didn't help Sad
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...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline desertrock

Senior Newbie





« Reply #3 - Posted 2003-11-04 22:52:27 »

i'm doing the following and get proper blending:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
    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);
Offline Java Cool Dude

Senior Member




Java forever


« Reply #4 - Posted 2003-11-04 23:32:50 »

Yup that extra line fixed it Smiley
Thank you
Offline Java Cool Dude

Senior Member




Java forever


« Reply #5 - Posted 2003-11-05 00:03:27 »

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....
Offline Java Cool Dude

Senior Member




Java forever


« Reply #6 - Posted 2003-11-05 00:13:24 »

Nope nope nope, got it to work after setting things up individually...
Looks like Xith3D manages things around a bit diffrent than Java3D...
Offline Java Cool Dude

Senior Member




Java forever


« Reply #7 - Posted 2003-11-05 01:08:03 »

Hey what method do you use to load your textures?
Same question targets David Yazel Smiley
Offline Java Cool Dude

Senior Member




Java forever


« Reply #8 - Posted 2003-11-05 01:23:54 »



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 Tongue


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
  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;
  }
Offline Yuri Vl. Gushchin

Senior Member




Speak Java!


« Reply #9 - Posted 2003-11-05 05:14:43 »

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

Yuri Vl. Gushchin
JProof Group
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Java Cool Dude

Senior Member




Java forever


« Reply #10 - Posted 2003-11-05 05:29:23 »

I'll see if I can write a little tutorial about particles in Java3D and Xith3D and publish the entire source as well.
Offline Yuri Vl. Gushchin

Senior Member




Speak Java!


« Reply #11 - Posted 2003-11-05 05:32:38 »

To load textures, I use something like

1  
2  
3  
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

Yuri Vl. Gushchin
JProof Group
Offline Preston

Senior Member


Medals: 4



« Reply #12 - Posted 2003-11-18 13:50:52 »

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

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)?
Offline Yuri Vl. Gushchin

Senior Member




Speak Java!


« Reply #13 - Posted 2003-11-18 14:00:37 »

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


Yes, sure. And even there is a test/demo named Xith3DTransparencyAlphaTest.bat - check it for details.

Yuri

Yuri Vl. Gushchin
JProof Group
Offline Preston

Senior Member


Medals: 4



« Reply #14 - Posted 2003-11-18 14:27:20 »

Quote

Yes, sure. And even there is a test/demo named Xith3DTransparencyAlphaTest.bat - check it for details.

My question has been fuzzy, sorry. I forgot to mention that currently I am always using light. :-) The AlphaTest I've read and using
1  
appeareance.setTransparencyAttributes(new TransparecnyAttributes(TransparencyAttributes.BLENDED, 0.5f);

without light works well.
However what if there's light in the scene?
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #15 - Posted 2003-11-18 14:43:05 »

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

Endolf

Offline Preston

Senior Member


Medals: 4



« Reply #16 - Posted 2003-11-18 16:51:50 »

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

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:
Quote

// Appearance
IndexedTriangleArray geo = ...
...
Appearance ape = new Appearance();
ape.setTexture(texture);
ape.setTextureAttributes(new TextureAttributes());  // Default texturemode is REPLACE.
ape.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.BLENDED, 0.5f));

ape.setMaterial(new Material()); // Now lighting is on, but then no transparency.

Shape3D korpus = new Shape3D(geo, ape);

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

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #17 - Posted 2003-11-18 17:24:58 »

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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
         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);

Offline Preston

Senior Member


Medals: 4



« Reply #18 - Posted 2003-11-19 05:48:10 »

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.

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:
1  
2  
3  
4  
5  
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.
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #19 - Posted 2003-11-19 18:00:02 »

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

Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #20 - Posted 2003-11-19 18:09:00 »

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 Smiley

HTH

Endolf.

Offline Yuri Vl. Gushchin

Senior Member




Speak Java!


« Reply #21 - Posted 2003-11-19 19:45:12 »

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

Yuri Vl. Gushchin
JProof Group
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #22 - Posted 2003-11-19 20:37:40 »

Hi
 Adding
1  
mat.setColorTarget(Material.AMBIENT_AND_DIFFUSE);
to my ac3d loader fixed it. I'll upload a new version at some point.

Thanks Yuri

Endolf

Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #23 - Posted 2003-11-20 05:00:43 »

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

Offline Yuri Vl. Gushchin

Senior Member




Speak Java!


« Reply #24 - Posted 2003-11-20 06:16:20 »

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.


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

Yuri Vl. Gushchin
JProof Group
Offline Preston

Senior Member


Medals: 4



« Reply #25 - Posted 2003-11-20 06:40:50 »

Thanks Endolf and Yuri. This helped my much.
Offline endolf

JGO Coder


Medals: 7


Current project release date: sometime in 3003


« Reply #26 - Posted 2003-11-20 07:52:47 »

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


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 Smiley

Cheers

Endolf

Offline 5parrowhawk

Senior Newbie




Java games rock!


« Reply #27 - Posted 2005-10-11 08:05:11 »

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!
Offline hawkwind

Junior Member




Java games rock!


« Reply #28 - Posted 2005-10-11 23:11:09 »

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

Offline 5parrowhawk

Senior Newbie




Java games rock!


« Reply #29 - Posted 2005-10-13 06:23:24 »


(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.)
Pages: [1] 2
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

radar3301 (12 views)
2014-09-21 23:33:17

BurntPizza (30 views)
2014-09-21 02:42:18

BurntPizza (22 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (28 views)
2014-09-20 20:14:06

BurntPizza (33 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (103 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!