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

New autoparam ACT_SURFACE_ALPHA_REJECTION_VALUE

Post by Nodrev » Wed Apr 03, 2013 2:57 pm

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.
0 x

User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 1
Contact:

Re: New autoparam ACT_SURFACE_ALPHA_REJECTION_VALUE

Post by Wolfmanfx » Wed Apr 03, 2013 3:11 pm

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.
0 x

Nodrev
Gremlin
Posts: 193
Joined: Fri Jan 25, 2008 6:55 pm
Location: Nantes / France

Re: New autoparam ACT_SURFACE_ALPHA_REJECTION_VALUE

Post by Nodrev » Wed Apr 03, 2013 3:22 pm

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"???
0 x

Nodrev
Gremlin
Posts: 193
Joined: Fri Jan 25, 2008 6:55 pm
Location: Nantes / France

Re: New autoparam ACT_SURFACE_ALPHA_REJECTION_VALUE

Post by Nodrev » Wed Apr 03, 2013 7:19 pm

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.
0 x

User avatar
Wolfmanfx
OGRE Team Member
OGRE Team Member
Posts: 1525
Joined: Fri Feb 03, 2006 10:37 pm
Location: Austria - Leoben
x 1
Contact:

Re: New autoparam ACT_SURFACE_ALPHA_REJECTION_VALUE

Post by Wolfmanfx » Wed Apr 03, 2013 8:26 pm

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 :)
0 x

technique
Halfling
Posts: 91
Joined: Fri Oct 22, 2010 10:46 pm

Re: New autoparam ACT_SURFACE_ALPHA_REJECTION_VALUE

Post by technique » Sun Dec 01, 2013 3:03 pm

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
			}
		}
	}
}
0 x
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

Re: New autoparam ACT_SURFACE_ALPHA_REJECTION_VALUE

Post by technique » Mon Dec 02, 2013 9:30 pm

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!
0 x
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