[SOLVED] overlapping textures alpha blending not working

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
supadenz
Halfling
Posts: 41
Joined: Sat Feb 16, 2013 2:18 am
x 1

[SOLVED] overlapping textures alpha blending not working

Post by supadenz »

Edit: Oh, This is in Ogre 1.9, using GLES2 on IOS.

I have a character that is rigged in maya and exported to ogre. It is essentially a bunch of quads rigged to a skeleton and textured. In Maya, it looks like this:
Screen Shot 2013-11-22 at 4.42.07 PM.png
Screen Shot 2013-11-22 at 4.42.07 PM.png (128.8 KiB) Viewed 3396 times
In ogre, each quad piece (face, leg, hand, etc) is an entity. They all have a similar material applied, just with a different texture. The material scripts look something like this:

Code: Select all

material LShoulderMaterial
{
        technique
        {
                pass
                {
                        ambient 0 0 0 1
                        specular 0 0 0 1 89.6
                        scene_blend alpha_blend

                        texture_unit
                        {
                                texture L_Shoulder.png
                        }
                }

        }

}
In ogre, when all the entities render, it looks like this. Note that the green color is the background. The entities are depth sorted correctly, note that the brows are over the face. But when they render, each piece does not get the contributing color from the texture behind it, only the background.
Screen Shot 2013-11-22 at 4.42.41 PM.png
Screen Shot 2013-11-22 at 4.42.41 PM.png (63.5 KiB) Viewed 3396 times
If i turn depth checking or writing off, by doing either:

Code: Select all

                entity->getSubEntity(0)->getMaterial()->setDepthWriteEnabled(false);
                entity->getSubEntity(0)->getMaterial()->setDepthCheckEnabled(false);
it looks like this. The alpha blending seems correct, but the quads render in the wrong order.
Screen Shot 2013-11-22 at 4.43.25 PM.png
Screen Shot 2013-11-22 at 4.43.25 PM.png (76.44 KiB) Viewed 3396 times
Am I missing something about depth sorting and transparency here? This seems like it should just be working...
Last edited by supadenz on Wed Nov 27, 2013 8:37 pm, edited 1 time in total.
scrawl
OGRE Expert User
OGRE Expert User
Posts: 1119
Joined: Sat Jan 01, 2011 7:57 pm
x 216

Re: overlapping textures alpha blending not working as expec

Post by scrawl »

Ogre sorts based on the scene node position. Are you maybe attaching all entities to scene nodes with the same position?
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: overlapping textures alpha blending not working as expec

Post by Kojack »

There are several conditions for ogre to enable depth sorting of transparent objects.
You need:
- a source of alpha
- an alpha blending mode
- either depth check or depth write set to false (colour write set to false works too iirc)

When both depth check and write are true, no depth sorting is performed. Ogre renders in an order based on the way the scenenodes are iterated (it uses maps, so probably alphabetical by node name for sibling nodes).

You can manually control the rendering order using setRenderQueueGroup() or setRenderQueueGroupAndPriority() on the entity. A group is a numeric value from 0 to 105, where 50 is the default for all objects. Higher numbers render later. Priority gives you finer grain access to sorting. It's a value from 0 to 65535 that controls sorting within a single group. The default for priority is 100.
supadenz
Halfling
Posts: 41
Joined: Sat Feb 16, 2013 2:18 am
x 1

Re: overlapping textures alpha blending not working as expec

Post by supadenz »

Kojack wrote:There are several conditions for ogre to enable depth sorting of transparent objects.
You need:
- a source of alpha
- an alpha blending mode
I have both textures with alpha and scene blending set to alpha blend
- either depth check or depth write set to false (colour write set to false works too iirc)

When both depth check and write are true, no depth sorting is performed. Ogre renders in an order based on the way the scenenodes are iterated (it uses maps, so probably alphabetical by node name for sibling nodes).
can you elaborate on this? based on my example, it seems to do the proper depth sorting based on the position values in my nodes if they are both on, but just not the right, uhmm, transparencey compositing if you will.
if i set either or both to false, then it seems to depth sort in an arbitrary order, and upon further examination after reading your response, yes, it seems to be name based. but given the incorrect order it renders in, at least the transparency effect works correctly *for that ordering*.
basically, screenshot 2 has the right ordering but weird transparency issues, while screenshot 3 has the wrong order but the right transparecy effect.
You can manually control the rendering order using setRenderQueueGroup() or setRenderQueueGroupAndPriority() on the entity. A group is a numeric value from 0 to 105, where 50 is the default for all objects. Higher numbers render later. Priority gives you finer grain access to sorting. It's a value from 0 to 65535 that controls sorting within a single group. The default for priority is 100.
I can perhaps programatically do this manual sorting based on the initial position in my base pose, but this seems like something i should not have to do. It might be ok in this case because I believe that per character, relative positions will be fixed, but if I get multiple characters on screen with animations specifying positions, this gets much more complicated and would require dynamically updating render groups and priorities every frame!
supadenz
Halfling
Posts: 41
Joined: Sat Feb 16, 2013 2:18 am
x 1

Re: [SOLVED] overlapping textures alpha blending not working

Post by supadenz »

ok..

so the solution was simply to turn depth checking off in my passes..

*HOWEVER* the reason things seemed out of order is because the delta in z between cards was too small. it worked ok in maya but for ogre i needed to bump the distance up.
sdong21
Gnoblar
Posts: 7
Joined: Sat Oct 04, 2014 1:48 pm

Re: [SOLVED] overlapping textures alpha blending not working

Post by sdong21 »

So, have you got any solution for this problem? The alpha blended parts cannot do depth sorting correctly for GLES2, but it works fine for windows platform.
Post Reply