Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Problem with Transparency blending.  (Read 4131 times)
0 Members and 1 Guest are viewing this topic.
Offline Alfryd

Junior Duke





« Posted 2005-09-13 21:05:52 »

http://s13.invisionfree.com/Heroes_of_Ardania_v2/index.php?showtopic=67&st=0#entry2033965

The attachment there is a zipfile that demos the problem I've been having with setting TransparencyAttributes to BLENDED- the smaller square I generate appears to disappear behind the larger one, which is impossible.  Using an opaque surface fixes this problem, but I definitely need to be able to present transparency.  Any clues as to the problem here?  Any help would be greatly appreciated.
Offline Mike Jacobs

Junior Duke





« Reply #1 - Posted 2005-09-13 22:25:22 »

Are you using TRANSPARENCY_SORT_GEOMETRY on the view?  The default transparency sort policy is TRANSPARENCY_SORT_NONE.

Mike

Special Effects for Java 3D games: http://www.indietechnologies.com
Offline Alfryd

Junior Duke





« Reply #2 - Posted 2005-09-14 17:47:21 »

Thanks for the help!  Though why on Earth J3D should have it's default set to anything else boggles my mind...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Alfryd

Junior Duke





« Reply #3 - Posted 2005-09-14 18:07:40 »

Hmm.  After testing, while this solves the problem for transparency sorting between different Shape3Ds, it does nothing to help sorting within a single Shape3D.  Most irritating.  It's not as if Transparency support is rarely required of typical 3D apps these days, you'd think the engine would cover it somewhere...
Offline tom
« Reply #4 - Posted 2005-09-14 20:04:01 »

Most apps do not require polygons sorted by transparency. There are techincal reasons why this would be to slow. In particular if there are many polygons. I don't know what your trying to do but try to think of a workaround where you don't use transparency, or find a clever way of breaking the geometry up to reduce the visual artifacts.

It is possible to implement it yourself, but it's a huge amount of work and would be dog slow.

Offline Alfryd

Junior Duke





« Reply #5 - Posted 2005-09-14 21:15:50 »

Quote
I don't know what your trying to do...
http://s13.invisionfree.com/Heroes_of_Ardania_v2/index.php?showtopic=67
If you're really curious,  theres a zipfile for a more complete demo, at the top of the thread.

Oh, it can probably be worked around with reasonable success, but I don't think it's fair to say most 3D apps don't require transparency support.  Warcraft3 certainly *seemed* capable of it, and I'm looking to rig up an engine with roughly the same properties.  I already have bone-based animation support worked out, the models just display terribly unless I turn off transparency.  Surely most modern games can deal with this sort of demand?  It's like in java2d, they don't have proper hardware-accelerated transparency support worked out yet, so I had to go devise my own engine to handle it.  And it was a huge amount of work, and dog slow unless I re-used most of the canvas each frame.  But surely there's a method of skipping screen regions that you know have been rendered completely opaque at less depth than the current poly, and skipping those?  I applied something similar to my 2d engine and got good, (approaching O(n),) results, but then, I'm no expert at 3d.
Plus, I don't think they've released the source code for the OSX implementation of J3d.  So, I couldn't really go about tweaking the code myself.  And it would all get very platform-dependant.
Bah...  ...oh well.  Thanks for the advice.
Offline tom
« Reply #6 - Posted 2005-09-15 00:34:24 »

Quote
If you're really curious,  theres a zipfile for a more complete demo, at the top of the thread.

Sorry, but getting someones source code to compile is way to much work. In particular since I'm guessing I have to download and intall java3d and possible java5. If you had a screenshot I could look at it.

Quote
Oh, it can probably be worked around with reasonable success, but I don't think it's fair to say most 3D apps don't require transparency support.  Warcraft3 certainly *seemed* capable of it, and I'm looking to rig up an engine with roughly the same properties.

I did not say games don't use transparency. But they don't do perfect polygon sorted transparency like you suggested when you said "it does nothing to help sorting within a single Shape3D". There are workarounds, but what is best depends on what you are rendering. Trees and grass can be rendered with on/off transparency and set up correctly can be rendered without sorting. Other times it can be enough to turn off depth write. That will help with the "hidden by transparent triangle" bug, but can lead to "triangles not sorted bug" material is more opaque than transparent. In any  case, the Warcraft 3 people knows all this and the levels is buildt so that the bugs don't stand out.

Quote
But surely there's a method of skipping screen regions that you know have been rendered completely opaque at less depth than the current poly, and skipping those?  I applied something similar to my 2d engine and got good, (approaching O(n),) results, but then, I'm no expert at 3d.

There is. In opengl it is called AlphaFunc. Java3d should have it somewhere in one of the Appearances attributes. It allows you to process or reject an incoming fragment depending on its alpha value. You can use it by rendering the geometry twice. First only processing opaque pixels with depth write on. The second pass rendering only transprent pixels with depth write off. That would look good in most cases, but are still not perfect.

Quote
Plus, I don't think they've released the source code for the OSX implementation of J3d.  So, I couldn't really go about tweaking the code myself.  And it would all get very platform-dependant.
Bah...  ...oh well.  Thanks for the advice.

You don't have to. Java3D allows you to change the geometry every frame. By rearanging the triangles in a back to front fasion using a bsp, you can sort the triangles within a Shape3D perfectly. Note that only sorting the triangles is not enough. Triangles can be overlapping in such a way that sorting is impossible. Then you need to split it up wich is what the bsp is for.

Offline Alfryd

Junior Duke





« Reply #7 - Posted 2005-09-15 12:08:34 »

There's not much new information, but on the left you have the figure without Transparency Blending, which is comparatively easy on the eye (or would be if diffuse lighting were working correctly,) on the right, the problems occur.
Click to Play

Quote
Sorry, but getting someones source code to compile is way to much work. In particular since I'm guessing I have to download and intall java3d and possible java5. If you had a screenshot I could look at it.
Java3d yes, I don't think java5.  So much for write once, run anywhere...
Quote
Java3d should have it somewhere in one of the Appearances attributes. It allows you to process or reject an incoming fragment depending on its alpha value. You can use it by rendering the geometry twice. First only processing opaque pixels with depth write on. The second pass rendering only transprent pixels with depth write off. That would look good in most cases, but are still not perfect.
Quote
You don't have to. Java3D allows you to change the geometry every frame. By rearanging the triangles in a back to front fasion using a bsp, you can sort the triangles within a Shape3D perfectly. Note that only sorting the triangles is not enough. Triangles can be overlapping in such a way that sorting is impossible. Then you need to split it up wich is what the bsp is for.
That should prove most useful, if I knew where and how to access and sort the geometry in this fashion, though I'm reasonably confident I can figure out the Appearance class.  Could you point me in the right direction on the class/methods needed?

(Since you seem to be formidably informed, would you have any idea what could cause diffuse lighting to switch from 100 to 0% across an entire model depending on which way you look at it (except, for some bizarre reason, a tiny patch on the left rim of the helmet?))

EDIT:  Oh, right, binary space partition.
Offline Alfryd

Junior Duke





« Reply #8 - Posted 2005-09-15 13:19:01 »

Hmm.

View view = universe.getViewer().getView();  //SimpleUniverse
view.setTransparencySortingPolicy(View.TRANSPARENCY_SORT_GEOMETRY);
view.setDepthBufferFreezeTransparent(false);

Seems to solve the problem for me.  I presume there is some ghastly hidden pitfall I should be wary of.  Lighting still a problem, mind.
Offline Mike Jacobs

Junior Duke





« Reply #9 - Posted 2005-09-15 15:08:41 »

...have any idea what could cause diffuse lighting to switch from 100 to 0% across an entire model depending on which way you look at it (except, for some bizarre reason, a tiny patch on the left rim of the helmet?))

The diffuse lighting effects are based on the vertex normals.  I have seen similar artifacts when the vertex normals are incorrect. 

Mike

Special Effects for Java 3D games: http://www.indietechnologies.com
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Alfryd

Junior Duke





« Reply #10 - Posted 2005-09-15 16:35:05 »

Quote
The diffuse lighting effects are based on the vertex normals.  I have seen similar artifacts when the vertex normals are incorrect.
I'm almost certain that's not the problem, as the diffuse lighting changes when the view rotates, which should, in theory, have no effect on the normals.  Still, I'll investigate.

Oh- one other item- is there some relatively inexpensive method of applying antialising just to the edges of the triangles, to avoid jag artifacts against the background?
Offline tom
« Reply #11 - Posted 2005-09-16 03:17:03 »

There's not much new information, but on the left you have the figure without Transparency Blending, which is comparatively easy on the eye (or would be if diffuse lighting were working correctly,) on the right, the problems occur.

It looks like the arms is not shown on the right. But why are you using Transparency Blending. The texture looks all opaque. Seems to me like your trying to do something the wrong way.

Quote
That should prove most useful, if I knew where and how to access and sort the geometry in this fashion, though I'm reasonably confident I can figure out the Appearance class.  Could you point me in the right direction on the class/methods needed?

Have a look at javax.media.j3d.GeometryUpdater. Given the information in the javadoc you should find out how to change the verteces of a model.

Btw. RenderingAttributes contains the functions needed to manipulate alpha and depth buffer. View.setDepthBufferFreezeTransparent(boolean) overrides the attribute on the transparent pass. It's nice they have added this. When I used Java3D last sorting of transparent Shape3D was not implemented yet. It sucked.

Offline Jeff

JGO Coder




Got any cats?


« Reply #12 - Posted 2005-09-16 05:42:50 »

So is this solved?  I have transparency working perfectly for NWN environments.  I can cli pthe JNWN code and post it if it would be helpful.  (Or you cna grab the whole source base from jnwn.dev.java.net)   

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Alfryd

Junior Duke





« Reply #13 - Posted 2005-09-16 16:13:18 »

Having checked the normals at runtime, they don't seem to have been obviously tampered with.  Lighting is still off.  I'm going to download kduling's viewer code again and see if I get the same bug.
Quote
It looks like the arms is not shown on the right. But why are you using Transparency Blending. The texture looks all opaque. Seems to me like your trying to do something the wrong way.
More than that, the shield is on the opposite side of the body from where it should be and the back of the head is visible through the helm.  This texture is almost completely opaque, yes, but other models I've produced rely heavily on transparency support.
Quote
Have a look at javax.media.j3d.GeometryUpdater. Given the information in the javadoc you should find out how to change the verteces of a model.
I've been using that for geometry-by-reference (though that's changed, but vertices were in correct order, witness the fact they displayed fine without transparency blended, they just weren't being displayed in that order.
Quote
View.setDepthBufferFreezeTransparent(boolean) overrides the attribute on the transparent pass. It's nice they have added this. When I used Java3D last sorting of transparent Shape3D was not implemented yet. It sucked.
Excellent... <steeples fingers>
Quote
So is this solved?  I have transparency working perfectly for NWN environments.  I can cli pthe JNWN code and post it if it would be helpful.  (Or you cna grab the whole source base from jnwn.dev.java.net)
Much appreciated, I'll go download the source.  You didn't run into any problems with lighting, did you?
Offline tom
« Reply #14 - Posted 2005-09-16 19:50:53 »

Quote
More than that, the shield is on the opposite side of the body from where it should be and the back of the head is visible through the helm.  This texture is almost completely opaque, yes, but other models I've produced rely heavily on transparency support.

Try to split the model into opaque and transparent parts and use 2 different textures. Don't use blending on the opaque texture. That would solve most of the blending problems.

Offline Alfryd

Junior Duke





« Reply #15 - Posted 2005-09-16 21:19:49 »

Quote
Try to split the model into opaque and transparent parts and use 2 different textures. Don't use blending on the opaque texture. That would solve most of the blending problems.
It seems to be working well at the moment, but you're right, a mixed approach would do no harm.
Quote
The diffuse lighting effects are based on the vertex normals.  I have seen similar artifacts when the vertex normals are incorrect.
Although it doesn't explain the bug I had with lighting before, when I used the Viewer code:
http://home.earthlink.net/~kduling/Milkshape/Viewer.java
I did discover that the normals were oscillating madly.  I had forgotten to reset them to default values before joint rotation.  After that, it works fine.  Mea culpa.

Thank you all for your assistance, it was extremely helpful.
Offline Mithrandir

Senior Duke




Cut from being on the bleeding edge too long


« Reply #16 - Posted 2005-09-19 21:21:18 »

Looking at that picture, it appears as though all your normals are back to front to what they should be.  This is pretty typicaly of the loader code reading triangles assuming clockwise ordering and J3D is rendering them using anticlockwise.

The site for 3D Graphics information http://www.j3d.org/
Aviatrix3D JOGL Scenegraph http://aviatrix3d.j3d.org/
Programming is essentially a markup language surrounding mathematical formulae and thus, should not be patentable.
Offline Alfryd

Junior Duke





« Reply #17 - Posted 2005-09-20 04:56:28 »

Worry not, it's working fine atm.  No complaints here.
Offline Alfryd

Junior Duke





« Reply #18 - Posted 2005-09-26 06:15:33 »

Right.  Terrain display is now causing headaches, probably because this is my first attempt at actually using large-scale transparency blending.  At the rate this is going, I'll have to make Jeff and Tom honorary authors for the code.
Quote
I have transparency working perfectly for NWN environments.  I can cli pthe JNWN code and post it if it would be helpful.
On consideration, that would be greatly appreciated, rather than having to review the code at length.  If you wouldn't mind.

As far as I can tell, the real problem here is that the polygons I'm using to 'fringe' the terrain tiles are very close to the basic surface, so J3D has difficulty depth-sorting them properly.  I can't think of any simple remedy, though "...rendering the geometry twice. First only processing opaque pixels with depth write on. The second pass rendering only transprent pixels with depth write off",  would probably help.
I've attached a screenshot of the problem, and the terrain texture files.  Grass should overlap on stone.  The texture files have a central tile piece corresponding to UV (1/6, 1/6) to (1/3, 1/3), while fringe pieces adjoin this square.
Any thoughts?
Offline Alfryd

Junior Duke





« Reply #19 - Posted 2005-09-26 06:43:06 »

I find that disabling the depth buffer under RenderAttributes helps significantly with the 'blackouts.'  Does nothing for depth-sorting, of course.

Edit:  Also, I think the problems with depth-sorting are not due to the closeness of the surfaces.  I increased their seperation from 0.015x16 to 0.25x16, to the point where it was easily visible from man angles, and still find that about half the fringe polys were being hidden.
Offline tom
« Reply #20 - Posted 2005-09-26 18:18:45 »

In this case you can use OrderedGroup to do the sorting. Render the terrain before everyting else. You can also use OrderedGroup to render the terrain layers in a particular order. The first terrain layer (rock maybe?) must enable depth write and process all pixels even the transparent ones. The idee is to fill the depth buffer on the first layer. The next layers must be rendered with the exact same vertices as the first layer(very important), but only process pixels with equal depth. Offsetting the layers like you described is not the way to go.

Offline Jeff

JGO Coder




Got any cats?


« Reply #21 - Posted 2005-09-27 03:45:50 »

Do you really need to do this by putting one poly omtop of another? Cant you just multi-texture a single poly.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Alfryd

Junior Duke





« Reply #22 - Posted 2005-09-27 07:30:57 »

Quote
Do you really need to do this by putting one poly omtop of another? Cant you just multi-texture a single poly.
After a little research and experimentation, it seems that multi-texturing averages out the texel values (which simply resulted in ~97% transparent tiles,) whereas what I'm looking for is proper alpha-compositing.  If you know how to do this, I'd be most indebted.
Quote
In this case you can use OrderedGroup to do the sorting.
Why so I can.  Had I but known.
Quote
Render the terrain before everyting else. You can also use OrderedGroup to render the terrain layers in a particular order. The first terrain layer (rock maybe?) must enable depth write and process all pixels even the transparent ones. The idee is to fill the depth buffer on the first layer. The next layers must be rendered with the exact same vertices as the first layer(very important), but only process pixels with equal depth. Offsetting the layers like you described is not the way to go.
I think that can be arranged.  One question.  "But only process pixels with equal depth."  As far as I can gather the RenderAttributes works on the basic of alpha values, not a z-buffer.  Where would I find the method for this?
Meanwhile, I'll tinker around and see what results I get.
Offline Alfryd

Junior Duke





« Reply #23 - Posted 2005-09-27 11:46:00 »

Ah, it's functioning perfectly now.  BTW, there seems to be a specific class for this purpose- DecalGroup.  Many thanks.
Offline Jeff

JGO Coder




Got any cats?


« Reply #24 - Posted 2005-10-01 03:42:22 »

Caveat:  I haven't done anything with multi-texturing myself.

Belief: I believe the OP used for multi-texturing is actually settable and that all the standard OGL OPs are supported...

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline NVaidya

Junior Duke




Java games rock!


« Reply #25 - Posted 2005-10-01 19:28:47 »

The  MultiTexture Combine mode for blending 2 textures should be useful here I'd think - may be that's what Jeff has been suggesting. You might want to  look at TextureAttributes.COMBINE and specifically TextureAttributes.COMBINE_INTERPOLATE modes or may be some variants of it.
As a simple case, if you've 2 opaque textures and want to blend them in using a uniform blending factor then you could use the combine mode and set a TextureBlendColor of ( 0, 0, 0, blendFactor ).

This is a snapshot (from Java 3D) showing 2 textures - colormap + advection - with a blend factor of 0.7:
Click to Play



And this with a blend factor of 0.92:
Click to Play



It runs at about 12 FPS on a 6600GT with a 2048^2 texture + continuous offscreen rendering + noise texture cycling.

Gravity Sucks !
Offline Alfryd

Junior Duke





« Reply #26 - Posted 2005-10-02 12:29:23 »

Quote
The  MultiTexture Combine mode for blending 2 textures should be useful here I'd think - may be that's what Jeff has been suggesting. You might want to  look at TextureAttributes.COMBINE and specifically TextureAttributes.COMBINE_INTERPOLATE modes or may be some variants of it.
COMBINE_PREVIOUS_TEXTURE_UNIT_STATE and COMBINE_ONE_MINUS_SRC_ALPHA seem to be the most promising, but I haven't tested that out yet, and there seem to be quite a few combinations of plausible options.  I wish there were more thorough documentation on this point.  I should probably look over the OpenGL api.
One other problem-  I never seemed to be able to add more than 4 layers of texture to a single Appearance object, it always spat out an ArrayIndexOutOfBoundsException if I introduced another TextureUnitState beyond that.  Is there some way I can increase this limit, or is it enforced by the hardware?
Offline Mike Jacobs

Junior Duke





« Reply #27 - Posted 2005-10-02 16:04:45 »

Quote
One other problem-  I never seemed to be able to add more than 4 layers of texture to a single Appearance object, it always spat out an ArrayIndexOutOfBoundsException if I introduced another TextureUnitState beyond that.  Is there some way I can increase this limit, or is it enforced by the hardware?

The number of texture unit states is based on your video card.  The number can be found by querying the textureUnitStateMax property on the Canvas3D.

Mike

Special Effects for Java 3D games: http://www.indietechnologies.com
Offline Alfryd

Junior Duke





« Reply #28 - Posted 2005-10-04 12:11:15 »

Quote
The number of texture unit states is based on your video card.  The number can be found by querying the textureUnitStateMax property on the Canvas3D.
I see.  No, I'll have to go with the DecalGroup approach then, doing the fringe overlays correctly alone could require up to 9 texture layers, though that would be a fairly pathological case.  Building splats, SFX and footrpints, etc, on top of that could require more.  I'll just fake it by introducing a few extra polys at runtime as neccesary.  Thanks anyway.
Pages: [1]
  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.

Longarmx (44 views)
2014-10-17 03:59:02

Norakomi (34 views)
2014-10-16 15:22:06

Norakomi (27 views)
2014-10-16 15:20:20

lcass (31 views)
2014-10-15 16:18:58

TehJavaDev (61 views)
2014-10-14 00:39:48

TehJavaDev (61 views)
2014-10-14 00:35:47

TehJavaDev (51 views)
2014-10-14 00:32:37

BurntPizza (67 views)
2014-10-11 23:24:42

BurntPizza (39 views)
2014-10-11 23:10:45

BurntPizza (81 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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