浏览代码

Make the right computation for the number of mip levels

Popov72 4 年之前
父节点
当前提交
1308979c76

+ 1 - 1
src/Engines/WebGPU/webgpuTextureHelper.ts

@@ -32,7 +32,7 @@ export class WebGPUTextureHelper {
     private _mipmapPipeline: GPURenderPipeline;
 
     public static computeNumMipmapLevels(width: number, height: number) {
-        return Math.round(Scalar.Log2(Math.max(width, height))) + 1;
+        return Scalar.ILog2(Math.max(width, height)) + 1;
     }
 
     constructor(device: GPUDevice, glslang: any, bufferManager: WebGPUBufferManager) {

+ 1 - 0
src/LibDeclarations/browser.d.ts

@@ -65,4 +65,5 @@ interface HTMLVideoElement {
 interface Math {
     fround(x: number): number;
     imul(a: number, b: number): number;
+    log2(x: number): number;
 }

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

@@ -92,7 +92,7 @@ export class HDRFiltering {
 
     private _prefilterInternal(texture: BaseTexture): BaseTexture {
         const width = texture.getSize().width;
-        const mipmapsCount = Math.round(Scalar.Log2(width)) + 1;
+        const mipmapsCount = Scalar.ILog2(width) + 1;
 
         const effect = this._effectWrapper.effect;
         const outputTexture = this._createRenderTarget(width);

+ 1 - 1
src/Misc/environmentTextureTools.ts

@@ -433,7 +433,7 @@ export class EnvironmentTextureTools {
             throw new Error("Texture size must be a power of two");
         }
 
-        const mipmapsCount = Math.round(Scalar.Log2(texture.width)) + 1;
+        const mipmapsCount = Scalar.ILog2(texture.width) + 1;
 
         // Gets everything ready.
         let engine = texture.getEngine() as Engine;