[SOLVED] Clear color buffer / Eraser shader?

Hey everyone!

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?

Thank you in advance for any suggestion!

As in you would like have nothing rendered behind objects with this material?

Hi @underlight,

I’ve done something similar on this project, check it. To create invisible occluders:



Yep, clearing to skybox or to transparency depending on if we have skybox layer enabled on camera / rendering to transparent canvas (for AR stuff)

Awesome, thanks you!!!

Will try to port it into my project and see if it works as expected :+1:

1 Like

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.

I see, makes sense now. Thanks for your help!

1 Like