i've made some tests, and it seems that "distance = tex2D(depthFrame, uv).r" function always return the same value for me, in this code (tried too staticfocus mode),
as the shader consider that distance is always greater than tfocus, even if tfocus is fixed to staticfocus = 0.98f
i've checked and "calculated depth & focus" are activated in gui
float4 DoF(in float2 uv : TEXCOORD0) : COLOR
{
float distance = 0;
float tfocus = 0;
float factor = 0;
float n = 1.0;
float f = 1000.0;
float4 color = tex2D(lastShader, uv);
float4 blur = tex2D(lastPass, uv);
distance = tex2D(depthFrame, uv).r;
if ( mode == 0 )
{
tfocus = focus; //tex2D(depthFrame, float2(0.5, 0.5)).r;
} else {
tfocus = staticfocus;
}
distance = (2.0 * n) / (f + n - distance * (f - n));
tfocus = (2.0 * n) / (f + n - tfocus * (f - n));
factor = abs(distance - tfocus); // Should be 0 - 0.5
if ( distance < tfocus )
{
factor *= 2.175; // 0 - 1.250;
} else {
factor *= 2.075; // 0 - 1.125; <<<<<<<< always use this line
}
factor *= factor; // 0 - 1.26 if farther, 0 - 1.56 if near
factor = clamp(factor, 0, 1.35);
color.rgb = lerp(color.rgb, blur.rgb, factor.rrr);
return float4(color.rgb, 1.0);
}
if i change the code to
" if ( distance < tfocus )
{
factor *= 2.175; // 0 - 1.250;
} else {
factor *= 0; // 0 - 1.125;
}
"
all my screen is clear with no blur so the shader always use the "distance > tfocus" case, it means , i guess' that "calculated depth " option does not function correctly for me
Modifié par chico400, 14 août 2010 - 08:35 .