Bladeren bron

Add stencil option

Popov72 4 jaren geleden
bovenliggende
commit
b877e13e6d
2 gewijzigde bestanden met toevoegingen van 10 en 3 verwijderingen
  1. 1 1
      src/Engines/thinEngine.ts
  2. 9 2
      src/Engines/webgpuEngine.ts

+ 1 - 1
src/Engines/thinEngine.ts

@@ -299,7 +299,7 @@ export class ThinEngine {
     protected _hardwareScalingLevel: number;
     /** @hidden */
     public _caps: EngineCapabilities;
-    private _isStencilEnable: boolean;
+    protected _isStencilEnable: boolean;
 
     private _glVersion: string;
     private _glRenderer: string;

+ 9 - 2
src/Engines/webgpuEngine.ts

@@ -9,7 +9,7 @@ import { IEffectCreationOptions, Effect } from "../Materials/effect";
 import { EffectFallbacks } from "../Materials/effectFallbacks";
 import { _TimeToken } from "../Instrumentation/timeToken";
 import { Constants } from "./constants";
-import * as WebGPUConstants from './webGPU/webgpuConstants';
+import * as WebGPUConstants from './WebGPU/webgpuConstants';
 import { VertexBuffer } from "../Meshes/buffer";
 import { WebGPUPipelineContext, IWebGPUPipelineContextVertexInputsCache, IWebGPURenderPipelineStageDescriptor } from './WebGPU/webgpuPipelineContext';
 import { IPipelineContext } from './IPipelineContext';
@@ -111,6 +111,11 @@ export interface WebGPUEngineOptions extends GPURequestAdapterOptions {
      * Defines wether MSAA is enabled on the canvas.
      */
     antialiasing?: boolean;
+
+    /**
+     * Defines wether the stencil buffer should be enabled.
+     */
+    stencil?: boolean;
 }
 
 /**
@@ -224,6 +229,7 @@ export class WebGPUEngine extends Engine {
         options.deviceDescriptor = options.deviceDescriptor || { };
         options.swapChainFormat = options.swapChainFormat || WebGPUConstants.TextureFormat.BGRA8Unorm;
         options.antialiasing = false;//options.antialiasing === undefined ? true : options.antialiasing;
+        options.stencil = options.stencil ?? true;
 
         Logger.Log(`Babylon.js v${Engine.Version} - WebGPU engine`);
         if (!navigator.gpu) {
@@ -257,6 +263,7 @@ export class WebGPUEngine extends Engine {
 
         this._hardwareScalingLevel = 1;
         this._mainPassSampleCount = options.antialiasing ? this._defaultSampleCount : 1;
+        this._isStencilEnable = options.stencil;
 
         this._sharedInit(canvas, !!options.doNotHandleTouchAction, options.audioEngine);
 
@@ -453,7 +460,7 @@ export class WebGPUEngine extends Engine {
             mipLevelCount: 1,
             sampleCount: this._mainPassSampleCount,
             dimension: WebGPUConstants.TextureDimension.E2d,
-            format: WebGPUConstants.TextureFormat.Depth24PlusStencil8,
+            format: this.isStencilEnable ? WebGPUConstants.TextureFormat.Depth24PlusStencil8 : WebGPUConstants.TextureFormat.Depth32Float,
             usage:  WebGPUConstants.TextureUsage.OutputAttachment
         };