postprocessing icon indicating copy to clipboard operation
postprocessing copied to clipboard

Rendering tearing / distortion when using stencils

Open victorronnow opened this issue 1 year ago • 1 comments

I'm trying to render 2 planes using stencils. Somehow the green plane is not masking the red plane properly when rendering with the EffectComposer and is causing to tearing around the mask, see the attached gifs:

No postprocessing With postprocessing:
Screen Recording 2024-07-30 at 10 35 33 Screen Recording 2024-07-30 at 10 37 22

To reproduce

Here's a stackblitz link: https://stackblitz.com/edit/vitejs-vite-6fxjcx

In the demo I'm using 2 planes:

A green plane

const geometry = new THREE.PlaneGeometry(1, 1, 1);
const material = new THREE.MeshBasicMaterial({
  color: 0x00ff00,
});

material.depthWrite = false;
material.stencilWrite = true;
material.stencilRef = 1;
material.stencilFunc = THREE.AlwaysStencilFunc;
material.stencilZPass = THREE.ReplaceStencilOp;

const mask = new THREE.Mesh(geometry, material);

A red plane getting masked by the green plane using THREE.EqualStencilFunc

const planeGeometry = new THREE.PlaneGeometry(1, 1, 1);
const planeMaterial = new THREE.MeshBasicMaterial({
  color: 'red',
});

planeMaterial.stencilWrite = true;
planeMaterial.stencilRef = 1;
planeMaterial.stencilFunc = THREE.EqualStencilFunc;

const plane = new THREE.Mesh(planeGeometry, planeMaterial);

Library versions used

  • Three: 0.167.0
  • Post Processing: 6.36.0

Desktop

  • OS: macOS
  • Browser: Chrome 127.0.6533.72
  • Graphics hardware: M2 Max

victorronnow avatar Jul 30 '24 08:07 victorronnow

Hi, I haven't used stencil ops with postprocessing before, but there's MaskPass and ClearMaskPass which might help.

vanruesc avatar Jul 31 '24 19:07 vanruesc

Closing due to inactivity.

vanruesc avatar Aug 14 '25 15:08 vanruesc