*Digging up my distance field shader*
You're welcome.
1. This Valve article is only valid for alpha tested "objects"?
I don't think so. If you enable alpha blending that shader should work without any change. You can of course combine it with alpha testing (e.g. for performance).
In what ranges these first two parameters should be in context of rendering 2d fonts?
Depends on how big the decal (or whatever) appears on your render target and how you created the distance field in the first place.
In short: Let's play with it: Here's a distance you can use
(Click on the images, there's scaled up/down. I deliberately don't use the forum's gallery functionality: the images get sometimes screwed - or disappear. Imagebam keeps them for ages).
Here's a minimalpixel shader I just came up with for illustration:
float4 PS(in float2 texCoord: TEXCOORD0, in float4 diffuse: COLOR0) : COLOR0
{
float dist = tex2D(DiffuseSampler, texCoord).r;
float center = 0.46;
float transition = 0.01; // in distance field space !
diffuse.a *= smoothstep(center - transition, center + transition, dist);
return diffuse;
}
Note: I had to play around with the center value. Can't quite remember how I generated the distance field.
This yields:
Playing with the transition value (now 0.02)
transition now 0.05
3. I don't understand ddx/y function, what parameters is it expecting and how should i replace smoothstep with them?
ddx() gives you the rate of change of
any value (not only scalars) from one pixel to the next to the right. ddy is the same for down.
With this information one can achieve a couple of useful stuff but here one can estimate the distance field change in screen space.
Here's a good explanation for this estimation (without the hardware gradients).
This GPU Gems article is also enlighting. (Paragraph 25.5 about Antialiasing).
Don't bother too much, there's a shortcut for the problem at hand :
fwidth
float transition = fwidth(dist) * 1.0;
This yields approx 1 pixel AA independant of how big we render.
Cheers.