浏览代码

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.
n8programs 3 年之前
父节点
当前提交
ca5f97ccf3
共有 1 个文件被更改,包括 8 次插入2 次删除
  1. 8 2
      examples/jsm/objects/ShadowMesh.js

+ 8 - 2
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
 
 		} );