fog in cg fragment shader

How do I use fog in a fragment shader? #pragma fragmentoption ARB_fog_exp2 does some magic but what if I want to set the fog manually in a fragment shader?

You could check out what the PositionFog function does:

// Computes final clip space position and fog parameter
inline void PositionFog( in float4 v, out float4 pos, out float fog )
{
    pos = mul( glstate.matrix.mvp, v );
    fog = pos.z;
}

as well as that define you put into the vertexshaders output struct:

#define V2F_POS_FOG float4 pos : POSITION; float fog : FOGC

alternatively you can just deactivate it and fade it in yourself in pixel shader. I dont know what exactly you want to do, but this should basicly be all information needed?

I also checked this source before and then I tried to use i.fog in fragment shader but what I'm getting is :

"Cg in program 'frag': error C5119: variable/member "fog" has semantic "FOGC" which is not visible in this profile at line 56"

Does it mean that I have to calculate fog color in vertex shader? Is there any build in variable for fog color?