Sign in to follow this  

How do focal planes work?

Recommended Posts

I've been looking into depth of field bluring and came across a demo where the scene image is taken and blurred, then it is re-combined with the un-blurred scene image based on its depth dot'd by a focal plane (a four dimensional vector). This is where it happens:
// Pixel Shader: DofCombine
// Desc: Combine the source image with the original image based on pixel
//       depths.
void DofCombine( float2 Tex : TEXCOORD0,
                 float2 Tex2 : TEXCOORD1,
                 out float4 oCol : COLOR0 )
    float3 ColorOrig = tex2D( g_samSceneColor, Tex2 );

    float3 ColorBlur = tex2D( g_samSrcColor, Tex );

    float Blur = dot( tex2D( g_samSrcPosition, Tex ), FocalPlane );

oCol = float4( lerp( ColorOrig, ColorBlur, saturate(abs(Blur)) ), 1.0f );

// Technique: PostProcess
// Desc: Performs post-processing effect that down-filters.
technique PostProcess
    string Parameter0 = "FocalPlane";
    float4 Parameter0Def = float4( 0.0f, 0.0f, 0.2f, -0.6f );
    int Parameter0Size = 4;
    string Parameter0Desc = " (vector of 4 floats)";
    pass p0
        VertexShader = null;
        PixelShader = compile ps_2_0 DofCombine();
        ZEnable = false;

Where g_samSceneColor is a sampler for the original scene and g_samSrcColor is the blurred image. What I don't understand is how FocalPlane works I'm also not sure what the first two components in it are used for, in the code above they're always 0,0, when I change them a strip appears through th escreen which has everything inside it properly focused, but I don't know what's going on. Just to add: What I'd really like to do is define a point of focus in the scene, say have four values such as x, y, z, w where x defines a minimum area where blur is applied full force and by the time x reaches y the blur dissapears, and then from z it starts going up again where it peeks again at w. It doesn't sound like something that should be too difficult but maybe it is?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this