Help with DOF needed

t's icon

Hi there,

I would need some help with the DOF help patch (mrt.dof.maxpat). What I would like to achieve is that objects behind AND in front of focal point would be blurry. So for instance if focal point is set to the middle layer of toruses, everything behind and in front would be out of focus.

PS: Also I don't understand at all how the help patch works so I have no idea where to start.

Max Patch
Copy patch and select New From Clipboard in Max.

Rob Ramirez's icon

the effect already does that. might be easier to simply use the jit.gl.pass @fxname dof. in any case you simply narrow the focal_range parameter, and adjust the focal_distance parameter on the area you want in focus.

t's icon

Thanks Rob, I forgot about the dof option of the jit.gl.pass. It works ok on the 3D objects but I have some problems with the point mesh. If you could please check the patch that would be great (*I am trying to uplad a matrix that goes with it but I can't...I will try again in next post or alternatively I will send it to your email)...

1. If material is applied to the mesh the dof works...is material necessary? Also it seems that quality of the pass needs to be set to lo.

2. Inside the cube there is one larger "blot". I would like this "blot" to be sharp while front and back blurry. I can not achieve that. I tried rotating/zooming with jit.gl.handle and adjusting params but no luck.

3. If I understand the DOF correctly, the focal distance parameter is the distance from the camera position? If that is correct then I am assuming that something is not working correctly.

4. If I would like to achieve a higher quality DOF result, with more gradual blur, would it make sense to connect few jit.gl.pass together, all with the same focal distance but each with slightly wider focal range?

Thank you!!!

Max Patch
Copy patch and select New From Clipboard in Max.

t's icon

PS: I can't upload the matrix for the mesh, please see your email

Andro's icon

try using the cubic pulse function from IQ here with a blur shader (GLSL).
http://www.iquilezles.org/www/articles/functions/functions.htm

So you basically read the output of the depth buffer and use that figure to increase the amount of blur. Best part with that function is that you have distance AND curve response.

t's icon

Hi Andro,

Unfortunately I have no experience in writing shaders. If you think that what you sugested could be done by someone with no shader experience then please explain a bit more. For instance I don't even know how to acess depth buffer and how to use it...this is unknown world to me.

However if anyone else would like to try with my matrix, here is the link to it:

http://www.tadej-droljc.org/td-zip/Pointmatrix.zip

Rob in case you missed my questions above I would really like to get some answers.

Thanks!

Rob Ramirez's icon

Hi T.

yes jit.gl.pass effects that make use of the normals and depth buffer require a jit.gl.material.

i would not recommend this technique for what you are trying to acheive, but would instead try a custom technique. perhaps it is as simple as drawing once unblurred, with a color or alpha mask based on distance from the center, and then drawing a second blurred pass on top of that, perhaps with an inverse of the mask from the previous pass.

t's icon

Hi Rob,

thank you for answering. The problem with your suggested solution is that the unblurred layer would also include the very close and far points as sharp points. Also in case I am missing something that technique would not be suitable for animation where there is zoom-ing, rotation, translation, scaling etc going on...I would need to animate masks along with animation which is of course not an option...it would take me a life time to that.

I tried creating submatrices with xray objects (slicing the point cloud into layers based on Z distance from camera) so that the close points would present one layer, middle points second layer and far points third layer. I even tried with 5 layers but the blur is too "steppy" .... I really need a continuous blur on the Z camera axis.

So it seems to me that the DOF in max is not really a DOF because it is not possible to have things behind and infront of focal point blurry. Is this something you plan to fix/upgrade? Should I send bug report or is this not a bug?

Why does working with Max has to be so hard? Why can't things simply work...

t's icon

Dear Cycling 74,

I would really like to know if DOF is something that we can anticipate in further updates / releases or is the curent "DOF" something you are happy with meaning if the users want DOF we need another software ? So once again: is the current DOF buggy and I need to file a bug report or would be that a waste of time because you think it works fine?

Pedro Santos's icon

I think DOF is working fine. It's not perfect, certainly not as sophisticated as in game render engines but perfectly adequate for most projects. I remember having to build my own dof implementation before Max 7, so the current implementation is certainly welcome.

I think you're not getting the results you want because of a wrong approach, not because of Max's DOF implementation. You're trying to get a sense of depth with the aid of the depth of field effect, but drawing in point mode. By drawing points, you don't get the sense of distance because the points always have the same size, i.e, they're not scaled according to distance from the camera/viewport.

I think you would get the desired result by drawing bi or tridimensional shapes instead of points. Doing it this way is more CPU and GPU intensive, but it gives you a more realistic result. To that end, I recommend you to downsize the points matrix accordingly.

dof_pedro.zip
zip 2.11 MB

t's icon

Pedro thanks a lot for your help! Much appreciated!


The thing is that I need points as I need a feeling of dust hence I need a lot of them - more than Max can handle when using 3D spheres. I am not after some realism so I am fine with points being the same size.


After doing some more experiments with points I realised that from a technical point of view DOF probably works but the result is visually so bad (beyond bad) that it seems as it is not working. So it is basically useless.


I will try to offline render “600x600” matrices with jit.gl.multiple to see if I can get visually simillar results as with points (without DOF) and then go from there. So your solution might work for me at the end.


However, as always with Max, I am spending many days on things that one would expect to work… It seems that things in Jitter work only in a very limited circumstances - as soon as you go out you end up in contless problems. At least I am experiencing that non stop.

t's icon

OK so I've moved to 3D spheres (which gives me less attractive aesthetic results and eats way more computer power) and DOF still works buggy. Even if I set blur amount to 0 the image is still very blurry. If you disable jit.gl.pass you will see how a non blurry image should look like.

How to set a tiny or ar least little amount of blur (while keeping the focal point sharp)?

dof_pedro_tweaked.zip
zip 2.12 MB

Pedro Santos's icon

OK, you might be into something here.

I was able to reproduce your problem. With blur width at 0. the result should, in principle be the same as with jit.gl.pass with enable 0. That is not the case. Only If you also configure the focal range parameter with a high value like 20 or more, then it is practically the same.

If you double-click on the jit.gl.pass object, you see the problem: for performance reasons, the blur passes are being done at half-resolution (dimscale 0.5 0.5).

This is not a problem by itself (it's obviously useful), but the way the blurred texture is combined with the color texture reflects this problem. In other words, even though the "blurred" texture is not actually blurred (when blur_width is 0.), the texture still has half the resolution of the main image.

The quickest and easiest solution for you would be to simply change this dof.jxp text file with "dimscale 1.0 1.0".

But the ideal solution would be to change the actual mrt.dof.jxs and combine the textures in another way in order to avoid this problem. Right now the mixing is done this way: mix(image, blur, dof).

Any thoughts on this, Rob Ramirez?

Andrew Benson's icon

I'm looking at this and am having trouble knowing exactly what the complaint is. Maybe you could mock up or find an image of how you'd expect the effect to work, so we can visually understand where the effect is failing for you. FWIW, I find 3D DOF effects to be pretty difficult to get right when doing high contrast, single-pixel shapes, especially white on black. One suggestion might be to develop a better blur stage using multiple passes with width multiplied for each pass (similar to how jit.gl.slab.gauss6x), and the compositing method can be adjusted as well.

t's icon

Hi Pedro and Andrew,

Pedro your solution removes one problem which is great - thanks a lot for your help! Much appreciated!

The remaining problems are:

- DOF is still not working with points (please see the attached patch, all instructions are there). There are two layers, one point layer and one jit.gl.multiple. All DOF parameters are already set. Jit.gl.multiple now works (with "dimscale 1.0 1.0") while points doesn't. Points sort of work in some weird way if you disable blend_enable but the result is totally unacceprable ...

- Why are things such as "blur passes are being done at half-resolution (dimscale 0.5 0.5)" nowhere documented? Why is there not a DOF help patch that would explain such things? I literally experience simmilar things non stop with Max and I am wasting a lot of time tweaking parameters, trying different things out...and I never know if its me doing something wrong, is it some undocumented detail that is causing me problems or is it simply a bug. I think working with a software should not be such a nightmare.

About increasing the quality of DOF (so these are not complaints):

- "One suggestion might be to develop a better blur stage using multiple passes with width multiplied for each pass (similar to how jit.gl.slab.gauss6x)" So I should connect few jit.gl.pass in a row, each with slightly wider focal range? What do you mean by "and the compositing method can be adjusted as well"?

- Ideally, this is more a future request, I would be great if DOF would also have a horizontal range, so one could really put a cenral object in focus, like on the images below for instance. On the black and white one I tried to fake the DOF in postproduction (maybe that shouldn't be called DOF anymore). But the idea is that you can have a sharp central object with blurry surrounding. And when you rotate the whole thing the central object stays sharp while the rest is blurred

DOF-ForumQuestion.zip
zip 2.12 MB

Rob Ramirez's icon

as suggested above, my recommended approach is to render in two passes, and blurring one of the passes. the patch below simply color masks based on distance from the origin, and adds the render passes together to composite. could be lots of different approaches and improvements to this basic technique.

Max Patch
Copy patch and select New From Clipboard in Max.

t's icon

Rob, this is a totally amazing solution! Very powerful patch, so many potentials here. Thank you very much! And unfortunately I didn't understand at all what you were trying to say when you suggested that - I thought you were talking about 2D masks on textures. However I would not be able to implement such a smooth solution even if I would understand you so many thanks for this! Much appreciated!

Is there any chance to keep the material on the point mesh while applying this colour mask on the top? I prefer how the points are rendered when material is on as you get this nice shading effect when rotating the point mesh. I tried also with jit.gl.multiple and there is no problem with the combination of material and colour mask.