Selaa lähdekoodia

Fix HDRCubeTexture in WebGPU

Popov72 4 vuotta sitten
vanhempi
commit
c4362d854f

+ 3 - 0
src/Engines/engineFeatures.ts

@@ -16,4 +16,7 @@ export interface EngineFeatures {
 
     /** Indicates to check the matrix bytes per bytes to know if it has changed or not. If false, only the updateFlag of the matrix is checked */
     uniformBufferHardCheckMatrix: boolean;
+
+    /** Indicates that prefiltered mipmaps can be generated in some processes (for eg when loading an HDR cube texture) */
+    allowTexturePrefiltering: boolean;
 }

+ 2 - 0
src/Engines/thinEngine.ts

@@ -181,6 +181,7 @@ export class ThinEngine {
         supportDepthStencilTexture: false,
         supportShadowSamplers: false,
         uniformBufferHardCheckMatrix: false,
+        allowTexturePrefiltering: false,
     };
 
     /**
@@ -720,6 +721,7 @@ export class ThinEngine {
         ThinEngine.Features.supportRenderAndCopyToLodForFloatTextures = this._webGLVersion !== 1;
         ThinEngine.Features.supportDepthStencilTexture = this._webGLVersion !== 1;
         ThinEngine.Features.supportShadowSamplers = this._webGLVersion !== 1;
+        ThinEngine.Features.allowTexturePrefiltering = this._webGLVersion !== 1;
 
         // Ensures a consistent color space unpacking of textures cross browser.
         this._gl.pixelStorei(this._gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, this._gl.NONE);

+ 2 - 1
src/Materials/Textures/Filtering/hdrFiltering.ts

@@ -75,6 +75,7 @@ export class HDRFiltering {
         const texture = this._engine.createRenderTargetCubeTexture(size, {
             format: Constants.TEXTUREFORMAT_RGBA,
             type: textureType,
+            createMipMaps: true,
             generateMipMaps: false,
             generateDepthBuffer: false,
             generateStencilBuffer: false,
@@ -198,7 +199,7 @@ export class HDRFiltering {
       * @return Promise called when prefiltering is done
       */
     public prefilter(texture: BaseTexture, onFinished: Nullable<() => void> = null) {
-        if (this._engine.webGLVersion === 1) {
+        if (!ThinEngine.Features.allowTexturePrefiltering) {
             Logger.Warn("HDR prefiltering is not available in WebGL 1., you can use real time filtering instead.");
             return;
         }

+ 1 - 1
src/Materials/Textures/hdrCubeTexture.ts

@@ -237,7 +237,7 @@ export class HDRCubeTexture extends BaseTexture {
             return results;
         };
 
-        if (this._getEngine()!.webGLVersion >= 2 && this._prefilterOnLoad) {
+        if (ThinEngine.Features.allowTexturePrefiltering && this._prefilterOnLoad) {
             const previousOnLoad = this._onLoad;
             const hdrFiltering = new HDRFiltering(engine);
             this._onLoad = () => {

+ 5 - 1
src/Materials/Textures/renderTargetCreationOptions.ts

@@ -4,7 +4,11 @@
  */
 export class RenderTargetCreationOptions {
     /**
-     * Specifies is mipmaps must be generated
+     * Specifies if mipmaps must be created. If undefined, the value from generateMipMaps is taken instead
+     */
+    createMipMaps?: boolean;
+    /**
+     * Specifies if mipmaps must be generated
      */
     generateMipMaps?: boolean;
     /** Specifies whether or not a depth should be allocated in the texture (true by default) */