I have just started learning how to use and create shaders in ThreeJS and, while going through some shaders in the example folder, I have come across BokehShader2. Inside the shader, blur is computed using a formula, but I dont really understand where this formula comes from and what it really computes. Here is some code:

“float f = focalLength; // focal length in mm",
"float d = fDepth*1000.0; // focal plane in mm",
"float o = depth*1000.0; // depth in mm",
"float a = (o*f)/(o-f);",
"float b = (d*f)/(d-f);",
"float c = (d-f)/(d*fstop*CoC);",
"blur = abs(a-b)*c;"

What I don’t understand is what c is and how I can then use it to compute the blur. Can anyone help me out?

Hey, thank you for responding me unfortunately, while the post is very informative, it does not revolve around a fixed CoC limit and I dont understand where the formulas I posted come from. I think it is somehow relatable to the approach used in the post, but I have been looking around to understand what my code is actually computing and I didnt manage to find any matching real-world formula

Yes, I can confirm. In fact the general idea is very different and that is why I have not been able to find any reference to those formulas. I believe it has to be somewhat of a blur factor, but I haven’t been able to find anything confirming it