Ogre"polygon transparency sorting"

Problems building or running the engine, queries about how to use features etc.
vagase
Gnoblar
Posts: 7
Joined: Wed Nov 26, 2008 3:14 pm

Ogre"polygon transparency sorting"

Post by vagase »

Hi , guys.
I've got a prob. I made a model with maya 8.5(with skeleton animation , transparent texture).And export with Maya Ogre exporter.
But after I imported the model, it didn't appear the same as expected.And you can see that:
Image
Image

You may find that in pictures, the model's leg and arms are not rendered right.It just go through!Oops...

The prob is that the model's transparent texture can not be rendered well. And this effect is the same as, in Maya, you don't choose the option "Shading->Polygon Transparency Sorting".
I don't how could this happen and how the fix it....

Did any guy meet this case before? And how did you solve it?Plz let me know.

Thank you so much!

==========================================================================================
Here is the content of my material file:

Code: Select all

material lambert7
{
	technique
	{
		pass
		{
			ambient 0 0 0 1
			diffuse 1 1 1 1
			specular 0.2 0.2 0.2 6.4
			emissive 0 0 0

			scene_blend alpha_blend
			depth_write off

			texture_unit
			{
				texture leg.tif
				tex_coord_set 0
				colour_op modulate
				scale 1 1
				scroll 0 0
				rotate 0
			}
		}
	}
}
material lambert4
{
	technique
	{
		pass
		{
			ambient 0 0 0 1
			diffuse 1 1 1 1
			specular 0.2 0.2 0.2 6.4
			emissive 0 0 0

			texture_unit
			{
				texture face.tif
				tex_coord_set 0
				colour_op modulate
				scale 1 1
				scroll 0 0
				rotate 0
			}
		}
	}
}
material lambert6
{
	technique
	{
		pass
		{
			ambient 0 0 0 1
			diffuse 1 1 1 1
			specular 0.2 0.2 0.2 6.4
			emissive 0 0 0

			scene_blend alpha_blend
			depth_write off

			texture_unit
			{
				texture body.tif
				tex_coord_set 0
				colour_op modulate
				scale 1 1
				scroll 0 0
				rotate 0
			}
		}
	}
}
material lambert8
{
	technique
	{
		pass
		{
			ambient 0 0 0 1
			diffuse 1 1 1 1
			specular 0.2 0.2 0.2 6.4
			emissive 0 0 0

			texture_unit
			{
				texture hand.tif
				tex_coord_set 0
				colour_op modulate
				scale 1 1
				scroll 0 0
				rotate 0
			}
		}
	}
}
material lambert5
{
	technique
	{
		pass
		{
			ambient 0 0 0 1
			diffuse 1 1 1 1
			specular 0.2 0.2 0.2 6.4
			emissive 0 0 0

			scene_blend alpha_blend
			depth_write off

			texture_unit
			{
				texture hair.tif
				tex_coord_set 0
				colour_op modulate
				scale 1 1
				scroll 0 0
				rotate 0
			}
		}
	}
}
Last edited by vagase on Thu Feb 19, 2009 4:47 am, edited 1 time in total.
User avatar
Moohasha
Gnoll
Posts: 672
Joined: Fri Dec 07, 2007 7:37 pm
x 8

Re: Ogre"polygon transparency sorting"

Post by Moohasha »

Does your material scrpit have depth_check off? If so, the depth buffer is not checked before rendering a pixel and pixels that should be behind other pixels may be in front of them.
Black holes are where God divided by 0
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 9

Re: Ogre"polygon transparency sorting"

Post by nullsquared »

Ogre doesn't sort per-polygon, that would be very slow.

Instead - split your mesh into two parts, the hair and the body. The body is not transparent, but the hair is - therefore, only the hair should have "depth_write off".
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: Ogre"polygon transparency sorting"

Post by xavier »

Actually, the shaders in Maya will already cause split meshes (submeshes really), since the shader applied to the hair will be different than the one applied to the rest of the body.

The Maya exporter should pick this up -- if there is transparency in the shader, then it puts the depth-write-off/depth-check-on/alpha-blend flags in the material script (and vice versa).

Now, if the whole body is using one texture (or if they both have alpha channels), then you have problems (the ones you are seeing) -- both of these objects share an origin and there is no way of telling which one should be "in front".

My suggestion is, that since you don't have any need for alpha in the body texture, that you either eliminate the alpha channel from its texture (make it RGB instead of RGBA), or change the body shader's "transparency" attribute from using a texture to just being a normal color (and leave the value at 0).
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
vagase
Gnoblar
Posts: 7
Joined: Wed Nov 26, 2008 3:14 pm

Re: Ogre"polygon transparency sorting"

Post by vagase »

Moohasha wrote:Does your material scrpit have depth_check off? If so, the depth buffer is not checked before rendering a pixel and pixels that should be behind other pixels may be in front of them.
I think that doesn't make any sense...
vagase
Gnoblar
Posts: 7
Joined: Wed Nov 26, 2008 3:14 pm

Re: Ogre"polygon transparency sorting"

Post by vagase »

nullsquared wrote:Ogre doesn't sort per-polygon, that would be very slow.

Instead - split your mesh into two parts, the hair and the body. The body is not transparent, but the hair is - therefore, only the hair should have "depth_write off".
Does that really work? I have update my material content...you can check that...Thx..
vagase
Gnoblar
Posts: 7
Joined: Wed Nov 26, 2008 3:14 pm

Re: Ogre"polygon transparency sorting"

Post by vagase »

xavier wrote:Actually, the shaders in Maya will already cause split meshes (submeshes really), since the shader applied to the hair will be different than the one applied to the rest of the body.

The Maya exporter should pick this up -- if there is transparency in the shader, then it puts the depth-write-off/depth-check-on/alpha-blend flags in the material script (and vice versa).

Now, if the whole body is using one texture (or if they both have alpha channels), then you have problems (the ones you are seeing) -- both of these objects share an origin and there is no way of telling which one should be "in front".

My suggestion is, that since you don't have any need for alpha in the body texture, that you either eliminate the alpha channel from its texture (make it RGB instead of RGBA), or change the body shader's "transparency" attribute from using a texture to just being a normal color (and leave the value at 0).
I have pasted my material file,Plz give me some instructions after you reading that.
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: Ogre"polygon transparency sorting"

Post by xavier »

See this?

Code: Select all

         scene_blend alpha_blend
         depth_write off

         texture_unit
         {
            texture body.tif
That is what I am talking about. You are exporting the body shader as if it is transparent.

Go to the body shader and remove the map connection from the transparency attribute. Then re-export.
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
vagase
Gnoblar
Posts: 7
Joined: Wed Nov 26, 2008 3:14 pm

Re: Ogre"polygon transparency sorting"

Post by vagase »

xavier wrote:See this?

Code: Select all

         scene_blend alpha_blend
         depth_write off

         texture_unit
         {
            texture body.tif
That is what I am talking about. You are exporting the body shader as if it is transparent.

Go to the body shader and remove the map connection from the transparency attribute. Then re-export.
But without transparency, I think it is impossible to do this , like hair:

*This is what i want , that when rendered in maya:
Image
But result in ogre is :
Image

You look that, the front side is not the same as what it should be....OMG...
Last edited by vagase on Fri Feb 20, 2009 10:38 am, edited 2 times in total.
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: Ogre"polygon transparency sorting"

Post by xavier »

Given that you have a different material for hair (the one that uses the hair texture) I think it's safe to say that the material you use for the body (that uses the body texture) doesn't need alpha. I don't see anywhere on that model's body where alpha blending is being used.

Seriously, please, just do what I suggest. Remove the alpha from the body. It will be fine. You can probably remove it from everything else too (I recall seeing it in use for the leg). Leave it for the hair, which does use alpha. It will all "just work" then.
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
User avatar
Moohasha
Gnoll
Posts: 672
Joined: Fri Dec 07, 2007 7:37 pm
x 8

Re: Ogre"polygon transparency sorting"

Post by Moohasha »

Using scene_blend alpha_blend shouldn't hurt anything if everything has an alpha value of 1. I think the problem is depth_write off. That prevents that pass from updating the depth buffer, so future depth checks may cause something else to be rendered in front of it instead of behind.
Black holes are where God divided by 0
lvella
Kobold
Posts: 35
Joined: Thu Nov 27, 2008 3:58 am

Re: Ogre"polygon transparency sorting"

Post by lvella »

This is a doubt I have. Simply passing "depth_write off" is not a solution to meshes with transparent materials; it will only allow objects behind a transparent one be drawn over it, with no blending. The way to handle transparent objects is to drawn them after drawing the opaque ones and, in case of multiple transparent objects, the farthest ones first.

This way, unless in some configurations where transparent objects overlaps other objects, "depth_write off" will make no difference.

The problem is that I don't know how to make Ogre sort the transparent meshes... do you?
User avatar
Moohasha
Gnoll
Posts: 672
Joined: Fri Dec 07, 2007 7:37 pm
x 8

Re: Ogre"polygon transparency sorting"

Post by Moohasha »

lvella wrote:...it will only allow objects behind a transparent one be drawn over it, with no blending.
Yes and no. depth_write off can have good results on transparent objects, but it can have really bad results when used with solid objects. Try updating the material for the Ogre skin to use depth_write off and render several Ogre heads in a scene. Things will get ugly. I was telling him to take depth_write off OUT for the solid materials because it's not needed.
Ivella wrote:The problem is that I don't know how to make Ogre sort the transparent meshes... do you?
I'm pretty sure you can't.
Black holes are where God divided by 0
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 9

Re: Ogre"polygon transparency sorting"

Post by nullsquared »

lvella wrote:This is a doubt I have. Simply passing "depth_write off" is not a solution to meshes with transparent materials; it will only allow objects behind a transparent one be drawn over it, with no blending. The way to handle transparent objects is to drawn them after drawing the opaque ones and, in case of multiple transparent objects, the farthest ones first.

This way, unless in some configurations where transparent objects overlaps other objects, "depth_write off" will make no difference.

The problem is that I don't know how to make Ogre sort the transparent meshes... do you?
Ogre does sort the transparent meshes. Your problem is that the body material has depth_write off, even though it is not alpha blended. Get rid of depth_write off for the body material and keep it only for the hair material.
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 6
Contact:

Re: Ogre"polygon transparency sorting"

Post by haffax »

Ivella wrote:The problem is that I don't know how to make Ogre sort the transparent meshes... do you?
I'm pretty sure you can't.
Of course you can.

All objects with a material's pass set to depth_write off are drawn after meshes without depth_write off. Sorted back to front. The blending is done using the scene_blend alpha_blend operation in the same pass. Or any other blending operation, if you need something else than alpha blending. Ogre manual section 3.1 has the details.
team-pantheon programmer
creators of Rastullahs Lockenpracht
lvella
Kobold
Posts: 35
Joined: Thu Nov 27, 2008 3:58 am

Re: Ogre"polygon transparency sorting"

Post by lvella »

haffax wrote:All objects with a material's pass set to depth_write off are drawn after meshes without depth_write off. Sorted back to front. The blending is done using the scene_blend alpha_blend operation in the same pass. Or any other blending operation, if you need something else than alpha blending. Ogre manual section 3.1 has the details.
I didn't know of this, maybe this info should be made clear in the manual.
There was something wrong with the scene I built one day, because I passed "depth_write off" and it was clear that the transparent object was being blended with the skycube, but not with the other objects behind it, maybe because I was using the new portal scene manager and the objects behind were in another zone.
Moohasha wrote: Yes and no. depth_write off can have good results on transparent objects, but it can have really bad results when used with solid objects. Try updating the material for the Ogre skin to use depth_write off and render several Ogre heads in a scene. Things will get ugly. I was telling him to take depth_write off OUT for the solid materials because it's not needed.
I agree with you about disabling depth buffer write on opaque objects, it is clearly the case in the pictures posted by the author of the topic, but I didn't knew that this option in ogre affected the drawing order of the objects, that's why I didn't understand why using it on transparent objects.
nullsquared wrote: Ogre does sort the transparent meshes. Your problem is that the body material has depth_write off, even though it is not alpha blended. Get rid of depth_write off for the body material and keep it only for the hair material.
Wrong guy. I am not the author of the topic. :D
But after so many converging opinions, he must have solved the problem.
vagase
Gnoblar
Posts: 7
Joined: Wed Nov 26, 2008 3:14 pm

Re: Ogre"polygon transparency sorting"

Post by vagase »

Thanks to all~~~I do appreciate that so many people focus on the matter...

But do you guys notice the hair...the bang should be at the front of hair, but err...It is covered by other hair...I really don't know how to solve the prob...BTW, if Ogre doesn't sort meshs or polygons, is there a alternative to do the hair style like this one...
User avatar
xadhoom
Minaton
Posts: 973
Joined: Fri Dec 28, 2007 4:35 pm
Location: Germany
x 1

Re: Ogre"polygon transparency sorting"

Post by xadhoom »

Hi vagase!

Maybe you missed the important point in the suggestions here.
Use 2 Materials for your character.
One for the completely opaque body material (I think everything except the transparent hair would use it) and one transparency enabled material for the hair itself!

If you do this in your modelling tool the exported mesh will contain a character mesh with two submeshes. In this case Ogre will sort the hair submesh
to the end of the renderqueue (because it has the transparent flag set). This shouldsolve the issues you have in the picture.

xad

PS: Setting the depth-write off in the transparent material is necessary for dealing with multiple transparent faces behind each other.
Chaster
OGRE Expert User
OGRE Expert User
Posts: 557
Joined: Wed May 05, 2004 3:19 pm
Location: Portland, OR, USA
Contact:

Re: Ogre"polygon transparency sorting"

Post by Chaster »

Umm, I actually think you're all barking up the wrong tree.

I look at those screenshots and they scream "inverted polys" to me. (i.e. the polygon vertices are in the wrong winding order, resulting in inward facing polygons)... The giveaway is the hollow arm sockets - that's the classic rendering artifact of an inverted tube (the arm).

Of course, I could be wrong - but having seen that many times, that's what it looks like to me...

Chaster
vagase
Gnoblar
Posts: 7
Joined: Wed Nov 26, 2008 3:14 pm

Re: Ogre"polygon transparency sorting"

Post by vagase »

Chaster wrote:Umm, I actually think you're all barking up the wrong tree.

I look at those screenshots and they scream "inverted polys" to me. (i.e. the polygon vertices are in the wrong winding order, resulting in inward facing polygons)... The giveaway is the hollow arm sockets - that's the classic rendering artifact of an inverted tube (the arm).

Of course, I could be wrong - but having seen that many times, that's what it looks like to me...

Chaster
Could you explain a little more... I am really a green hand...
Chaster
OGRE Expert User
OGRE Expert User
Posts: 557
Joined: Wed May 05, 2004 3:19 pm
Location: Portland, OR, USA
Contact:

Re: Ogre"polygon transparency sorting"

Post by Chaster »

(standard disclaimer - I could be wrong, I'm just going by appearances from the screenshots)..

It looks like you have polygons that are facing inwards where they should be facing outwards. For example, the arm. Since the videocard does not draw polygons that face "away" from the camera (hardware culling), when the polygons are facing the "wrong way", the polys that are closest to the camera are not drawn, and polys that are furthest from the camera ARE drawn. So what you are seeing is the polys that are normally hidden.

This is the opposite of what should normally happen. That's why you see the "back" side of the arm instead of the part you should see (which is the polys that would normally be facing you).

An easy way to check if this is indeed the problem is add "cull_hardware none" to the material. It will tell the videocard not to do any hardware culling of polys that face away from the camera. If inverted polys is indeed your problem, then they will show up because Ogre will stop culling them. (you still should fix the problem though).

If this is indeed your problem, you need to go back into your modeling software, and flip those polys (sometimes referred to as "flipping poly normals"). This problem can happen fairly often when newbie artists use mirroring when they make a model.

I hope that helps.

Chaster
NinjaSaru
Gnoblar
Posts: 4
Joined: Tue May 05, 2009 10:56 am

Re: Ogre"polygon transparency sorting"

Post by NinjaSaru »

haffax wrote: All objects with a material's pass set to depth_write off are drawn after meshes without depth_write off. Sorted back to front. The blending is done using the scene_blend alpha_blend operation in the same pass. Or any other blending operation, if you need something else than alpha blending. Ogre manual section 3.1 has the details.
Is this something that you just know, or is there some good source of info that we are missing? I'm really happy I found this post because I just ran into a very similar problem. Actually, I have been wondering how the depth buffer works with transparency for a while now. This note helps a LOT!!! :o
lvella wrote: I didn't know of this, maybe this info should be made clear in the manual.
Yeah, seriously. Now I'm wondering what other really important info I am missing out on. :?
AYYAN
Greenskin
Posts: 117
Joined: Wed May 09, 2007 8:55 am

Re: Ogre"polygon transparency sorting"

Post by AYYAN »

Hi NinjaSaru
read this blog. it gives simple & good details about alpha blending and depth buffer.
http://blogs.msdn.com/etayrien/archive/ ... art-1.aspx

I hope most of you have so much of articles talking about how really transparency works.
please give links here.
NinjaSaru
Gnoblar
Posts: 4
Joined: Tue May 05, 2009 10:56 am

Re: Ogre"polygon transparency sorting"

Post by NinjaSaru »

Cool, thanks for the link!
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: Ogre"polygon transparency sorting"

Post by xavier »

NinjaSaru wrote: Is this something that you just know, or is there some good source of info that we are missing?
haffax wrote: Ogre manual section 3.1 has the details.
The manual isn't there just to look pretty. ;)

http://www.ogre3d.org/docs/manual/manua ... C_Contents
The Manual wrote: Depth writing should normally be on but can be turned off when rendering static backgrounds or when rendering a collection of transparent objects at the end of a scene so that they overlap each other correctly.
One of the things to bear in mind with Ogre, is that while it's certainly easy to get something up quickly and rendering with Ogre, a certain level of understanding about how 3D graphics work is assumed, and is somewhat of a entry criteria to be productive using Ogre (indeed, any 3D graphics library).
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
Post Reply