I’m trying to modify a standard material to make it clear everything rendered behind it (but not in front), so effectively to set color buffer alpha to 0 for every fragment of the shader visible on screen.
I’ve tried playing with blend equations already, but to no avail. My only remaining hope is grab pass functionality, but it seems like an overkill for this. Am I missing something?
Thanks, it works with transparent canvas as expected (haven’t tested it with skybox though):
var Eraser = pc.createScript ('Eraser');
Eraser.prototype.initialize = function()
{
for (var mesh of this.entity.model.meshInstances)
{
var mat = mesh.material;
mat.redWrite = mat.greenWrite = mat.blueWrite = mat.alphaWrite = false;
}
};
I suppose my simplified code will introduce some problems with clearing to skybox, hence additional workarounds needed like mat.blendType = pc.BLEND_NORMAL;?
Also, for future reference - would it be possible to occlude / erase only certain layers?
For the skybox I am not sure, I haven’t tested myself. It’s a bit of a hack this code, not a very official way of doing this. Feel free to try and let us know, I’d be curious to know if it works.
I think yes that can work as well, by putting everything you don’t want to occlude on a separate layer that is rendered after the occluders layer.