Hello, here its me again!
I have been braining(if that word exist...) around with a problem I am having with the SSAO filter I am using.
The problem appears when I reduce my fov. And I havent been able to reproduce the problem at Fovs above 45º( ~0.78 radians ). Also vary near and far plane doesnt affect so I discarded a malformed linear z.
Here is the code i used:
float doAmbientOcclusion(in float2 tcoord,in float2 uv, in float3 position, in float3 cnorm)
{
float3 pos = getViewPosition( tcoord + uv );
float result = 0;
if( (pos.z > 0) && position.z < fFarClipPlane )//General case - inside frustum
{
float3 diff = position - pos;
if( (diff.z > fMinDiff) && (diff.z < fMaxDiff) )//Particular case
{
const float3 v = normalize(-diff);
//const float d = length(diff)/**g_scale*/;
result = /*max(0,length(diff)/50.0);/*/max(0.0,dot(cnorm,v)/*-g_bias*/)/*(1.0/(1.0+d))*/*g_intensity;
}
}
return result;
}
float4 ps_main(PS_INPUT i) : COLOR
{
float4 o = (float4)0;
o.rgba = 1.0f;
const float2 vec[16] = {
float2( 4, 0),
float2(-4, 0),
float2( 0, 4),
float2( 0, -4),
float2( 8, 0),
float2(-8, 0),
float2( 0, 8),
float2( 0, -8),
float2( 12, 0),
float2(-12, 0),
float2( 0, 12),
float2( 0, -12),
float2( 16, 0),
float2(-16, 0),
float2( 0, 16),
float2( 0, -16),
};
float4 sampledTex = tex2D( NormalSampler, i.uv);
float3 normal = sampledTex.xyz;
if( encodeNormal )
{
normal = decode( float3(normal.xy,0) );
}
else
{
normal = (normal*2.0f)-1.0f;
}
float3 position = getViewPosition(i.position, sampledTex.w);
float2 rand = getRandom(i.uv);
//position.z = normal.z;
//**SSAO Calculation**//;
int iterations = 4;
float ao = 0.0f;
float rad = 0;
float2 sampleDistanceFactor= float2(0.707f,0.487f);
//HERE I MANAGE FOV WITH THE RADIUS
rad = g_sample_radDR*(1.0f-(fFOV*0.0174532f))/position.z;
int totalSamples = 0;
float result = 0;
for (int j = 0; j < iterations; ++j)
{
float2 coord1 = reflect(vec[j],rand)*rad;
float2 coord2 = float2(coord1.x - coord1.y, coord1.x + coord1.y)*sampleDistanceFactor;
ao += doAmbientOcclusion(i.uv,coord1*0.25, position, normal);
ao += doAmbientOcclusion(i.uv,coord2*0.5, position, normal);
ao += doAmbientOcclusion(i.uv,coord1*0.75, position, normal);
ao += doAmbientOcclusion(i.uv,coord2, position, normal);
}
ao/=(float)iterations*4.0f;
//**END**//
o = float4( o.rgb*(1-ao), 1.0f );
return o;
}
I thought the problem might be with the apperture difference (fov) and the sampled radius but must be something more hidden...
Any ideas about? I think I am overwhelmed and frustrated with this, but will continue till find the thing is tricking around ;(