I’ve only spent a few days playing with ZapStudio so it’s possible I’ve missed something in the docs, or this may just not be possible. But it’d be super powerful if it was.
During rendering a depthBuffer is used to track the depth of previously rasterised objects, pixel by pixel, so occlusion can be performed correctly. It’s how we can do that portal masking effect: you drop a Square Mask at the start of your hierarchy, set it to render nothing to the screen (Alpha = 0) but still have it write to the depthBuffer, so even though it’s invisible it stops anything behind if from being rendered.
Once something’s been written to the depthBuffer, though, it’s there for ever (well, until the frame is redrawn), and regardless of render order, you’ll never be able to have a 3D object render behind it.
If we had a way to clear that depthBuffer at a certain point in the render order then it’d open up loads of new and exciting effects:
- you could mask groups of objects individually
- multiple objects could occupy the same 3D space, but depending on which mask your phone was “looking through”, different ones could appear
- you could add 3D overlays (not to be confused with the “overlay” layer mode) over previously drawn objects, to create holographic display effects
- but mostly: once you’ve created a masked portal, you could then reset the depthBuffer and add elements around and behind the portal - something impossible at the moment.
For example - my first experiment with a portal:
scrappy image target:
It’s a load of 3D gubbins masked with the Square Mask. It’s an idea for a postcard.
Say I want to add some sparkles coming out from behind the card - I can’t do it, because once the first mask has written to the depth buffer it’s there for good, so anything I try and put there gets occluded:
Nosing around behind the scenes, there seem to be two flags that get set depending on an object’s LayerMode: depthTest (which determines whether to test the buffer before writing pixels) and fillDepthBuffer (which determines whether to write the new pixels’ depths to the buffer).
We can currently choose 3 out of the 4 possible permutations:
overlay: test = 0; fill = 0;
test_3d: test = 1; fill = 0;
full_3d: test = 1; fill = 1.
We need that missing permutation. Maybe call it reset_3d:
reset_3d: test = 0; fill = 1. Put another way: don’t test the depth buffer, but do write the new pxel depths to it.
We could apply it to a large plane set in the distance, and it’d effectively reset the buffer, stopping any existing masks and objects from occluding new objects. Then we could start over - render new masks and objects to the colour and depth buffers freely.
It’d be an advanced tool: it would be up to us to ensure the render order made sense so occlusion happened correctly for the particular scene and camera orientation, but it’d open up a whole new set of visual possibilities; allow for some clever and eyecatching compositing tricks.
Anyway, that’s been my TED talk; if you’ve got this far, thank you