Depth and transparency [SOLVED]

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
aungsithu
Posts: 39
Joined: Thu Sep 04, 2008 2:14 am
Location: Singapore
Contact:

Depth and transparency [SOLVED]

Post by aungsithu »

Hi,
Pardon me as I know a solution for this issue might be somewhere on board.
I just can't find the right solution.
I'm using irrlicht and irredit 1.4.2.

Image
Image

As in image, the trees behind the fence are rendered in front of the fence.
I use trans_alphach as material type for both trees and fence.

How can I fix this problem?

Thanks in advance.
Last edited by aungsithu on Fri Nov 21, 2008 6:50 am, edited 1 time in total.
Aung Sithu
*** Check out my latest book, Beginner's guide to Irrlicht 3D engine: http://bit.ly/rSnm4O
Company: http://rivaledge.sg
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Try playing around with the ZBuffer and ZWriteEnable parameters of the node's material. It's probably ZBuffer set to false that is causing the problem, so try setting it to true.
Image Image Image
aungsithu
Posts: 39
Joined: Thu Sep 04, 2008 2:14 am
Location: Singapore
Contact:

Post by aungsithu »

Thanks.
ZWriteEnable is set to True and ZBuffer is already set to 1 for all the trees and fences. It still doesn't solve the problem and I still see this 'incorrect' rendering in irrEdit.
What did I miss something?
Aung Sithu
*** Check out my latest book, Beginner's guide to Irrlicht 3D engine: http://bit.ly/rSnm4O
Company: http://rivaledge.sg
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You have to use the new scene parameter ALLOW_ZWRITE_ON_TRANSPARENT set to true. This allows to toggle the zwrite flag for transparent materials. If it's not set Irrlicht will override this setting to always false :!:
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Also make sure you're applying the changes to the correct material of the tree... do you just have one material or two... possibly there's two materials if you have seperate materials for the trunk and the leaves ;)
Image Image Image
jontan6
Posts: 278
Joined: Fri Jun 13, 2008 5:29 pm

Post by jontan6 »

quick fix: use trans_alphach_ref, works for me
Frank Dodd
Posts: 208
Joined: Sun Apr 02, 2006 9:20 pm

Post by Frank Dodd »

jontan6 wrote:quick fix: use trans_alphach_ref, works for me
That worked for me too, it has to be changed in both main.cpp and CTreeSceneNode.cpp
aungsithu
Posts: 39
Joined: Thu Sep 04, 2008 2:14 am
Location: Singapore
Contact:

Post by aungsithu »

Thanks all for inputs.
Right now, I'm just using irredit to construct and visualize the scene.
Setting to trans_alpharef make some trees to be correctly rendered.
But some trees are still being rendered in front of the fence.
I'll check the other ways posted here when I render the scene from code.

Thank you all.
Aung Sithu
*** Check out my latest book, Beginner's guide to Irrlicht 3D engine: http://bit.ly/rSnm4O
Company: http://rivaledge.sg
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

DX9?

Post by 3DModelerMan »

Are you using a DirectX driver?. It does'nt seem to happen in OpenGL.
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
aungsithu
Posts: 39
Joined: Thu Sep 04, 2008 2:14 am
Location: Singapore
Contact:

Post by aungsithu »

Yes. Because in irrEdit, there's only D3D9, D3D8 and software driver.
I'll try with OGL again in irrlicht.
Aung Sithu
*** Check out my latest book, Beginner's guide to Irrlicht 3D engine: http://bit.ly/rSnm4O
Company: http://rivaledge.sg
jontan6
Posts: 278
Joined: Fri Jun 13, 2008 5:29 pm

Post by jontan6 »

change all trans_alphach to trans_alphach_ref

opengl should also work
Frank Dodd
Posts: 208
Joined: Sun Apr 02, 2006 9:20 pm

Post by Frank Dodd »

I've been playing about with this a bit today while integrating trees into my wrapper project. Hybrid's advice is the complete solution and I implemented a command in the wrapper to use: -
smgr->getParameters()->setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true);

EMT_TRANSPARENT_ALPHA_CHANNEL_REF does seam to correct the problem but probably only by chance in the implementation, it is however the better option to use as it is intended to be the faster implementation for foliage. It does have the draw back of not being effected by vertex lighting as far as I can see though.

After using ALLOW_ZWRITE_ON_TRANSPARENT as Hybrid suggests, IRR_EMT_TRANSPARENT_ALPHA_CHANNEL also seams to work properly and is effected by vertex lighting too.

When using ALLOW_ZWRITE_ON_TRANSPARENT and EMT_TRANSPARENT_ALPHA_CHANNEL_REF with textures that have alpha channels that contain aliased pixels, these pixels seam to pick up the background color giving them an oddly colored edge. Changing the textures so the alpha value was just 0 or 255 would clear up the problem I think.

Regards,
jontan6
Posts: 278
Joined: Fri Jun 13, 2008 5:29 pm

Post by jontan6 »

[quote="Frank EMT_TRANSPARENT_ALPHA_CHANNEL_REF does seam to correct the problem but probably only by chance in the implementation, it is however the better option to use as it is intended to be the faster implementation for foliage. It does have the draw back of not being effected by vertex lighting as far as I can see though.
[/quote]

yes i know this is by chance, and hybrid advice is correct one. but im too afraid to change source in irrlicht and compile :p
Frank Dodd
Posts: 208
Joined: Sun Apr 02, 2006 9:20 pm

Post by Frank Dodd »

You can place the smgr->getParameters()->setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true); in your own code after your createDevice call, you wont need to change the irrlicht dll.
jontan6
Posts: 278
Joined: Fri Jun 13, 2008 5:29 pm

Post by jontan6 »

ohhh... i thought i need change irrlicht code. i remember someone (i think one of the irrlicht devs) said to change headers or something... forgot the post
Post Reply