Patch sharing: Point clouds with antialiasing, motion blur and DoF processed by geometry shader

Matteo Marson's icon

Hi guys,

I'd like to share with you a patch I'm currently working on. It consists of a particle rendering system with some of the eye candy we know and love (antialiasing, motion blur and depth of field) created by a geometry shader.

The particle system is divided in two parts:
- a point "displacer" done with jit.gl.tf
- a particle rendering shader

The first part is quite simple and random; it just provides some moving points for the sake of example.

The key part is the rendering shader. Around each point is constructed a set of vertices in a circular path. In the geometry shader the radius of each circle and the color of each vertex is defined independently.

The depth of field is created by enlarging the radius of the circles according to the distance from the camera (z depth) and a focus distance, and by reducing the transparency of the circles far from the focus distance. This gives the illusion of "out of focus" objects.

The motion blur effect is achieved by elongating the geometry against the direction of motion. This is done by retrieving the position of the particles at the previous frame from [jit.gl.tf] and varying what is considered the center to construct the circle around according to the angle formed by the center and the vertices at the circle border. The color of the elongated part is then faded in order to make it appear more like a trail than a solid object.

The antialiasing is achieved by giving a transparent color to the vertices at the border of the circle and by deciding (in the fragment shader) at witch distance from the center to start fading the color.
An issue if found is that I should have worked in another space, because enlarging the window causes the geometry to deform.
What i'd like to introduce is curved motion blur trails done by keeping in a buffer the velocity of the particles at the previous frame and generating more vetices in the geometry shader following the curve the particle "might have done".

I'd also like to extend the same principle to lines.

I'd love if you could contribute to this or spread some suggestions.

Here it is the patch and the shaders:

Cool Points.maxpat
text/plain 87.00 KB

antialiasedPoints.jxs
jxs 5.15 KB

pointTrails.jxs
jxs 2.14 KB

Ciao!

AudioMatt's icon

This could be a bug in jit.gl3 (not your patch) but I'm loading it and it says....

jit.gl.buffer: could not allocate object
jit.gl.buffer: could not allocate object
jit.gl.buffer: could not allocate object
jit.gl.buffer: could not allocate object
jit.gl.tf: could not allocate object

Matteo Marson's icon

that's strange... I tried the patch on two different computers and it works.
Try to lower the number of particles (top-right corner)

Matteo Marson's icon

New version: I just dropped in a raw/fake phong shading to give more volume to the particles

Cool Points.maxpat
text/plain 88.43 KB

antialiasedPoints.jxs
jxs 5.52 KB

pointTrails.jxs
jxs 2.14 KB

Rob Ramirez's icon

This is gorgeous, thanks so much for sharing your work!

@audiomatt, make sure you've set your glengine to gl3

Jean-Francois Charles's icon

Beautiful, thanks for sharing, Matteo!

Federico-AmazingMaxStuff's icon

Are you kidding me!! This antialising shader looks like a million dollar effect

Matteo Marson's icon

Hi guys!
Little update: I added some volumetric shadows processed on the geometry shader. Patch and shaders attached. I also optimized a bit the previous code, but it starts to be quite heavy, so I dropped down a bit the default number of particles.

The shadows are still a bit sketchy because i'd need to calculate their geometry more carefully...

Cool Points2.maxpat
text/plain 102.28 KB

antialiasedPoints.jxs
jxs 6.83 KB

pointTrails.jxs
jxs 2.14 KB

Ciao!

riccardo dapelo's icon

Wow, supercool!!
Thanx for sharing

Matteo Marson's icon

I'd like to add ambient occlusion to the package, but I don't get if itis possible (and how) to write normals and depth information into a frame buffer to access later into an SSAO shader.

Maybe @Rob Ramirez can shed some light on this... :)

As an alternative, since we are dealing with points (more or less), I thought about constructing a sort of "3D density map" showing where there is more "stuff". It could be looked-up inside the main shader and used to roughly determine how much ambient light each particle receives, according to its position. I don't know if it is a well-established technique in the literature, but it seems like a feasible option in this context, to me at least.

Any advice on this is more than welcome!

Riccardo Santalucia's icon

Wonderful : )

zangpa's icon

For some strange reason i can not get this to work. When i activate jit.world, i can not enable the the jit.gl.tf, and if i enable the jit.gl.tf, i can not get the jit.world to be activated. Anyone know what i am doing wrong?

Pedro Santos's icon

Do you have the GL3 installed from Package Manager and selected in the Preferences?

zangpa's icon

Found out what was the problem. I have to disable the Radeon graphics card on my macbook 2019 16" when using Max (and Ableton) to prevent the machine from heating up like crazy and fans from running wild. Looks like i can't enable the jit.gl.tf when using the Intel graphics card, and i can not use the Radeon without fans getting crazy. Stupid Macbooks! Well anyway, patch looks great. Thanks for sharing