From ca5f97ccf3c2b2ca57e251a5ed9191a8274562de Mon Sep 17 00:00:00 2001 From: n8programs <43304488+N8python@users.noreply.github.com> Date: Fri, 3 Jun 2022 03:42:43 -0400 Subject: [PATCH] Improve ShadowMesh.js and Prevent Shadow Overlap (#24180) A simple use of the stencil buffer can prevent ugly artifacts caused by the planar projected shadow of the geometry overlapping with itself. --- examples/jsm/objects/ShadowMesh.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/jsm/objects/ShadowMesh.js b/examples/jsm/objects/ShadowMesh.js index 599f7eba1acb4..f04b86a2bf84d 100644 --- a/examples/jsm/objects/ShadowMesh.js +++ b/examples/jsm/objects/ShadowMesh.js @@ -1,7 +1,9 @@ import { Matrix4, Mesh, - MeshBasicMaterial + MeshBasicMaterial, + EqualStencilFunc, + IncrementStencilOp } from 'three'; /** @@ -19,7 +21,11 @@ class ShadowMesh extends Mesh { color: 0x000000, transparent: true, opacity: 0.6, - depthWrite: false + depthWrite: false, + stencilWrite: true, + stencilFunc: EqualStencilFunc, + stencilRef: 0, + stencilZPass: IncrementStencilOp } );