浏览代码

enabling filtering on probes by default
Unlinking baseTexture and HdrFiltering
some linting

Benjamin Guignabert 5 年之前
父节点
当前提交
3a0c57d91e

+ 12 - 0
src/Engines/constants.ts

@@ -241,6 +241,18 @@ export class Constants {
     /** Equirectangular Fixed Mirrored coordinates mode */
     public static readonly TEXTURE_FIXED_EQUIRECTANGULAR_MIRRORED_MODE = 9;
 
+    /** Offline (baking) quality for texture filtering */
+    public static readonly TEXTURE_FILTERING_QUALITY_OFFLINE = 4096;
+
+    /** High quality for texture filtering */
+    public static readonly TEXTURE_FILTERING_QUALITY_HIGH = 64;
+
+    /** Medium quality for texture filtering */
+    public static readonly TEXTURE_FILTERING_QUALITY_MEDIUM = 16;
+
+    /** Low quality for texture filtering */
+    public static readonly TEXTURE_FILTERING_QUALITY_LOW = 8;
+
     // Texture rescaling mode
     /** Defines that texture rescaling will use a floor to find the closer power of 2 size */
     public static readonly SCALEMODE_FLOOR = 1;

+ 9 - 29
src/Materials/Textures/Filtering/hdrFiltering.ts

@@ -21,7 +21,7 @@ interface IHDRFilteringOptions {
     hdrScale?: number;
 
     /**
-     * Quality of the filter. Should be `HDRFiltering.QUALITY_OFFLINE` for prefiltering
+     * Quality of the filter. Should be `Constants.TEXTURE_FILTERING_QUALITY_OFFLINE` for prefiltering
      */
     quality?: number;
 }
@@ -39,10 +39,10 @@ export class HDRFiltering {
     private _lodGenerationScale: number = 0.8;
 
     /**
-     * Quality switch for prefiltering. Should be set to ` HDRFiltering.QUALITY_OFFLINE` unless
+     * Quality switch for prefiltering. Should be set to `Constants.TEXTURE_FILTERING_QUALITY_OFFLINE` unless
      * you care about baking speed.
      */
-    public quality: number = HDRFiltering.QUALITY_OFFLINE;
+    public quality: number = Constants.TEXTURE_FILTERING_QUALITY_OFFLINE;
 
     /**
      * Scales pixel intensity for the input HDR map.
@@ -50,26 +50,6 @@ export class HDRFiltering {
     public hdrScale: number = 1;
 
     /**
-     * Offline (baking) quality
-     */
-    public static readonly QUALITY_OFFLINE = 4096;
-
-    /**
-     * High quality
-     */
-    public static readonly QUALITY_HIGH = 64;
-
-    /**
-     * Medium quality
-     */
-    public static readonly QUALITY_MEDIUM = 16;
-
-    /**
-     * Low quality
-     */
-    public static readonly QUALITY_LOW = 8;
-
-    /**
      * Instantiates HDR filter for reflection maps
      *
      * @param engine Thin engine
@@ -82,7 +62,7 @@ export class HDRFiltering {
         this.quality = options.hdrScale || this.quality;
     }
 
-    private createRenderTarget(size: number): InternalTexture {
+    private _createRenderTarget(size: number): InternalTexture {
         const texture = this._engine.createRenderTargetCubeTexture(size, {
             format: Constants.TEXTUREFORMAT_RGBA,
             type: Constants.TEXTURETYPE_FLOAT,
@@ -101,13 +81,13 @@ export class HDRFiltering {
         return texture;
     }
 
-    private prefilterInternal(texture: BaseTexture): BaseTexture {
+    private _prefilterInternal(texture: BaseTexture): BaseTexture {
         // const nbRoughnessStops = 2;
         const width = texture.getSize().width;
         const mipmapsCount = Math.round(Scalar.Log2(width)) + 1;
 
         const effect = this._effectWrapper.effect;
-        const outputTexture = this.createRenderTarget(width);
+        const outputTexture = this._createRenderTarget(width);
         this._effectRenderer.setViewport();
 
         const intTexture = texture.getInternalTexture();
@@ -157,7 +137,7 @@ export class HDRFiltering {
         return texture;
     }
 
-    private createEffect(texture: BaseTexture, onCompiled?: Nullable<(effect: Effect) => void>): EffectWrapper {
+    private _createEffect(texture: BaseTexture, onCompiled?: Nullable<(effect: Effect) => void>): EffectWrapper {
         const defines = [];
         if (texture.gammaSpace) {
             defines.push("#define GAMMA_INPUT");
@@ -201,7 +181,7 @@ export class HDRFiltering {
     public prefilter(texture: BaseTexture, onFinished?: () => void) {
         return new Promise((resolve) => {
             const callback = () => {
-                this.prefilterInternal(texture);
+                this._prefilterInternal(texture);
                 this._effectRenderer.dispose();
                 this._effectWrapper.dispose();
                 resolve();
@@ -211,7 +191,7 @@ export class HDRFiltering {
             };
 
             this._effectRenderer = new EffectRenderer(this._engine);
-            this._effectWrapper = this.createEffect(texture, callback);
+            this._effectWrapper = this._createEffect(texture, callback);
         });
     }
 }

+ 1 - 2
src/Materials/Textures/baseTexture.ts

@@ -9,7 +9,6 @@ import { Constants } from "../../Engines/constants";
 import { IAnimatable } from '../../Animations/animatable.interface';
 import { GUID } from '../../Misc/guid';
 import { ISize, Size } from '../../Maths/math.size';
-import { HDRFiltering } from "./Filtering/hdrFiltering";
 
 import "../../Misc/fileTools";
 import { ThinEngine } from '../../Engines/thinEngine';
@@ -361,7 +360,7 @@ export class BaseTexture implements IAnimatable {
         }
     }
 
-    private _realTimeFilteringQuality: number = HDRFiltering.QUALITY_MEDIUM;
+    private _realTimeFilteringQuality: number = Constants.TEXTURE_FILTERING_QUALITY_LOW;
     /**
      * Quality switch for realtime filtering
      */

+ 2 - 1
src/Probes/reflectionProbe.ts

@@ -92,7 +92,8 @@ export class ReflectionProbe {
         this._scene.reflectionProbes.push(this);
 
         this._renderTargetTexture = new RenderTargetTexture(name, size, scene, generateMipMaps, true, useFloat ? Constants.TEXTURETYPE_FLOAT : Constants.TEXTURETYPE_UNSIGNED_INT, true);
-
+        this._renderTargetTexture.realTimeFiltering = true;
+        
         this._renderTargetTexture.onBeforeRenderObservable.add((faceIndex: number) => {
             switch (faceIndex) {
                 case 0:

+ 43 - 16
src/Shaders/ShadersInclude/helperFunctions.fx

@@ -73,22 +73,49 @@ float square(float value)
     return value * value;
 }
 
-// https://learnopengl.com/PBR/IBL/Specular-IBL
-// Hammersley
-float radicalInverse_VdC(uint bits) 
-{
-    bits = (bits << 16u) | (bits >> 16u);
-    bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
-    bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
-    bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
-    bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
-    return float(bits) * 2.3283064365386963e-10; // / 0x100000000
-}
-
-vec2 hammersley(uint i, uint N)
-{
-    return vec2(float(i)/float(N), radicalInverse_VdC(i));
-}
+#ifdef WEBGL2
+    // https://learnopengl.com/PBR/IBL/Specular-IBL
+    // Hammersley
+    float radicalInverse_VdC(uint bits) 
+    {
+        bits = (bits << 16u) | (bits >> 16u);
+        bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
+        bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
+        bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
+        bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
+        return float(bits) * 2.3283064365386963e-10; // / 0x100000000
+    }
+
+    vec2 hammersley(uint i, uint N)
+    {
+        return vec2(float(i)/float(N), radicalInverse_VdC(i));
+    }
+#else
+    float vanDerCorpus(uint n, uint base)
+    {
+        float invBase = 1.0 / float(base);
+        float denom   = 1.0;
+        float result  = 0.0;
+
+        for(uint i = 0u; i < 32u; ++i)
+        {
+            if(n > 0u)
+            {
+                denom   = mod(float(n), 2.0);
+                result += denom * invBase;
+                invBase = invBase / 2.0;
+                n       = uint(float(n) / 2.0);
+            }
+        }
+
+        return result;
+    }
+
+    vec2 hammersley(uint i, uint N)
+    {
+        return vec2(float(i)/float(N), vanDerCorpus(i, 2u));
+    }
+#endif
 
 float log4(float x) {
     return log2(x) / 2.;