Browse Source

moving to constants

Benjamin Guignabert 5 years ago
parent
commit
033d0f232a

+ 36 - 0
src/Engines/constants.ts

@@ -484,4 +484,40 @@ export class Constants {
      * Detailled logging while loading
      * Detailled logging while loading
      */
      */
     public static readonly SCENELOADER_DETAILED_LOGGING = 3;
     public static readonly SCENELOADER_DETAILED_LOGGING = 3;
+
+    /**
+     * Constant used to retrieve the irradiance texture index in the textures array in the prepass
+     * using getIndex(Constants.PREPASS_IRRADIANCE_TEXTURE_TYPE)
+     */
+    public static readonly PREPASS_IRRADIANCE_TEXTURE_TYPE = 0;
+    /**
+     * Constant used to retrieve the position texture index in the textures array in the prepass
+     * using getIndex(Constants.PREPASS_POSITION_TEXTURE_INDEX)
+     */
+    public static readonly PREPASS_POSITION_TEXTURE_TYPE = 1;
+    /**
+     * Constant used to retrieve the velocity texture index in the textures array in the prepass
+     * using getIndex(Constants.PREPASS_VELOCITY_TEXTURE_INDEX)
+     */
+    public static readonly PREPASS_VELOCITY_TEXTURE_TYPE = 2;
+    /**
+     * Constant used to retrieve the reflectivity texture index in the textures array in the prepass
+     * using the getIndex(Constants.PREPASS_REFLECTIVITY_TEXTURE_TYPE)
+     */
+    public static readonly PREPASS_REFLECTIVITY_TEXTURE_TYPE = 3;
+    /**
+     * Constant used to retrieve the lit color texture index in the textures array in the prepass
+     * using the getIndex(Constants.PREPASS_COLOR_TEXTURE_TYPE)
+     */
+    public static readonly PREPASS_COLOR_TEXTURE_TYPE = 4;
+    /**
+     * Constant used to retrieve depth + normal index in the textures array in the prepass
+     * using the getIndex(Constants.PREPASS_DEPTHNORMAL_TEXTURE_TYPE)
+     */
+    public static readonly PREPASS_DEPTHNORMAL_TEXTURE_TYPE = 5;
+    /**
+     * Constant used to retrieve albedo index in the textures array in the prepass
+     * using the getIndex(Constants.PREPASS_ALBEDO_TEXTURE_TYPE)
+     */
+    public static readonly PREPASS_ALBEDO_TEXTURE_TYPE = 6;
 }
 }

+ 10 - 10
src/Materials/materialHelper.ts

@@ -1,24 +1,24 @@
 import { Logger } from "../Misc/logger";
 import { Logger } from "../Misc/logger";
 import { Nullable } from "../types";
 import { Nullable } from "../types";
+import { Camera } from "../Cameras/camera";
 import { Scene } from "../scene";
 import { Scene } from "../scene";
+import { Engine } from "../Engines/engine";
 import { EngineStore } from "../Engines/engineStore";
 import { EngineStore } from "../Engines/engineStore";
 import { AbstractMesh } from "../Meshes/abstractMesh";
 import { AbstractMesh } from "../Meshes/abstractMesh";
 import { Mesh } from "../Meshes/mesh";
 import { Mesh } from "../Meshes/mesh";
 import { VertexBuffer } from "../Meshes/buffer";
 import { VertexBuffer } from "../Meshes/buffer";
 import { Light } from "../Lights/light";
 import { Light } from "../Lights/light";
-import { PrePassRenderer } from "../Rendering/prePassRenderer";
+import { Constants } from "../Engines/constants";
 
 
 import { UniformBuffer } from "./uniformBuffer";
 import { UniformBuffer } from "./uniformBuffer";
 import { Effect, IEffectCreationOptions } from "./effect";
 import { Effect, IEffectCreationOptions } from "./effect";
+import { BaseTexture } from "../Materials/Textures/baseTexture";
+import { WebVRFreeCamera } from '../Cameras/VR/webVRCamera';
+import { MaterialDefines } from "./materialDefines";
 import { Color3 } from '../Maths/math.color';
 import { Color3 } from '../Maths/math.color';
+import { EffectFallbacks } from './effectFallbacks';
 import { ThinMaterialHelper } from './thinMaterialHelper';
 import { ThinMaterialHelper } from './thinMaterialHelper';
 
 
-declare type Engine = import("../Engines/engine").Engine;
-declare type Camera = import("../Cameras/camera").Camera;
-declare type BaseTexture = import("../Materials/Textures/baseTexture").BaseTexture;
-declare type WebVRFreeCamera = import("../Cameras/VR/webVRCamera").WebVRFreeCamera;
-declare type MaterialDefines = import("./materialDefines").MaterialDefines;
-declare type EffectFallbacks = import("./effectFallbacks").EffectFallbacks;
 /**
 /**
  * "Static Class" containing the most commonly used helper while dealing with material for rendering purpose.
  * "Static Class" containing the most commonly used helper while dealing with material for rendering purpose.
  *
  *
@@ -309,7 +309,7 @@ export class MaterialHelper {
             defines.PREPASS = true;
             defines.PREPASS = true;
             defines.SCENE_MRT_COUNT = scene.prePassRenderer.mrtCount;
             defines.SCENE_MRT_COUNT = scene.prePassRenderer.mrtCount;
 
 
-            const irradianceIndex = scene.prePassRenderer.getIndex(PrePassRenderer.IRRADIANCE_TEXTURE_TYPE);
+            const irradianceIndex = scene.prePassRenderer.getIndex(Constants.PREPASS_IRRADIANCE_TEXTURE_TYPE);
             if (irradianceIndex !== -1) {
             if (irradianceIndex !== -1) {
                 defines.PREPASS_IRRADIANCE = true;
                 defines.PREPASS_IRRADIANCE = true;
                 defines.PREPASS_IRRADIANCE_INDEX = irradianceIndex;
                 defines.PREPASS_IRRADIANCE_INDEX = irradianceIndex;
@@ -317,7 +317,7 @@ export class MaterialHelper {
                 defines.PREPASS_IRRADIANCE = false;
                 defines.PREPASS_IRRADIANCE = false;
             }
             }
 
 
-            const albedoIndex = scene.prePassRenderer.getIndex(PrePassRenderer.ALBEDO_TEXTURE_TYPE);
+            const albedoIndex = scene.prePassRenderer.getIndex(Constants.PREPASS_ALBEDO_TEXTURE_TYPE);
             if (albedoIndex !== -1) {
             if (albedoIndex !== -1) {
                 defines.PREPASS_ALBEDO = true;
                 defines.PREPASS_ALBEDO = true;
                 defines.PREPASS_ALBEDO_INDEX = albedoIndex;
                 defines.PREPASS_ALBEDO_INDEX = albedoIndex;
@@ -325,7 +325,7 @@ export class MaterialHelper {
                 defines.PREPASS_ALBEDO = false;
                 defines.PREPASS_ALBEDO = false;
             }
             }
 
 
-            const depthNormalIndex = scene.prePassRenderer.getIndex(PrePassRenderer.DEPTHNORMAL_TEXTURE_TYPE);
+            const depthNormalIndex = scene.prePassRenderer.getIndex(Constants.PREPASS_DEPTHNORMAL_TEXTURE_TYPE);
             if (depthNormalIndex !== -1) {
             if (depthNormalIndex !== -1) {
                 defines.PREPASS_DEPTHNORMAL = true;
                 defines.PREPASS_DEPTHNORMAL = true;
                 defines.PREPASS_DEPTHNORMAL_INDEX = depthNormalIndex;
                 defines.PREPASS_DEPTHNORMAL_INDEX = depthNormalIndex;

+ 4 - 3
src/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.ts

@@ -14,6 +14,7 @@ import { _TypeStore } from '../../../Misc/typeStore';
 import { EngineStore } from '../../../Engines/engineStore';
 import { EngineStore } from '../../../Engines/engineStore';
 import { SSAO2Configuration } from "../../../Rendering/ssao2Configuration";
 import { SSAO2Configuration } from "../../../Rendering/ssao2Configuration";
 import { PrePassRenderer } from "../../../Rendering/prePassRenderer";
 import { PrePassRenderer } from "../../../Rendering/prePassRenderer";
+import { Constants } from "../../../Engines/constants";
 
 
 import "../../../PostProcesses/RenderPipeline/postProcessRenderPipelineManagerSceneComponent";
 import "../../../PostProcesses/RenderPipeline/postProcessRenderPipelineManagerSceneComponent";
 
 
@@ -295,7 +296,7 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
             if (this._forceGeometryBuffer) {
             if (this._forceGeometryBuffer) {
                 effect.setTexture("depthNormalSampler", this._scene.enableGeometryBufferRenderer()!.getGBuffer().textures[0]);
                 effect.setTexture("depthNormalSampler", this._scene.enableGeometryBufferRenderer()!.getGBuffer().textures[0]);
             } else {
             } else {
-                effect.setTexture("depthNormalSampler", this._prePassRenderer.prePassRT.textures[this._prePassRenderer.getIndex(PrePassRenderer.DEPTHNORMAL_TEXTURE_TYPE)]);
+                effect.setTexture("depthNormalSampler", this._prePassRenderer.prePassRT.textures[this._prePassRenderer.getIndex(Constants.PREPASS_DEPTHNORMAL_TEXTURE_TYPE)]);
             }
             }
             effect.setArray("samplerOffsets", this._samplerOffsets);
             effect.setArray("samplerOffsets", this._samplerOffsets);
         };
         };
@@ -313,7 +314,7 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
             if (this._forceGeometryBuffer) {
             if (this._forceGeometryBuffer) {
                 effect.setTexture("depthNormalSampler", this._scene.enableGeometryBufferRenderer()!.getGBuffer().textures[0]);
                 effect.setTexture("depthNormalSampler", this._scene.enableGeometryBufferRenderer()!.getGBuffer().textures[0]);
             } else {
             } else {
-                effect.setTexture("depthNormalSampler", this._prePassRenderer.prePassRT.textures[this._prePassRenderer.getIndex(PrePassRenderer.DEPTHNORMAL_TEXTURE_TYPE)]);
+                effect.setTexture("depthNormalSampler", this._prePassRenderer.prePassRT.textures[this._prePassRenderer.getIndex(Constants.PREPASS_DEPTHNORMAL_TEXTURE_TYPE)]);
             }
             }
             effect.setArray("samplerOffsets", this._samplerOffsets);
             effect.setArray("samplerOffsets", this._samplerOffsets);
 
 
@@ -431,7 +432,7 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
                 effect.setTexture("depthSampler", this._scene.enableGeometryBufferRenderer()!.getGBuffer().textures[0]);
                 effect.setTexture("depthSampler", this._scene.enableGeometryBufferRenderer()!.getGBuffer().textures[0]);
                 effect.setTexture("normalSampler", this._scene.enableGeometryBufferRenderer()!.getGBuffer().textures[1]);
                 effect.setTexture("normalSampler", this._scene.enableGeometryBufferRenderer()!.getGBuffer().textures[1]);
             } else {
             } else {
-                effect.setTexture("depthNormalSampler", this._prePassRenderer.prePassRT.textures[this._prePassRenderer.getIndex(PrePassRenderer.DEPTHNORMAL_TEXTURE_TYPE)]);
+                effect.setTexture("depthNormalSampler", this._prePassRenderer.prePassRT.textures[this._prePassRenderer.getIndex(Constants.PREPASS_DEPTHNORMAL_TEXTURE_TYPE)]);
             }
             }
             effect.setTexture("randomSampler", this._randomTexture);
             effect.setTexture("randomSampler", this._randomTexture);
         };
         };

+ 3 - 4
src/PostProcesses/subSurfaceScatteringPostProcess.ts

@@ -6,7 +6,6 @@ import { PostProcess, PostProcessOptions } from "./postProcess";
 import { Engine } from "../Engines/engine";
 import { Engine } from "../Engines/engine";
 import { Scene } from "../scene";
 import { Scene } from "../scene";
 import { Constants } from "../Engines/constants";
 import { Constants } from "../Engines/constants";
-import { PrePassRenderer } from "../Rendering/prePassRenderer";
 import { Logger } from "../Misc/logger";
 import { Logger } from "../Misc/logger";
 
 
 import "../Shaders/imageProcessing.fragment";
 import "../Shaders/imageProcessing.fragment";
@@ -39,9 +38,9 @@ export class SubSurfaceScatteringPostProcess extends PostProcess {
             var texelSize = this.texelSize;
             var texelSize = this.texelSize;
             effect.setFloat("metersPerUnit", scene.subSurfaceConfiguration.metersPerUnit);
             effect.setFloat("metersPerUnit", scene.subSurfaceConfiguration.metersPerUnit);
             effect.setFloat2("texelSize", texelSize.x, texelSize.y);
             effect.setFloat2("texelSize", texelSize.x, texelSize.y);
-            effect.setTexture("irradianceSampler", scene.prePassRenderer.prePassRT.textures[scene.prePassRenderer.getIndex(PrePassRenderer.IRRADIANCE_TEXTURE_TYPE)]);
-            effect.setTexture("depthSampler", scene.prePassRenderer.prePassRT.textures[scene.prePassRenderer.getIndex(PrePassRenderer.DEPTHNORMAL_TEXTURE_TYPE)]);
-            effect.setTexture("albedoSampler", scene.prePassRenderer.prePassRT.textures[scene.prePassRenderer.getIndex(PrePassRenderer.ALBEDO_TEXTURE_TYPE)]);
+            effect.setTexture("irradianceSampler", scene.prePassRenderer.prePassRT.textures[scene.prePassRenderer.getIndex(Constants.PREPASS_IRRADIANCE_TEXTURE_TYPE)]);
+            effect.setTexture("depthSampler", scene.prePassRenderer.prePassRT.textures[scene.prePassRenderer.getIndex(Constants.PREPASS_DEPTHNORMAL_TEXTURE_TYPE)]);
+            effect.setTexture("albedoSampler", scene.prePassRenderer.prePassRT.textures[scene.prePassRenderer.getIndex(Constants.PREPASS_ALBEDO_TEXTURE_TYPE)]);
             effect.setFloat2("viewportSize",
             effect.setFloat2("viewportSize",
                 Math.tan(scene.activeCamera!.fov / 2) * scene.getEngine().getAspectRatio(scene.activeCamera!, true),
                 Math.tan(scene.activeCamera!.fov / 2) * scene.getEngine().getAspectRatio(scene.activeCamera!, true),
                 Math.tan(scene.activeCamera!.fov / 2));
                 Math.tan(scene.activeCamera!.fov / 2));

+ 9 - 46
src/Rendering/prePassRenderer.ts

@@ -9,7 +9,6 @@ import { Logger } from '../Misc/logger';
 import { _DevTools } from '../Misc/devTools';
 import { _DevTools } from '../Misc/devTools';
 import { Color4 } from "../Maths/math.color";
 import { Color4 } from "../Maths/math.color";
 import { PrePassEffectConfiguration } from "./prePassEffectConfiguration";
 import { PrePassEffectConfiguration } from "./prePassEffectConfiguration";
-
 /**
 /**
  * Renders a pre pass of the scene
  * Renders a pre pass of the scene
  * This means every mesh in the scene will be rendered to a render target texture
  * This means every mesh in the scene will be rendered to a render target texture
@@ -22,69 +21,33 @@ export class PrePassRenderer {
         throw _DevTools.WarnImport("PrePassRendererSceneComponent");
         throw _DevTools.WarnImport("PrePassRendererSceneComponent");
     }
     }
 
 
-    /**
-     * Constant used to retrieve the irradiance texture index in the textures array
-     * using getIndex(PrePassRenderer.IRRADIANCE_TEXTURE_TYPE)
-     */
-    public static readonly IRRADIANCE_TEXTURE_TYPE = 0;
-    /**
-     * Constant used to retrieve the position texture index in the textures array
-     * using getIndex(PrePassRenderer.POSITION_TEXTURE_INDEX)
-     */
-    public static readonly POSITION_TEXTURE_TYPE = 1;
-    /**
-     * Constant used to retrieve the velocity texture index in the textures array
-     * using getIndex(PrePassRenderer.VELOCITY_TEXTURE_INDEX)
-     */
-    public static readonly VELOCITY_TEXTURE_TYPE = 2;
-    /**
-     * Constant used to retrieve the reflectivity texture index in the textures array
-     * using the getIndex(PrePassRenderer.REFLECTIVITY_TEXTURE_TYPE)
-     */
-    public static readonly REFLECTIVITY_TEXTURE_TYPE = 3;
-    /**
-     * Constant used to retrieve the lit color texture index in the textures array
-     * using the getIndex(PrePassRenderer.COLOR_TEXTURE_TYPE)
-     */
-    public static readonly COLOR_TEXTURE_TYPE = 4;
-    /**
-     * Constant used to retrieve depth + normal index in the textures array
-     * using the getIndex(PrePassRenderer.DEPTHNORMAL_TEXTURE_TYPE)
-     */
-    public static readonly DEPTHNORMAL_TEXTURE_TYPE = 5;
-    /**
-     * Constant used to retrieve albedo index in the textures array
-     * using the getIndex(PrePassRenderer.ALBEDO_TEXTURE_TYPE)
-     */
-    public static readonly ALBEDO_TEXTURE_TYPE = 6;
-
     private _textureFormats = [
     private _textureFormats = [
         {
         {
-            type: PrePassRenderer.IRRADIANCE_TEXTURE_TYPE,
+            type: Constants.PREPASS_IRRADIANCE_TEXTURE_TYPE,
             format: Constants.TEXTURETYPE_HALF_FLOAT,
             format: Constants.TEXTURETYPE_HALF_FLOAT,
         },
         },
         {
         {
-            type: PrePassRenderer.POSITION_TEXTURE_TYPE,
+            type: Constants.PREPASS_POSITION_TEXTURE_TYPE,
             format: Constants.TEXTURETYPE_HALF_FLOAT,
             format: Constants.TEXTURETYPE_HALF_FLOAT,
         },
         },
         {
         {
-            type: PrePassRenderer.VELOCITY_TEXTURE_TYPE,
+            type: Constants.PREPASS_VELOCITY_TEXTURE_TYPE,
             format: Constants.TEXTURETYPE_HALF_FLOAT,
             format: Constants.TEXTURETYPE_HALF_FLOAT,
         },
         },
         {
         {
-            type: PrePassRenderer.REFLECTIVITY_TEXTURE_TYPE,
+            type: Constants.PREPASS_REFLECTIVITY_TEXTURE_TYPE,
             format: Constants.TEXTURETYPE_UNSIGNED_INT,
             format: Constants.TEXTURETYPE_UNSIGNED_INT,
         },
         },
         {
         {
-            type: PrePassRenderer.COLOR_TEXTURE_TYPE,
+            type: Constants.PREPASS_COLOR_TEXTURE_TYPE,
             format: Constants.TEXTURETYPE_HALF_FLOAT,
             format: Constants.TEXTURETYPE_HALF_FLOAT,
         },
         },
         {
         {
-            type: PrePassRenderer.DEPTHNORMAL_TEXTURE_TYPE,
+            type: Constants.PREPASS_DEPTHNORMAL_TEXTURE_TYPE,
             format: Constants.TEXTURETYPE_HALF_FLOAT,
             format: Constants.TEXTURETYPE_HALF_FLOAT,
         },
         },
         {
         {
-            type: PrePassRenderer.ALBEDO_TEXTURE_TYPE,
+            type: Constants.PREPASS_ALBEDO_TEXTURE_TYPE,
             format: Constants.TEXTURETYPE_UNSIGNED_INT,
             format: Constants.TEXTURETYPE_UNSIGNED_INT,
         },
         },
 ];
 ];
@@ -390,8 +353,8 @@ export class PrePassRenderer {
             this._textureIndices[this._textureFormats[i].type] = -1;
             this._textureIndices[this._textureFormats[i].type] = -1;
         }
         }
 
 
-        this._textureIndices[PrePassRenderer.COLOR_TEXTURE_TYPE] = 0;
-        this._mrtLayout = [PrePassRenderer.COLOR_TEXTURE_TYPE];
+        this._textureIndices[Constants.PREPASS_COLOR_TEXTURE_TYPE] = 0;
+        this._mrtLayout = [Constants.PREPASS_COLOR_TEXTURE_TYPE];
         this._mrtFormats = [Constants.TEXTURETYPE_HALF_FLOAT];
         this._mrtFormats = [Constants.TEXTURETYPE_HALF_FLOAT];
         this.mrtCount = 1;
         this.mrtCount = 1;
     }
     }

+ 2 - 2
src/Rendering/ssao2Configuration.ts

@@ -1,4 +1,4 @@
-import { PrePassRenderer } from "./prePassRenderer";
+import { Constants } from "../Engines/constants";
 import { PrePassEffectConfiguration } from "./prePassEffectConfiguration";
 import { PrePassEffectConfiguration } from "./prePassEffectConfiguration";
 import { _DevTools } from '../Misc/devTools';
 import { _DevTools } from '../Misc/devTools';
 
 
@@ -21,7 +21,7 @@ export class SSAO2Configuration implements PrePassEffectConfiguration {
      * Textures that should be present in the MRT for this effect to work
      * Textures that should be present in the MRT for this effect to work
      */
      */
     public readonly texturesRequired: number[] = [
     public readonly texturesRequired: number[] = [
-        PrePassRenderer.DEPTHNORMAL_TEXTURE_TYPE
+        Constants.PREPASS_DEPTHNORMAL_TEXTURE_TYPE
     ];
     ];
 
 
     /**
     /**

+ 5 - 5
src/Rendering/subSurfaceConfiguration.ts

@@ -2,10 +2,10 @@ import { Logger } from "../Misc/logger";
 import { Scene } from "../scene";
 import { Scene } from "../scene";
 import { Color3 } from "../Maths/math.color";
 import { Color3 } from "../Maths/math.color";
 import { SubSurfaceScatteringPostProcess } from "../PostProcesses/subSurfaceScatteringPostProcess";
 import { SubSurfaceScatteringPostProcess } from "../PostProcesses/subSurfaceScatteringPostProcess";
-import { PrePassRenderer } from "./prePassRenderer";
 import { SceneComponentConstants } from "../sceneComponent";
 import { SceneComponentConstants } from "../sceneComponent";
 import { PrePassEffectConfiguration } from "./prePassEffectConfiguration";
 import { PrePassEffectConfiguration } from "./prePassEffectConfiguration";
 import { _DevTools } from '../Misc/devTools';
 import { _DevTools } from '../Misc/devTools';
+import { Constants } from "../Engines/constants";
 
 
 /**
 /**
  * Contains all parameters needed for the prepass to perform
  * Contains all parameters needed for the prepass to perform
@@ -75,10 +75,10 @@ export class SubSurfaceConfiguration implements PrePassEffectConfiguration {
      * Textures that should be present in the MRT for this effect to work
      * Textures that should be present in the MRT for this effect to work
      */
      */
     public readonly texturesRequired: number[] = [
     public readonly texturesRequired: number[] = [
-        PrePassRenderer.DEPTHNORMAL_TEXTURE_TYPE,
-        PrePassRenderer.ALBEDO_TEXTURE_TYPE,
-        PrePassRenderer.COLOR_TEXTURE_TYPE,
-        PrePassRenderer.IRRADIANCE_TEXTURE_TYPE,
+        Constants.PREPASS_DEPTHNORMAL_TEXTURE_TYPE,
+        Constants.PREPASS_ALBEDO_TEXTURE_TYPE,
+        Constants.PREPASS_COLOR_TEXTURE_TYPE,
+        Constants.PREPASS_IRRADIANCE_TEXTURE_TYPE,
     ];
     ];
 
 
     private _scene: Scene;
     private _scene: Scene;