浏览代码

Occlusion material (#9387)

rgerd 4 年之前
父节点
当前提交
5eccee789b

+ 4 - 0
dist/preview release/what's new.md

@@ -4,6 +4,10 @@
 
 ## Updates
 
+### Materials
+
+- Added an `OcclusionMaterial` to simplify depth-only rendering of geometry ([rgerd](https://github.com/rgerd))
+
 ## Bugs
 
 - Fix issue with the Promise polyfill where a return value was expected from resolve() ([Deltakosh](https://github.com/deltakosh))

+ 1 - 0
src/Materials/Occlusion/index.ts

@@ -0,0 +1 @@
+export * from './occlusionMaterial';

+ 21 - 0
src/Materials/Occlusion/occlusionMaterial.ts

@@ -0,0 +1,21 @@
+import { Color4 } from '../../Maths/math.color';
+import { Scene } from "../../scene";
+import { ShaderMaterial } from '../shaderMaterial';
+
+import "../../Shaders/color.fragment";
+import "../../Shaders/color.vertex";
+
+/**
+ * A material to use for fast depth-only rendering.
+ */
+export class OcclusionMaterial extends ShaderMaterial {
+    constructor(name: string, scene: Scene) {
+        super(name, scene, "color", {
+            attributes: ["position"],
+            uniforms: ["world", "viewProjection", "color"]
+        });
+        this.disableColorWrite = true;
+        this.forceDepthWrite = true;
+        this.setColor4("color", new Color4(0, 0, 0, 1));
+    }
+}

+ 1 - 0
src/Materials/index.ts

@@ -10,6 +10,7 @@ export * from "./materialDefines";
 export * from "./thinMaterialHelper";
 export * from "./materialHelper";
 export * from "./multiMaterial";
+export * from "./Occlusion/index";
 export * from "./PBR/index";
 export * from "./pushMaterial";
 export * from "./shaderMaterial";