But how do you calculate the distance from the focus plane? Surely this is done per vertex and then interpolated across the triangle?
I’ve had a stab at trying to do this without having to compute the distance at renderscene time…please tell me what you think:-
void initialisation()
{
// bind sharp tex id
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, viewportwidth, viewportheight, 0);
// somehow compute a blurred version
// bind depth tex id
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, viewportwidth, viewportheight, 0);
}
void render()
{
// render scene
// bind sharp tex id
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, viewportwidth, viewportheight);
// somehow compute a blurred version
// bind depth tex id
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, viewportwidth, viewportheight);
// clear colour/depth buffer
// bind sharp texture to unit 0
// bind blurry texture to unit 1
// bind depth texture to unit 2
// enable register combiner program (shown below)
// set const0 of register combiner to some value between 0 and 1
// render screen size quad
// swap buffers
}
//////////////////////////////////////////////////
// nvparse Register Combiner
// tex0 = sharp texture
// tex1 = blur texture
// tex2 = depth texture
// const0 = depth of focal plane
// subtract focal plane depth from depth texture depth to
// give distance from focal plane
{
rgb
{
discard = tex2;
discard = negate(const0);
spare0 = sum();
}
}
out.rgb = lerp(tex0, tex1, unsigned(spare0));
out.a = unsigned_invert(zero);