New autoparam ACT_SURFACE_ALPHA_REJECTION_VALUE

Minor issues with the Ogre API that can be trivial to fix
Post Reply
Nodrev
Gremlin
Posts: 193
Joined: Fri Jan 25, 2008 6:55 pm
Location: Nantes / France
x 17

New autoparam ACT_SURFACE_ALPHA_REJECTION_VALUE

Post by Nodrev »

Hello, currently working on a deferred renderer, I came to the alpha rejection integration.
The fact is that there was no autoparam for alpha rejection value, so I added it to Ogre (https://ogre3d.atlassian.net/browse/OGRE-166) because the 2 other solution have huge drawbacks:
- the first one is to set a custom param on each renderable with alpha rejection passes, and use it in the shader for comparison, but changing the value on a pass dynamically is a problem, as we have to find all the renderable that uses this (material) pass, and set the custom parameter again -> unmanageable in real situation...
- the second is to generate a shader for each possible value of alpha rejection -> memory waste, almost identical shaders with only a different const value, that should be a variable value...

So I named this new auto param ACT_SURFACE_ALPHA_REJECTION_VALUE, or 'surface_alpha_rejection_value' in programs scripts.
It binds the alpha rejection value stored in the material pass converting it to a [0.0; 1.0] floating point value:

Code: Select all

autoParamValue = 255.0f / Ogre::Pass::getAlphaRejectionValue();
It shall be very usefull to handle alpha rejection correctly in shadows caster and compositor shaders too.
Last edited by Nodrev on Wed Apr 03, 2013 3:25 pm, edited 1 time in total.
User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 99
Contact:

Re: New autoparam ACT_SURFACE_ALPHA_REJECTION_VALUE

Post by Wolfmanfx »

First that's a good idea but your code will break RTSS so you have to add it there too - also this a new feature so you should base it again 1.9 and make a pull request on bitbucket.
Nodrev
Gremlin
Posts: 193
Joined: Fri Jan 25, 2008 6:55 pm
Location: Nantes / France
x 17

Re: New autoparam ACT_SURFACE_ALPHA_REJECTION_VALUE

Post by Nodrev »

Hi,

Do not know how RTSS works, never used it, I saw there was some autoparam related code there, but I have no idea about side effect adding the autoparam to this component could have, that's why I did not add it for the moment.
As far as I understand, RTSS generates shaders from material definition, so there's certainly some bunch of shader to add (?or not I don't know), something like:

Code: Select all

if (diffuseMapColor.a < alphaRejectionValue)
   discard;
And I did not know about pull request, I though that adding a feature request on jira was sufficient. Do I have to create my own fork to make those "pull requests"???
Nodrev
Gremlin
Posts: 193
Joined: Fri Jan 25, 2008 6:55 pm
Location: Nantes / France
x 17

Re: New autoparam ACT_SURFACE_ALPHA_REJECTION_VALUE

Post by Nodrev »

Ok, I understand now what you mean by breaking the RTSS, I updated RTSS enum so now there's no more offset between auto param enums definitions. Furthemore I updated the manual.
I think I understand how pulling changes to Ogre too, I hope I done it correctly. I added a small bug fix related to GL compilation when using TBB library within the request at the same time, everything in 1.9 branch.
User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 99
Contact:

Re: New autoparam ACT_SURFACE_ALPHA_REJECTION_VALUE

Post by Wolfmanfx »

I have merged your patch but for the next plz one commit per pull request - this time i merged.
Yeah that's what i meant with RTSS.

So great work :)
technique
Halfling
Posts: 91
Joined: Fri Oct 22, 2010 10:46 pm
x 8

Re: New autoparam ACT_SURFACE_ALPHA_REJECTION_VALUE

Post by technique »

I tried to use the new paramter in a RTSS setup on the new Ogre3D 1.9 stable (http://www.ogre3d.org/forums/viewtopic.php?f=10&t=79623).

Its not working if i render the alphaRejection value in a fragment program:

Code: Select all

uniform sampler2D textureSampler;
uniform float alphaRejection;

varying vec4 vp_color;
varying vec2 vp_uv;

void main(void)
{
	vec4 _color = texture2D(textureSampler, vp_uv);
	//if(_color.a < alphaRejection) discard;
	//_color.a = 1.0;
	gl_FragColor = vec4(alphaRejection, alphaRejection, alphaRejection, 1.0);//_color * vp_color;
}

Code: Select all

fragment_program alpha_rejection_fp_glsl glsl
{
	source alpha_rejection_fp.glsl
	param_named_auto textureSampler int 0
	param_named_auto alphaRejection surface_alpha_rejection_value
}
Its just black (0) - so i cant use it to discard a fragment for alpha rejection.

Debug Material:

Code: Select all

material leaf : alpha_rejection
{
	technique
	{
		pass
		{
		
			diffuse 1.0 1.0 1.0 1.0
			ambient 1.0 1.0 1.0 1.0
			specular 1.0 1.0 1.0 1.0
			
			scene_blend alpha_blend
			alpha_rejection greater 254
			
			texture_unit
			{	       	
				texture leaf.png
			}
		}
	}
}
Image
Kingdoms Defender offers Tower Defense action with breathtaking 3-D graphics for your mobile Android device.

Give it a try:
Free-Version:
http://play.google.com/store/apps/detai ... ender_free

Full-Version:
http://play.google.com/store/apps/detai ... msdefender
technique
Halfling
Posts: 91
Joined: Fri Oct 22, 2010 10:46 pm
x 8

Re: New autoparam ACT_SURFACE_ALPHA_REJECTION_VALUE

Post by technique »

Its working now. You have to add the "param_named_auto alphaRejection surface_alpha_rejection_value" parameter to the vertex program skript and add the alphaRejection in both programs. This way the value is set up correct!
Image
Kingdoms Defender offers Tower Defense action with breathtaking 3-D graphics for your mobile Android device.

Give it a try:
Free-Version:
http://play.google.com/store/apps/detai ... ender_free

Full-Version:
http://play.google.com/store/apps/detai ... msdefender
Post Reply