Browse Source

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

sebavan 5 years ago
parent
commit
1a7cb8f10a

+ 3 - 2
dist/preview release/babylon.d.ts

@@ -32780,8 +32780,9 @@ declare module BABYLON {
         /**
          * Force the mipmap generation for the given render target texture
          * @param texture defines the render target texture to use
+         * @param unbind defines whether or not to unbind the texture after generation. Defaults to true.
          */
-        generateMipMapsForCubemap(texture: InternalTexture): void;
+        generateMipMapsForCubemap(texture: InternalTexture, unbind?: boolean): void;
         /** States */
         /**
          * Set various states to the webGL context
@@ -51293,7 +51294,7 @@ declare module BABYLON {
         private _vertexBuffers;
         private _indexBuffer;
         private _effect;
-        private _alphaTestEffect;
+        private _previousDefines;
         /**
          * An event triggered when the layer is disposed.
          */

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/babylon.js


+ 25 - 9
dist/preview release/babylon.max.js

@@ -34376,13 +34376,17 @@ var Engine = /** @class */ (function (_super) {
     /**
      * Force the mipmap generation for the given render target texture
      * @param texture defines the render target texture to use
+     * @param unbind defines whether or not to unbind the texture after generation. Defaults to true.
      */
-    Engine.prototype.generateMipMapsForCubemap = function (texture) {
+    Engine.prototype.generateMipMapsForCubemap = function (texture, unbind) {
+        if (unbind === void 0) { unbind = true; }
         if (texture.generateMipMaps) {
             var gl = this._gl;
             this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, texture, true);
             gl.generateMipmap(gl.TEXTURE_CUBE_MAP);
-            this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);
+            if (unbind) {
+                this._bindTextureDirectly(gl.TEXTURE_CUBE_MAP, null);
+            }
         }
     };
     /** States */
@@ -53147,9 +53151,6 @@ var Layer = /** @class */ (function () {
         var vertexBuffer = new _Meshes_buffer__WEBPACK_IMPORTED_MODULE_4__["VertexBuffer"](engine, vertices, _Meshes_buffer__WEBPACK_IMPORTED_MODULE_4__["VertexBuffer"].PositionKind, false, false, 2);
         this._vertexBuffers[_Meshes_buffer__WEBPACK_IMPORTED_MODULE_4__["VertexBuffer"].PositionKind] = vertexBuffer;
         this._createIndexBuffer();
-        // Effects
-        this._effect = engine.createEffect("layer", [_Meshes_buffer__WEBPACK_IMPORTED_MODULE_4__["VertexBuffer"].PositionKind], ["textureMatrix", "color", "scale", "offset"], ["textureSampler"], "");
-        this._alphaTestEffect = engine.createEffect("layer", [_Meshes_buffer__WEBPACK_IMPORTED_MODULE_4__["VertexBuffer"].PositionKind], ["textureMatrix", "color", "scale", "offset"], ["textureSampler"], "#define ALPHATEST");
     }
     Object.defineProperty(Layer.prototype, "onDispose", {
         /**
@@ -53217,9 +53218,21 @@ var Layer = /** @class */ (function () {
      * Renders the layer in the scene.
      */
     Layer.prototype.render = function () {
-        var currentEffect = this.alphaTest ? this._alphaTestEffect : this._effect;
+        var engine = this._scene.getEngine();
+        var defines = "";
+        if (this.alphaTest) {
+            defines = "#define ALPHATEST";
+        }
+        if (this.texture && !this.texture.gammaSpace) {
+            defines += "\r\n#define LINEAR";
+        }
+        if (this._previousDefines !== defines) {
+            this._previousDefines = defines;
+            this._effect = engine.createEffect("layer", [_Meshes_buffer__WEBPACK_IMPORTED_MODULE_4__["VertexBuffer"].PositionKind], ["textureMatrix", "color", "scale", "offset"], ["textureSampler"], defines);
+        }
+        var currentEffect = this._effect;
         // Check
-        if (!currentEffect.isReady() || !this.texture || !this.texture.isReady()) {
+        if (!currentEffect || !currentEffect.isReady() || !this.texture || !this.texture.isReady()) {
             return;
         }
         var engine = this._scene.getEngine();
@@ -79086,7 +79099,8 @@ var _DDSTextureLoader = /** @class */ (function () {
             engine._unpackFlipY(info.isCompressed);
             _Misc_dds__WEBPACK_IMPORTED_MODULE_2__["DDSTools"].UploadDDSLevels(engine, texture, data, info, loadMipmap, 6);
             if (!info.isFourCC && info.mipmapCount === 1) {
-                engine.generateMipMapsForCubemap(texture);
+                // Do not unbind as we still need to set the parameters.
+                engine.generateMipMapsForCubemap(texture, false);
             }
         }
         engine._setCubeMapTextureParams(loadMipmap);
@@ -164633,9 +164647,11 @@ var kernelBlurVertexShader = { name: name, shader: shader };
 __webpack_require__.r(__webpack_exports__);
 /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "layerPixelShader", function() { return layerPixelShader; });
 /* harmony import */ var _Materials_effect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../Materials/effect */ "./Materials/effect.ts");
+/* harmony import */ var _ShadersInclude_helperFunctions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ShadersInclude/helperFunctions */ "./Shaders/ShadersInclude/helperFunctions.ts");
+
 
 var name = 'layerPixelShader';
-var shader = "\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform vec4 color;\nvoid main(void) {\nvec4 baseColor=texture2D(textureSampler,vUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\ngl_FragColor=baseColor*color;\n}";
+var shader = "\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform vec4 color;\n\n#include<helperFunctions>\nvoid main(void) {\nvec4 baseColor=texture2D(textureSampler,vUV);\n#ifdef LINEAR\nbaseColor.rgb=toGammaSpace(baseColor.rgb);\n#endif\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\ngl_FragColor=baseColor*color;\n}";
 _Materials_effect__WEBPACK_IMPORTED_MODULE_0__["Effect"].ShadersStore[name] = shader;
 /** @hidden */
 var layerPixelShader = { name: name, shader: shader };

File diff suppressed because it is too large
+ 1 - 1
dist/preview release/babylon.max.js.map


+ 7 - 4
dist/preview release/babylon.module.d.ts

@@ -33761,8 +33761,9 @@ declare module "babylonjs/Engines/engine" {
         /**
          * Force the mipmap generation for the given render target texture
          * @param texture defines the render target texture to use
+         * @param unbind defines whether or not to unbind the texture after generation. Defaults to true.
          */
-        generateMipMapsForCubemap(texture: InternalTexture): void;
+        generateMipMapsForCubemap(texture: InternalTexture, unbind?: boolean): void;
         /** States */
         /**
          * Set various states to the webGL context
@@ -53505,6 +53506,7 @@ declare module "babylonjs/Layers/layerSceneComponent" {
     }
 }
 declare module "babylonjs/Shaders/layer.fragment" {
+    import "babylonjs/Shaders/ShadersInclude/helperFunctions";
     /** @hidden */
     export var layerPixelShader: {
         name: string;
@@ -53585,7 +53587,7 @@ declare module "babylonjs/Layers/layer" {
         private _vertexBuffers;
         private _indexBuffer;
         private _effect;
-        private _alphaTestEffect;
+        private _previousDefines;
         /**
          * An event triggered when the layer is disposed.
          */
@@ -101713,8 +101715,9 @@ declare module BABYLON {
         /**
          * Force the mipmap generation for the given render target texture
          * @param texture defines the render target texture to use
+         * @param unbind defines whether or not to unbind the texture after generation. Defaults to true.
          */
-        generateMipMapsForCubemap(texture: InternalTexture): void;
+        generateMipMapsForCubemap(texture: InternalTexture, unbind?: boolean): void;
         /** States */
         /**
          * Set various states to the webGL context
@@ -120226,7 +120229,7 @@ declare module BABYLON {
         private _vertexBuffers;
         private _indexBuffer;
         private _effect;
-        private _alphaTestEffect;
+        private _previousDefines;
         /**
          * An event triggered when the layer is disposed.
          */

+ 3 - 2
dist/preview release/documentation.d.ts

@@ -32780,8 +32780,9 @@ declare module BABYLON {
         /**
          * Force the mipmap generation for the given render target texture
          * @param texture defines the render target texture to use
+         * @param unbind defines whether or not to unbind the texture after generation. Defaults to true.
          */
-        generateMipMapsForCubemap(texture: InternalTexture): void;
+        generateMipMapsForCubemap(texture: InternalTexture, unbind?: boolean): void;
         /** States */
         /**
          * Set various states to the webGL context
@@ -51293,7 +51294,7 @@ declare module BABYLON {
         private _vertexBuffers;
         private _indexBuffer;
         private _effect;
-        private _alphaTestEffect;
+        private _previousDefines;
         /**
          * An event triggered when the layer is disposed.
          */

+ 1 - 1
dist/preview release/packagesSizeBaseLine.json

@@ -1 +1 @@
-{"thinEngineOnly":116685,"engineOnly":153594,"sceneOnly":499004,"minGridMaterial":629004,"minStandardMaterial":752936}
+{"thinEngineOnly":116685,"engineOnly":153618,"sceneOnly":499028,"minGridMaterial":629028,"minStandardMaterial":752960}

+ 7 - 4
dist/preview release/viewer/babylon.module.d.ts

@@ -33761,8 +33761,9 @@ declare module "babylonjs/Engines/engine" {
         /**
          * Force the mipmap generation for the given render target texture
          * @param texture defines the render target texture to use
+         * @param unbind defines whether or not to unbind the texture after generation. Defaults to true.
          */
-        generateMipMapsForCubemap(texture: InternalTexture): void;
+        generateMipMapsForCubemap(texture: InternalTexture, unbind?: boolean): void;
         /** States */
         /**
          * Set various states to the webGL context
@@ -53505,6 +53506,7 @@ declare module "babylonjs/Layers/layerSceneComponent" {
     }
 }
 declare module "babylonjs/Shaders/layer.fragment" {
+    import "babylonjs/Shaders/ShadersInclude/helperFunctions";
     /** @hidden */
     export var layerPixelShader: {
         name: string;
@@ -53585,7 +53587,7 @@ declare module "babylonjs/Layers/layer" {
         private _vertexBuffers;
         private _indexBuffer;
         private _effect;
-        private _alphaTestEffect;
+        private _previousDefines;
         /**
          * An event triggered when the layer is disposed.
          */
@@ -101713,8 +101715,9 @@ declare module BABYLON {
         /**
          * Force the mipmap generation for the given render target texture
          * @param texture defines the render target texture to use
+         * @param unbind defines whether or not to unbind the texture after generation. Defaults to true.
          */
-        generateMipMapsForCubemap(texture: InternalTexture): void;
+        generateMipMapsForCubemap(texture: InternalTexture, unbind?: boolean): void;
         /** States */
         /**
          * Set various states to the webGL context
@@ -120226,7 +120229,7 @@ declare module BABYLON {
         private _vertexBuffers;
         private _indexBuffer;
         private _effect;
-        private _alphaTestEffect;
+        private _previousDefines;
         /**
          * An event triggered when the layer is disposed.
          */

File diff suppressed because it is too large
+ 4 - 4
dist/preview release/viewer/babylon.viewer.js


File diff suppressed because it is too large
+ 1 - 1
dist/preview release/viewer/babylon.viewer.max.js


+ 23 - 14
src/Layers/layer.ts

@@ -81,7 +81,7 @@ export class Layer {
     private _vertexBuffers: { [key: string]: Nullable<VertexBuffer> } = {};
     private _indexBuffer: Nullable<DataBuffer>;
     private _effect: Effect;
-    private _alphaTestEffect: Effect;
+    private _previousDefines: string;
 
     /**
      * An event triggered when the layer is disposed.
@@ -179,17 +179,6 @@ export class Layer {
         this._vertexBuffers[VertexBuffer.PositionKind] = vertexBuffer;
 
         this._createIndexBuffer();
-
-        // Effects
-        this._effect = engine.createEffect("layer",
-            [VertexBuffer.PositionKind],
-            ["textureMatrix", "color", "scale", "offset"],
-            ["textureSampler"], "");
-
-        this._alphaTestEffect = engine.createEffect("layer",
-            [VertexBuffer.PositionKind],
-            ["textureMatrix", "color", "scale", "offset"],
-            ["textureSampler"], "#define ALPHATEST");
     }
 
     private _createIndexBuffer(): void {
@@ -223,10 +212,30 @@ export class Layer {
      * Renders the layer in the scene.
      */
     public render(): void {
-        var currentEffect = this.alphaTest ? this._alphaTestEffect : this._effect;
+
+        var engine = this._scene.getEngine();
+
+        var defines = "";
+
+        if (this.alphaTest) {
+            defines = "#define ALPHATEST";
+        }
+
+        if (this.texture && !this.texture.gammaSpace) {
+            defines += "\r\n#define LINEAR";
+        }
+
+        if (this._previousDefines !== defines) {
+            this._previousDefines = defines;
+            this._effect = engine.createEffect("layer",
+                [VertexBuffer.PositionKind],
+                ["textureMatrix", "color", "scale", "offset"],
+                ["textureSampler"], defines);
+        }
+        var currentEffect = this._effect;
 
         // Check
-        if (!currentEffect.isReady() || !this.texture || !this.texture.isReady()) {
+        if (!currentEffect || !currentEffect.isReady() || !this.texture || !this.texture.isReady()) {
             return;
         }
 

+ 9 - 0
src/Shaders/layer.fragment.fx

@@ -5,13 +5,22 @@ uniform sampler2D textureSampler;
 // Color
 uniform vec4 color;
 
+// Helper functions
+#include<helperFunctions>
+
 void main(void) {
 	vec4 baseColor = texture2D(textureSampler, vUV);
+	
+#ifdef LINEAR
+	baseColor.rgb = toGammaSpace(baseColor.rgb);
+#endif
 
 #ifdef ALPHATEST
 	if (baseColor.a < 0.4)
 		discard;
 #endif
 
+
+
 	gl_FragColor = baseColor * color;
 }