Order Independent Transparency in Max 9 - can't get it to work
I'm not able to get Order Independent Transparency working for Transparent 3D objects. It's a new feature in Max 9 with almost no information on it. All I could find is that it uses the "depth_sort" and "transparency" attributes for the jit.world object.
The attached test patch shows the problem. It also shows the previous method using layers to control transparency.
In the patch the depth_sort attribute works but the transparency attribute does not. When transparency is set to 1, any transparent object disappears. When transparency is set to 0, one object loses transparency when it intersects with the other object.
Hi!
The attributes depth_sort and transparency control two different aspects of rendering.
depth_sort enables sorting draw calls based on each object’s distance from the camera. When it is enabled, the distance between each object’s position and the camera position is calculated before rendering, and the objects are then drawn from farthest to closest. This check is done per object, which means that when parts of two objects overlap, there is no single correct rendering order that will work in every case.
@transparency enables Order Independent Transparency, a technique that approximates correct rendering of semi-transparent objects regardless of draw order. It is generally more robust than depth sorting for overlapping shapes, but it requires that objects in the scene have a jit.gl.pbr attached.
That explains why things were not working in your tests:
With @depth_sort 1, transparency can still fail when objects overlap. And @transparency 1 did not work because there were no jit.gl.pbr objects attached to the gridshape objects.
Here is an example patch using @transparency 1 with jit.gl.pbr:
jit.gl.pbr applies physically based shading to objects, but if you want flat shading while still using transparency, there is a hacky but workable solution:
Add a dummy
jit.gl.light @diffuse 0 0 0to the patch. This overrides the default hemisphere light.Set
@mat_diffuseto0 0 0 A, whereAis the alpha value you want. Then control the shapes’ color using thejit.gl.pbrattribute@mat_emissive.
See your modified patch below:
Thanks for the patch. It looks like objects need to be captured by a jit.gl.node for transparency to function. I don't remember that always being the case, so I'm assuming this has something to do with the global-context functionality introduced in 9.1.
I also see the transparency example patch is not easily discoverable. I'll make a note to add this to the jit.world help patch. You can find it by searching in the max browser for "weighted.blended.oit.maxpat" , or simply "oit".
Thanks for these examples and information.
I was able to get transparency working using pbr and non-pbr textures. But ran into problems with each method with intersecting objects.
In the patch below, the intersecting object loses transparency when the object or camera changes z-position. This uses PBR.
In the next patch the intersecting shape loses transparency where it overlaps with the other shape if the other shape has no transparency.
Also, when alpha is changed on gridshape objects from 1.0 to 0.999, there's a jump in transparency when it should be a smooth transition. This seems like it could be a bug.
Is this the limit of OIT? Or is there a setting to get it fully working in the cases above?