Java Cool Dude
|
 |
«
Posted
2003-11-04 19: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);
|
|
|
|
|
DavidYazel
Junior Member  
Java games rock!
|
 |
«
Reply #1 - Posted
2003-11-04 21: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.netIt may look complicated, but in the end it is just a bunch of triangles
|
|
|
Java Cool Dude
|
 |
«
Reply #2 - Posted
2003-11-04 21:55:20 » |
|
Nope, didn't help  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!
|
|
desertrock
Senior Newbie 
|
 |
«
Reply #3 - Posted
2003-11-04 23: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); |
|
|
|
|
|
Java Cool Dude
|
 |
«
Reply #4 - Posted
2003-11-05 00:32:50 » |
|
Yup that extra line fixed it  Thank you
|
|
|
|
|
Java Cool Dude
|
 |
«
Reply #5 - Posted
2003-11-05 01: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....
|
|
|
|
|
Java Cool Dude
|
 |
«
Reply #6 - Posted
2003-11-05 01: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...
|
|
|
|
|
Java Cool Dude
|
 |
«
Reply #7 - Posted
2003-11-05 02:08:03 » |
|
Hey what method do you use to load your textures? Same question targets David Yazel 
|
|
|
|
|
Java Cool Dude
|
 |
«
Reply #8 - Posted
2003-11-05 02: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  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; } |
|
|
|
|
|
Yuri Vl. Gushchin
Senior Member   
Speak Java!
|
 |
«
Reply #9 - Posted
2003-11-05 06: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!
|
|
Java Cool Dude
|
 |
«
Reply #10 - Posted
2003-11-05 06: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.
|
|
|
|
|
Yuri Vl. Gushchin
Senior Member   
Speak Java!
|
 |
«
Reply #11 - Posted
2003-11-05 06: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
|
|
|
Preston
|
 |
«
Reply #12 - Posted
2003-11-18 14: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)?
|
Memento mori.
|
|
|
Yuri Vl. Gushchin
Senior Member   
Speak Java!
|
 |
«
Reply #13 - Posted
2003-11-18 15:00:37 » |
|
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
|
|
|
Preston
|
 |
«
Reply #14 - Posted
2003-11-18 15:27:20 » |
|
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?
|
Memento mori.
|
|
|
endolf
|
 |
«
Reply #15 - Posted
2003-11-18 15: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
|
|
|
|
Preston
|
 |
«
Reply #16 - Posted
2003-11-18 17:51:50 » |
|
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: // 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.
|
Memento mori.
|
|
|
endolf
|
 |
«
Reply #17 - Posted
2003-11-18 18: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); |
|
|
|
|
Preston
|
 |
«
Reply #18 - Posted
2003-11-19 06:48:10 » |
|
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.
|
Memento mori.
|
|
|
endolf
|
 |
«
Reply #19 - Posted
2003-11-19 19: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
|
|
|
|
endolf
|
 |
«
Reply #20 - Posted
2003-11-19 19: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  HTH Endolf.
|
|
|
|
Yuri Vl. Gushchin
Senior Member   
Speak Java!
|
 |
«
Reply #21 - Posted
2003-11-19 20: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
|
|
|
endolf
|
 |
«
Reply #22 - Posted
2003-11-19 21: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
|
|
|
|
endolf
|
 |
«
Reply #23 - Posted
2003-11-20 06: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
|
|
|
|
Yuri Vl. Gushchin
Senior Member   
Speak Java!
|
 |
«
Reply #24 - Posted
2003-11-20 07:16:20 » |
|
From Java3D docs: 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
|
|
|
Preston
|
 |
«
Reply #25 - Posted
2003-11-20 07:40:50 » |
|
Thanks Endolf and Yuri. This helped my much.
|
Memento mori.
|
|
|
endolf
|
 |
«
Reply #26 - Posted
2003-11-20 08:52:47 » |
|
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  Cheers Endolf
|
|
|
|
5parrowhawk
Senior Newbie 
Java games rock!
|
 |
«
Reply #27 - Posted
2005-10-11 10: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!
|
|
|
|
|
|
|
5parrowhawk
Senior Newbie 
Java games rock!
|
 |
«
Reply #29 - Posted
2005-10-13 08: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.)
|
|
|
|
|
|