Again another texure alpha problem

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Kiristu
Posts: 40
Joined: Wed Mar 13, 2013 12:31 am

Again another texure alpha problem

Post by Kiristu »

Hi,

I need to use texture transparency (PNG with alpha) on an object, using a material with shaders.
If I don't use shadersk, I can just use:

Code: Select all

node->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
And the result is OK.

But I need shaders (in particular vertex), and then I use:

Code: Select all

objectMaterial = gpu->addHighLevelShaderMaterialFromFiles(
                        "objects.hlsl", "vertexMain", video::EVST_VS_3_0,
                        "objects.hlsl", "pixelMain", video::EPST_PS_3_0,
                        mc, video::EMT_TRANSPARENT_ALPHA_CHANNEL, 0, shadingLanguage);
 
...
 
u32 mcount = node->getMaterialCount();
for(u32 i = 0; i < mcount - 1; i++)
{
    node->getMaterial(i).BackfaceCulling = false;
}
 
But the result is not correct.

The texture is a kind of grid.
The node is like a watermelon slice, a thick piece of sphere. From "inside", it appears correctly, I see every part of the grid on every faces. From "outside", I can only see the outside, just like it was only a piece of sphere without thickness.
So, from outside, all the object is like hidden by the external faces, even if I can see the rest of the scene through it.
Note I set backface culling to false.

So my question is:
What am I supposed to do if I want the same result with shaders than using setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL) without shaders ?

Thanks,
K.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Again another texure alpha problem

Post by CuteAlien »

Please just paste a screenshot - figuring out what text describing an image exactly means is tricky :-)
Use a service like imgur.com if you don't have an own server for that.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Again another texure alpha problem

Post by hendu »

Please note the EBO_ADD bug in 1.8 and later. You also need to set the blendmode to that for transparency to act reliably.
Kiristu
Posts: 40
Joined: Wed Mar 13, 2013 12:31 am

Re: Again another texure alpha problem

Post by Kiristu »

I tried to set the blendmode to EBO_ADD with:

Code: Select all

node->getMaterial(i).setFlag(EMF_BLEND_OPERATION, true);
(this is what I understood from the source of SMaterial in the documentation)

But the result is the same with or without it.

Here are two screenshots:

1) View from "inside", we can see the other side of the hexagonal grid, this is (mostly, there are some bugs) what I expect
Image

2) View from "outside" (moving the camera on the left), on the left part of the object, we still see the grid through the object, but on the right, only the external side is visible, even if it is transparent (we see the ground behind it)
Image

Maybe it can help to see the object in Blender:
Edition:
Image
Render:
Image

Note it could be related to the Blender model, but it is quite simple (a sphere where I removed some vertices, and then a solidify modifier applied).

Thanks

Edit: Ho I forgot to mention I'm working with XEffects too, that might be important to notice

Edit2: I tried to render without using XEffects and I have the same issue, so I think it is not related to XEffects
Kiristu
Posts: 40
Joined: Wed Mar 13, 2013 12:31 am

Re: Again another texure alpha problem

Post by Kiristu »

Finally, I'm trying to have this transparency work for a simple sphere. But even with this, there is no way to make it work correctly:

Image

As you can see, only some faces are visible.

It's obviously related to the fact I'm using shaders because else with:

Code: Select all

node->setMaterialType(EMT_TRANSPARENT_ALPHA_CHANNEL);
the result is perfect.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Again another texure alpha problem

Post by hendu »

That looks like you have transparent Z-write enabled. Please make a small runnable test-case that shows the issue.
Kiristu
Posts: 40
Joined: Wed Mar 13, 2013 12:31 am

Re: Again another texure alpha problem

Post by Kiristu »

I tried to enable disable ALLOW_ZWRITE_ON_TRANSPARENT in the scene manager without any success.

But I did not try it on the material with EMF_ZWRITE_ENABLE, and setting it to false makes it work !

So thank you, I guess that was the problem, I will have to try with my complex objects but it seems to be ok.
Kiristu
Posts: 40
Joined: Wed Mar 13, 2013 12:31 am

Re: Again another texure alpha problem

Post by Kiristu »

After some new tests, it appears that it solves only partially the problem:

Even if all faces are visible, some back ones are rendered on top of front ones (not every faces). It was not visible until now because it was all black.
It seems that faces that were not visible on previous screenshot are now visible, but "above" the others.

Image

In the blue circle, the small hexagon should be behind the big one.
The big black spot above the blue circle is on top of the sphere, so normally shown here.
The big black spot on top right of the circle is shown behind the red lines, that is not correct (it should be above).

Is there something to set to force Z-order rendering in that case ?

I read on another post that adding:

Code: Select all

smgr->getParameters()->setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true);
and changing to:

Code: Select all

node->setMaterialFlag(EMF_ZWRITE_ENABLE, true);
would work, but it does not. It makes faces disappear like in previous screenshot.

Also, I can't really extract a small part of code to show this, but I will try to load it into "Mesh viewer" (tutorial 9) to see how it works.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Again another texure alpha problem

Post by hendu »

There is no Z-sorting inside an object, as that would be prohibitively expensive for the cpu (per-triangle op!).

So to get such renders on realtime hw, as opposed to a renderer that can do such cpu-heavy things, you need to hack around it. For example, draw your object twice, first with frontface culling enabled and backface disabled, then vice versa.
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Re: Again another texure alpha problem

Post by Klunk »

if you don't need it to be "semi" transparent you could use AlphaRef (EMT_TRANSPARENT_ALPHA_CHANNEL_REF)or you'll need to break the objects up so they can be sorted against each other.
Kiristu
Posts: 40
Joined: Wed Mar 13, 2013 12:31 am

Re: Again another texure alpha problem

Post by Kiristu »

hendu wrote:There is no Z-sorting inside an object
By object do you mean "node" or "mesh" ?
Is it true for a node with several distinct meshes ?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Again another texure alpha problem

Post by hendu »

Node and mesh are the same thing really, for the purposes of this discussion. One node cannot have multiple meshes.

I think you mean it has multiple meshbuffers. There is no Z sorting between meshbuffers.
Kiristu
Posts: 40
Joined: Wed Mar 13, 2013 12:31 am

Re: Again another texure alpha problem

Post by Kiristu »

OK, I understand better those kind of glitches I have.

Well, I think I'll have to extend the node class and render back faces then front faces.

However, I'm surprised that a special development is needed because we see quite often in games semi-transparent objects such as cars or even wire fencing.

Thanks for all your answers.
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Re: Again another texure alpha problem

Post by Klunk »

I'm surprised that a special development is needed because we see quite often in games semi-transparent objects such as cars or even wire fencing..
I've worked on many games and one of the biggest headaches is always alpha sorting.
Kiristu
Posts: 40
Joined: Wed Mar 13, 2013 12:31 am

Re: Again another texure alpha problem

Post by Kiristu »

It seems that everything in a game finally ends with "it's the biggest headache to do" :lol:

OK another good thing to know, I'll try to avoid it if possible.

Thanks again.
Post Reply