[Fixed] Alpha rejection rejected?

The place for artists, modellers, level designers et al to discuss their approaches for creating content for OGRE.
Post Reply
User avatar
nvision
Halfling
Posts: 62
Joined: Thu Apr 27, 2006 5:31 am

[Fixed] Alpha rejection rejected?

Post by nvision »

Right, so, I've got this tree mesh:
http://www.ece.ualberta.ca/~nrossol/stu ... tree1.mesh
and a texture for it too that contains a lot of alpha:

Image

And I used this material file to bind the texture to the mesh:

Code: Select all

material tree1Material
{
   technique
   {
      pass
      {
         lighting off

         ambient 1 1 1 1
         diffuse 1 1 1 1
         specular 0 0 0 0
         emissive 0 0 0

         alpha_rejection greater 128 //increase number 128 we will get more transparent into object
         depth_write on

         texture_unit
         {
            texture tree1.png
            tex_coord_set 0
            colour_op modulate
         }
      }
   }
}
However, while the mesh does indeed have the tree texture applied to it, for some reason, areas which are supposed to be transparent, are just rendered as solid black like so:

Image

(All other Ogre demos run perfectly fine, and this result is exactly the same whether I'm in OpenGL or Direct3D). Did I make a really obvious classic blunder or something? Is it possibly a property of the mesh that I did incorrectly? If I use alpha_blending instead then the alpha regions are pretty much rendered correctly (except, of course, for the fact that the the depth-testing is all wrong and leaves in the back are being rendered ontop of leaves that are closer.). Sorry if the answer is really obvius, I'm kinda a n00b when it comes to Ogre materials.
Last edited by nvision on Mon Jul 31, 2006 10:06 pm, edited 2 times in total.
Yep, I'm that RTS guy (who mananged to get Ogre to run in Cygwin).
User avatar
independentCreations
Greenskin
Posts: 121
Joined: Sat Jan 07, 2006 7:30 am
Location: Gold Coast - Australia

Post by independentCreations »

i find using a .tga with a transparent background and alpha channel works best, really only have to use the alpha rejection if are getting alpha artifacts left behind. it seems that your image dosnt have any alpha in it may have been discarded when saved
Final Creations - Tech Leader For 'The Broken'
v2i - Tech Leader For Architectual Sim.
Ogre Enthusiast
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 7
Contact:

Post by haffax »

PNG works fine for us for transparent textures. Check what independentCreations proposes and if you do indeed save the alpha channel, check the alpha values. You reject everything with alpha less or equal than 128. Is this the case actually, or is the alpha value on the transparent texture parts higher maybe?
team-pantheon programmer
creators of Rastullahs Lockenpracht
User avatar
Jerky
Orc Shaman
Posts: 791
Joined: Wed Mar 02, 2005 4:13 am
Location: Springville, Utah
Contact:

Post by Jerky »

My PNG's look just fine with the following script. This isnt final for what I want (I eventually want normal maps working with this as well, which requires a custom shader), but it displays the transparency correctly:

Code: Select all

material WillowTree1
{
	receive_shadows on
	technique
	{
		pass
		{
			ambient 0.500000 0.500000 0.500000 1.000000
			diffuse 0.640000 0.640000 0.640000 1.000000
			specular 0.500000 0.500000 0.500000 1.000000 12.500000
			emissive 0.000000 0.000000 0.000000 1.000000
			alpha_rejection greater 150 
			scene_blend alpha_blend
			cull_hardware none
			cull_software none
			texture_unit
			{
				texture Willow_Tex1.png
			}
		}
	}
}
I believe the "scene_blend alpha_blend" portion should do the trick.
Erik Briggs (Jerky)
My Blog
Project Wish
Image
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 7
Contact:

Post by haffax »

scene_blend alpha_blend without depth_write off can and often will result in artifacts, when two of those materials overlap, as depth order is not guaranteed to be correct.

alpha_rejection works fine without alpha_blending. The problem is something different.
team-pantheon programmer
creators of Rastullahs Lockenpracht
User avatar
nvision
Halfling
Posts: 62
Joined: Thu Apr 27, 2006 5:31 am

Post by nvision »

Yeah, I've tried with the image in both tga and png format; the result is the same. Also, I've tried using rejection values from 0 to 255 with both greater than and less than operators; no effect. Do you have to set some variable in the mesh to allow it to have an alpha texture? or are materials completely seperate from the mesh they're applied to?
Yep, I'm that RTS guy (who mananged to get Ogre to run in Cygwin).
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 7
Contact:

Post by haffax »

You don't have to set anything to the mesh. It is all about the material and the texture. alpha_rejection works, I use it all the time without problems. I don't know what is wrong here.
See Ogre.log if there were any problems with your material definition and/or the texture.
team-pantheon programmer
creators of Rastullahs Lockenpracht
User avatar
nvision
Halfling
Posts: 62
Joined: Thu Apr 27, 2006 5:31 am

Post by nvision »

Argh! I found the problem!

You see, I copied that material file from the sample alpha-rejection tutorial on this page:

http://www.ogre3d.org/wiki/index.php/Ma ... parent_map

the issue is the line:

Code: Select all

alpha_rejection greater 128 //increase number 128 we will get more transparent into object
The tutorial had the comment there, but Ogre apparently doesn't support comments like this unless they're on a line of their own. Therefore, the whole line was simply being ignored as a parse error. The correct way to do the comment would have been:

Code: Select all

alpha_rejection greater 128
//increase number 128 we will get more transparent into object
Man, to think I spent days on such a simple bug... Well, the tutorial is a wiki tutorial so I guess I should probably correct that tutorial so that no one else falls for the same error.
Yep, I'm that RTS guy (who mananged to get Ogre to run in Cygwin).
User avatar
Jerky
Orc Shaman
Posts: 791
Joined: Wed Mar 02, 2005 4:13 am
Location: Springville, Utah
Contact:

Post by Jerky »

Heh, nice find. That can be frustrating. Just wait til you start using CEGUI ;).
Erik Briggs (Jerky)
My Blog
Project Wish
Image
VinculumOne
Gnoblar
Posts: 1
Joined: Fri Jul 06, 2012 1:29 pm

Re:

Post by VinculumOne »

Jerky wrote:Heh, nice find. That can be frustrating.
Heh, yes and SORRY for bringing up THAT an old topic.
Just fixed exact same issue in newer tikiwiki http://www.ogre3d.org/tikiwiki/tiki-ind ... =Materials
Funny how long issues sometimes persist when people forget updating the wiki. :lol:

Am just glad it solved the issues I had with one mesh.
cheers and BIG Thank You for the great engine Ogre, I love it :!:
Post Reply