Ogre 1.8: Emulating FFP alpha test with RTSS in GLES2

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
mannam
Halfling
Posts: 45
Joined: Tue Feb 15, 2011 7:23 am

Ogre 1.8: Emulating FFP alpha test with RTSS in GLES2

Post by mannam »

Hi all,

RT Shader System in 1.8 can emulate fixed function pipeline (FFP) and it works in most of the case, except alpha test enabled materials (alpha_rejection).

Anyone knows how to make it works with alpha test ?

If this is not officially supported, what's the direction if I want to do it myself? e.g. adding alpha test sub render state? Adding alpha test techniques like "BaseWhite", "BaseWhiteNoLighting"?

Thanks.
Last edited by mannam on Wed Aug 01, 2012 9:08 am, edited 1 time in total.
oiram
Halfling
Posts: 87
Joined: Sun Dec 13, 2009 5:06 am
x 6

Re: Ogre 1.8: Emulating FFP alpha test with RT Shader System

Post by oiram »

use " if (alpha < 0.1) discard;" in fragment shader.
mannam
Halfling
Posts: 45
Joined: Tue Feb 15, 2011 7:23 am

Re: Ogre 1.8: Emulating FFP alpha test with RT Shader System

Post by mannam »

Yes, I can use this approach to write shaders.

But my situation is, most of my old projects are based on FFP materials. I want to port them to 1.8 without converting all materials manually. My thought is using Shader Generator in RT Shader System to do the conversion. But I found that it does not work for alpha test materials...
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: Ogre 1.8: Emulating FFP alpha test with RT Shader System

Post by al2950 »

I use RTSS with alpha rejection and I dont have a problem! What other sub render states are you enabling at the same time?
mannam
Halfling
Posts: 45
Joined: Tue Feb 15, 2011 7:23 am

Re: Ogre 1.8: Emulating FFP alpha test with RT Shader System

Post by mannam »

I'm using two types of materials, AlphaTest and AlphaBlend. AlphaBlend is fine but AlphaTest not:

Code: Select all

material AlphaTest
{
	technique
	{
		pass
		{
			ambient 1 1 1 1
			diffuse 1 1 1 1
			specular 0.25 0.25 0.25 1 50
			emissive 0 0 0
			
			alpha_rejection greater_equal 128
			cull_hardware none
			cull_software none

			texture_unit
			{
				texture diffuse.png
				tex_coord_set 0
				colour_op modulate
				mipmap_bias -2
				scale 1 1
				scroll 0 0
				rotate 0
			}
		}
	}
}

Code: Select all

material AlphaBlend
{
	technique
	{
		pass
		{
			ambient 1 1 1 1
			diffuse 1 1 1 1
			specular 0.7 0.7 0.7 1 30
			emissive 0 0 0

//			scene_blend alpha_blend
			separate_scene_blend src_alpha one_minus_src_alpha one one 
			depth_write off

			texture_unit
			{
				texture diffuse.png
				tex_coord_set 0
				colour_op modulate
				mipmap_bias -2
				scale 1 1
				scroll 0 0
				rotate 0
			}
		}
	}
}
User avatar
joew
Greenskin
Posts: 113
Joined: Fri Nov 03, 2006 6:03 pm

Re: Ogre 1.8: Emulating FFP alpha test with RT Shader System

Post by joew »

On any iOS device using discard in a shader will seriously destroy performance, you should avoid it at all cost and blend if needed. I'm not sure if this occurs on other devices using chipsets such as Tegra though.
mannam
Halfling
Posts: 45
Joined: Tue Feb 15, 2011 7:23 am

Re: Ogre 1.8: Emulating FFP alpha test with RT Shader System

Post by mannam »

Yes I know this problem. But alpha test is the only choice if I need depth testing the alpha objects.

I wonder why GLES2 handle alpha test in such a backward incompatible manner...
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: Ogre 1.8: Emulating FFP alpha test with RT Shader System

Post by al2950 »

Both materials work for me. Are you running d3d or GL? Also I am running with Per Pixel Lighting as a template sub render state so that might be making a difference, I will have a look later.
mannam
Halfling
Posts: 45
Joined: Tue Feb 15, 2011 7:23 am

Re: Ogre 1.8: Emulating FFP alpha test with RT Shader System

Post by mannam »

I'm running on iPhone with OpenGLES 2.
User avatar
joew
Greenskin
Posts: 113
Joined: Fri Nov 03, 2006 6:03 pm

Re: Ogre 1.8: Emulating FFP alpha test with RT Shader System

Post by joew »

mannam wrote:I wonder why GLES2 handle alpha test in such a backward incompatible manner...
It's actually not a GLES2 issue but with PVR mobile GPUs (and others). Unfortunately if you discard in a shader nearly all optimizations have to be avoided so even calling it once will cause performance issues (for example in our scenes framerate drops from 60 to 36 fps just by calling discard a single time whereas sorting and blending we stay at 60. So with your problem set you are unable to manually sort alpha geometry and blend to avoid alpha testing?
oiram
Halfling
Posts: 87
Joined: Sun Dec 13, 2009 5:06 am
x 6

Re: Ogre 1.8: Emulating FFP alpha test with RTSS in GLES2

Post by oiram »

thanks for your information.
That means alpha blend is better then alpha test on PVR mobile?
Did your team test is on others ogles2 platform?
mannam
Halfling
Posts: 45
Joined: Tue Feb 15, 2011 7:23 am

Re: Ogre 1.8: Emulating FFP alpha test with RTSS in GLES2

Post by mannam »

joew wrote:So with your problem set you are unable to manually sort alpha geometry and blend to avoid alpha testing?
It's possible to sort, but it's hard.

The alpha test object is enclosed in an alpha blend object. To enable sorting, the alpha blend object has to be well subdivided.
User avatar
joew
Greenskin
Posts: 113
Joined: Fri Nov 03, 2006 6:03 pm

Re: Ogre 1.8: Emulating FFP alpha test with RTSS in GLES2

Post by joew »

oiram wrote:thanks for your information.
That means alpha blend is better then alpha test on PVR mobile?
Did your team test is on others ogles2 platform?
Yes, alpha blending is effectively free and alpha test should be avoided in all cases that are possible. This is the case with all current mobile GPUs (at least all the most popular ones), we tested the main 3 being PVR SGX, nVidia Tegra, and ARM Mali and got the same results across the board. This is due to having to skip optimizations and work at the pixel level for depth which normally isn't done on embedded mobile GPUs.
oiram
Halfling
Posts: 87
Joined: Sun Dec 13, 2009 5:06 am
x 6

Re: Ogre 1.8: Emulating FFP alpha test with RTSS in GLES2

Post by oiram »

Thanks! :D
User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 100

Re: Ogre 1.8: Emulating FFP alpha test with RTSS in GLES2

Post by Wolfmanfx »

alpha_rejection is ignored on gles2 RS.
mannam
Halfling
Posts: 45
Joined: Tue Feb 15, 2011 7:23 am

Re: Ogre 1.8: Emulating FFP alpha test with RTSS in GLES2

Post by mannam »

Yes, so I'm finding the simplest way to port old alpha test projects to gles2. I guess RTSS is the choice.