Browse Source

Merge remote-tracking branch 'upstream/master' into InProgress

sebastien 7 years ago
parent
commit
07ef5781d1

File diff suppressed because it is too large
+ 11459 - 11451
Playground/babylon.d.txt


+ 10 - 0
Tools/Gulp/gulp-addES6Exports.js

@@ -34,6 +34,16 @@ globalObject["${base}"] = ${base}${(subModule && !extendsRoot) ? '.' + varName :
                 match = matcher.exec(fileContent);
             }
 
+            let enumMatcher = new RegExp(`\\(${base}\\.([A-Za-z0-9].*)= {}\\)`, "g");
+            let enumMatch = enumMatcher.exec(fileContent);
+            while (enumMatch != null) {
+                if (enumMatch[1]) {
+                    listOfExports.push(enumMatch[1]);
+                }
+                enumMatch = enumMatcher.exec(fileContent);
+            }
+
+
             let exportsText = '';
             listOfExports.forEach(cls => {
                 exportsText += `var ${cls} = ${base}.${cls};`;

File diff suppressed because it is too large
+ 14647 - 14638
dist/preview release/babylon.d.ts


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


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


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


File diff suppressed because it is too large
+ 15193 - 15184
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


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


+ 52 - 32
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js

@@ -13160,35 +13160,6 @@ var BABYLON;
                 }
             });
         };
-        Engine.prototype._getInternalFormat = function (format) {
-            var internalFormat = this._gl.RGBA;
-            switch (format) {
-                case Engine.TEXTUREFORMAT_ALPHA:
-                    internalFormat = this._gl.ALPHA;
-                    break;
-                case Engine.TEXTUREFORMAT_LUMINANCE:
-                    internalFormat = this._gl.LUMINANCE;
-                    break;
-                case Engine.TEXTUREFORMAT_LUMINANCE_ALPHA:
-                    internalFormat = this._gl.LUMINANCE_ALPHA;
-                    break;
-                case Engine.TEXTUREFORMAT_RGB:
-                case Engine.TEXTUREFORMAT_RGB32F:
-                    internalFormat = this._gl.RGB;
-                    break;
-                case Engine.TEXTUREFORMAT_RGBA:
-                case Engine.TEXTUREFORMAT_RGBA32F:
-                    internalFormat = this._gl.RGBA;
-                    break;
-                case Engine.TEXTUREFORMAT_R32F:
-                    internalFormat = this._gl.RED;
-                    break;
-                case Engine.TEXTUREFORMAT_RG32F:
-                    internalFormat = this._gl.RG;
-                    break;
-            }
-            return internalFormat;
-        };
         Engine.prototype.updateRawTexture = function (texture, data, format, invertY, compression, type) {
             if (compression === void 0) { compression = null; }
             if (type === void 0) { type = Engine.TEXTURETYPE_UNSIGNED_INT; }
@@ -13537,6 +13508,7 @@ var BABYLON;
                 fullOptions.generateStencilBuffer = fullOptions.generateDepthBuffer && options.generateStencilBuffer;
                 fullOptions.type = options.type === undefined ? Engine.TEXTURETYPE_UNSIGNED_INT : options.type;
                 fullOptions.samplingMode = options.samplingMode === undefined ? BABYLON.Texture.TRILINEAR_SAMPLINGMODE : options.samplingMode;
+                fullOptions.format = options.format === undefined ? Engine.TEXTUREFORMAT_RGBA : options.format;
             }
             else {
                 fullOptions.generateMipMaps = options;
@@ -13544,6 +13516,7 @@ var BABYLON;
                 fullOptions.generateStencilBuffer = false;
                 fullOptions.type = Engine.TEXTURETYPE_UNSIGNED_INT;
                 fullOptions.samplingMode = BABYLON.Texture.TRILINEAR_SAMPLINGMODE;
+                fullOptions.format = Engine.TEXTUREFORMAT_RGBA;
             }
             if (fullOptions.type === Engine.TEXTURETYPE_FLOAT && !this._caps.textureFloatLinearFiltering) {
                 // if floating point linear (gl.FLOAT) then force to NEAREST_SAMPLINGMODE
@@ -13567,7 +13540,7 @@ var BABYLON;
             gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filters.min);
             gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
             gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
-            gl.texImage2D(gl.TEXTURE_2D, 0, this._getRGBABufferInternalSizedFormat(fullOptions.type), width, height, 0, gl.RGBA, this._getWebGLTextureType(fullOptions.type), null);
+            gl.texImage2D(gl.TEXTURE_2D, 0, this._getRGBABufferInternalSizedFormat(fullOptions.type, fullOptions.format), width, height, 0, this._getInternalFormat(fullOptions.format), this._getWebGLTextureType(fullOptions.type), null);
             // Create the framebuffer
             var framebuffer = gl.createFramebuffer();
             this.bindUnboundFramebuffer(framebuffer);
@@ -13847,7 +13820,7 @@ var BABYLON;
             this._gl.compressedTexImage2D(target, lod, internalFormat, width, height, 0, data);
         };
         Engine.prototype.createRenderTargetCubeTexture = function (size, options) {
-            var fullOptions = __assign({ generateMipMaps: true, generateDepthBuffer: true, generateStencilBuffer: false, type: Engine.TEXTURETYPE_UNSIGNED_INT, samplingMode: BABYLON.Texture.TRILINEAR_SAMPLINGMODE }, options);
+            var fullOptions = __assign({ generateMipMaps: true, generateDepthBuffer: true, generateStencilBuffer: false, type: Engine.TEXTURETYPE_UNSIGNED_INT, samplingMode: BABYLON.Texture.TRILINEAR_SAMPLINGMODE, format: Engine.TEXTUREFORMAT_RGBA }, options);
             fullOptions.generateStencilBuffer = fullOptions.generateDepthBuffer && fullOptions.generateStencilBuffer;
             if (fullOptions.type === Engine.TEXTURETYPE_FLOAT && !this._caps.textureFloatLinearFiltering) {
                 // if floating point linear (gl.FLOAT) then force to NEAREST_SAMPLINGMODE
@@ -13870,7 +13843,7 @@ var BABYLON;
             gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
             gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
             for (var face = 0; face < 6; face++) {
-                gl.texImage2D((gl.TEXTURE_CUBE_MAP_POSITIVE_X + face), 0, this._getRGBABufferInternalSizedFormat(fullOptions.type), size, size, 0, gl.RGBA, this._getWebGLTextureType(fullOptions.type), null);
+                gl.texImage2D((gl.TEXTURE_CUBE_MAP_POSITIVE_X + face), 0, this._getRGBABufferInternalSizedFormat(fullOptions.type, fullOptions.format), size, size, 0, this._getInternalFormat(fullOptions.format), this._getWebGLTextureType(fullOptions.type), null);
             }
             // Create the framebuffer
             var framebuffer = gl.createFramebuffer();
@@ -15123,9 +15096,44 @@ var BABYLON;
             return this._gl.UNSIGNED_BYTE;
         };
         ;
+        Engine.prototype._getInternalFormat = function (format) {
+            var internalFormat = this._gl.RGBA;
+            switch (format) {
+                case Engine.TEXTUREFORMAT_ALPHA:
+                    internalFormat = this._gl.ALPHA;
+                    break;
+                case Engine.TEXTUREFORMAT_LUMINANCE:
+                    internalFormat = this._gl.LUMINANCE;
+                    break;
+                case Engine.TEXTUREFORMAT_LUMINANCE_ALPHA:
+                    internalFormat = this._gl.LUMINANCE_ALPHA;
+                    break;
+                case Engine.TEXTUREFORMAT_RGB:
+                case Engine.TEXTUREFORMAT_RGB32F:
+                    internalFormat = this._gl.RGB;
+                    break;
+                case Engine.TEXTUREFORMAT_RGBA:
+                case Engine.TEXTUREFORMAT_RGBA32F:
+                    internalFormat = this._gl.RGBA;
+                    break;
+                case Engine.TEXTUREFORMAT_R32F:
+                    internalFormat = this._gl.RED;
+                    break;
+                case Engine.TEXTUREFORMAT_RG32F:
+                    internalFormat = this._gl.RG;
+                    break;
+            }
+            return internalFormat;
+        };
         /** @ignore */
         Engine.prototype._getRGBABufferInternalSizedFormat = function (type, format) {
             if (this._webGLVersion === 1) {
+                if (format) {
+                    switch (format) {
+                        case Engine.TEXTUREFORMAT_LUMINANCE:
+                            return this._gl.LUMINANCE;
+                    }
+                }
                 return this._gl.RGBA;
             }
             if (type === Engine.TEXTURETYPE_FLOAT) {
@@ -15144,6 +15152,12 @@ var BABYLON;
             else if (type === Engine.TEXTURETYPE_HALF_FLOAT) {
                 return this._gl.RGBA16F;
             }
+            if (format) {
+                switch (format) {
+                    case Engine.TEXTUREFORMAT_LUMINANCE:
+                        return this._gl.LUMINANCE;
+                }
+            }
             return this._gl.RGBA;
         };
         ;
@@ -24096,6 +24110,12 @@ var BABYLON;
          * Use this function to stop evaluating active meshes. The current list will be keep alive between frames
          */
         Scene.prototype.freezeActiveMeshes = function () {
+            if (!this.activeCamera) {
+                return this;
+            }
+            if (!this._frustumPlanes) {
+                this.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix());
+            }
             this._evaluateActiveMeshes();
             this._activeMeshesFrozen = true;
             return this;

File diff suppressed because it is too large
+ 54 - 34
dist/preview release/customConfigurations/minimalGLTFViewer/es6.js


File diff suppressed because it is too large
+ 59 - 38
dist/preview release/es6.js


+ 2 - 31
dist/preview release/typedocValidationBaseline.json

@@ -1,7 +1,7 @@
 {
-  "errors": 7189,
+  "errors": 7184,
   "babylon.typedoc.json": {
-    "errors": 7189,
+    "errors": 7184,
     "AnimationKeyInterpolation": {
       "Enumeration": {
         "Comments": {
@@ -25327,35 +25327,6 @@
         }
       }
     },
-    "RenderTargetCreationOptions": {
-      "Property": {
-        "generateDepthBuffer": {
-          "Comments": {
-            "MissingText": true
-          }
-        },
-        "generateMipMaps": {
-          "Comments": {
-            "MissingText": true
-          }
-        },
-        "generateStencilBuffer": {
-          "Comments": {
-            "MissingText": true
-          }
-        },
-        "samplingMode": {
-          "Comments": {
-            "MissingText": true
-          }
-        },
-        "type": {
-          "Comments": {
-            "MissingText": true
-          }
-        }
-      }
-    },
     "RenderTargetTexture": {
       "Class": {
         "Comments": {

+ 2 - 10
dist/preview release/viewer/babylon.viewer.d.ts

@@ -62,7 +62,6 @@ declare module BabylonViewer {
         onAllLoaded: BABYLON.Observable<TemplateManager>;
         onEventTriggered: BABYLON.Observable<EventCallback>;
         eventManager: EventManager;
-        constructor(containerElement: HTMLElement);
         initTemplate(templates: {
             [key: string]: ITemplateConfiguration;
         }): void;
@@ -81,7 +80,6 @@ declare module BabylonViewer {
         isShown: boolean;
         parent: HTMLElement;
         initPromise: Promise<Template>;
-        constructor(name: string, _configuration: ITemplateConfiguration);
         readonly configuration: ITemplateConfiguration;
         getChildElements(): Array<string>;
         appendTo(parent: HTMLElement): void;
@@ -93,7 +91,6 @@ declare module BabylonViewer {
     interface ViewerManager {
         onViewerAdded: (viewer: AbstractViewer) => void;
         onViewerAddedObservable: BABYLON.Observable<AbstractViewer>;
-        constructor();
         addViewer(viewer: AbstractViewer): void;
         getViewerById(id: string): AbstractViewer;
         getViewerByHTMLElement(element: HTMLElement): AbstractViewer | undefined;
@@ -110,7 +107,6 @@ declare module BabylonViewer {
     export function InitTags(selector?: string): void;
 
     interface EventManager {
-        constructor(templateManager: TemplateManager);
         registerCallback(templateName: string, callback: (eventData: EventCallback) => void, eventType?: string, selector?: string): void;
         unregisterCallback(templateName: string, callback?: (eventData: EventCallback) => void, eventType?: string, selector?: string): void;
     }
@@ -124,14 +120,12 @@ declare module BabylonViewer {
     }
     interface MapperManager {
         DefaultMapper: string;
-        constructor();
         getMapper(type: string): IMapper;
         registerMapper(type: string, mapper: IMapper): void;
     }
     export let mapperManager: MapperManager;
 
     interface ConfigurationLoader {
-        constructor();
         loadConfiguration(initConfig?: ViewerConfiguration): Promise<ViewerConfiguration>;
         getConfigurationType(type: string): void;
     }
@@ -416,7 +410,7 @@ declare module BabylonViewer {
         STOPPED = 3,
         ENDED = 4,
     }
-    interface IModelAnimation extends BABYLON.IDisposable {
+    export interface IModelAnimation extends BABYLON.IDisposable {
         readonly state: AnimationState;
         readonly name: string;
         readonly frames: number;
@@ -432,7 +426,7 @@ declare module BabylonViewer {
         goToFrame(frameNumber: number): any;
     }
 
-    class ViewerModel implements BABYLON.IDisposable {
+    export interface ViewerModel extends BABYLON.IDisposable {
         loader: BABYLON.ISceneLoaderPlugin | BABYLON.ISceneLoaderPluginAsync;
         meshes: Array<BABYLON.AbstractMesh>;
         particleSystems: Array<BABYLON.ParticleSystem>;
@@ -444,10 +438,8 @@ declare module BabylonViewer {
             message: string;
             exception: any;
         }>;
-        constructor(_modelConfiguration: IModelConfiguration, _scene: BABYLON.Scene, disableAutoLoad?: boolean);
         load(): void;
         getAnimationNames(): string[];
-        protected _getAnimationByName(name: string): BABYLON.Nullable<IModelAnimation>;
         playAnimation(name: string): IModelAnimation;
         dispose(): void;
     }

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


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


+ 44 - 35
materialsLibrary/src/custom/babylon.customMaterial.ts

@@ -1,18 +1,13 @@
 /// <reference path="../../../dist/preview release/babylon.d.ts"/>
 
 module BABYLON {
-
-    // old version of standard material updated every 3 months
     
-
     export class CustomShaderStructure {
 
         public FragmentStore: string;
         public VertexStore: string;
 
-        constructor() {
-
-        }
+        constructor() { }
     }
 
     export class ShaderSpecialParts {
@@ -41,7 +36,6 @@ module BABYLON {
         // normalUpdated
         public Vertex_Before_NormalUpdated: string;
     }
- 
 
     export class CustomMaterial extends StandardMaterial {
         public static ShaderIndexer = 1;
@@ -59,38 +53,53 @@ module BABYLON {
         public AttachAfterBind(mesh: Mesh, effect: Effect) {
             for (var el in this._newUniformInstances) {
                 var ea = el.toString().split('-');
-                if (ea[0] == 'vec2') effect.setVector2(ea[1], this._newUniformInstances[el]);
-                else if (ea[0] == 'vec3') effect.setVector3(ea[1], this._newUniformInstances[el]);
-                else if (ea[0] == 'vec4') effect.setVector4(ea[1], this._newUniformInstances[el]);
-                else if (ea[0] == 'mat4') effect.setMatrix(ea[1], this._newUniformInstances[el]);
-                else if (ea[0] == 'float') effect.setFloat(ea[1], this._newUniformInstances[el]);
+                if (ea[0] == 'vec2') {
+                    effect.setVector2(ea[1], this._newUniformInstances[el]);
+                }
+                else if (ea[0] == 'vec3') {
+                    effect.setVector3(ea[1], this._newUniformInstances[el]);
+                }
+                else if (ea[0] == 'vec4') {
+                    effect.setVector4(ea[1], this._newUniformInstances[el]);
+                }
+                else if (ea[0] == 'mat4') {
+                    effect.setMatrix(ea[1], this._newUniformInstances[el]);
+                }
+                else if (ea[0] == 'float') {
+                    effect.setFloat(ea[1], this._newUniformInstances[el]);
+                }
             }
-
             for (var el in this._newSamplerInstances) {
                 var ea = el.toString().split('-');
-                if (ea[0] == 'sampler2D' && this._newSamplerInstances[el].isReady && this._newSamplerInstances[el].isReady())
+                if (ea[0] == 'sampler2D' && this._newSamplerInstances[el].isReady && this._newSamplerInstances[el].isReady()) {
                     effect.setTexture(ea[1], this._newSamplerInstances[el]);
+                }
             }
         }
 
         public ReviewUniform(name: string, arr: string[]): string[] {
             if (name == "uniform") {
-                for (var ind in this._newUniforms)
-                    if (this._customUniform[ind].indexOf('sampler') == -1)
+                for (var ind in this._newUniforms) {
+                    if (this._customUniform[ind].indexOf('sampler') == -1) {
                         arr.push(this._newUniforms[ind]);
+                    }
+                }
             }
-
             if (name == "sampler") {
-                for (var ind in this._newUniforms)
-                    if (this._customUniform[ind].indexOf('sampler') != -1)
+                for (var ind in this._newUniforms) {
+                    if (this._customUniform[ind].indexOf('sampler') != -1) {
                         arr.push(this._newUniforms[ind]);
+                    }
+                }
             }
-
             return arr;
         }
+        
         public Builder(shaderName: string, uniforms: string[], uniformBuffers: string[], samplers: string[], defines: StandardMaterialDefines): string {
 
-            if (this._isCreatedShader) return this._createdShaderName;
+            if (this._isCreatedShader) {
+                return this._createdShaderName;
+            }
             this._isCreatedShader = false;
 
             CustomMaterial.ShaderIndexer++;
@@ -99,14 +108,14 @@ module BABYLON {
             this.ReviewUniform("uniform", uniforms);
             this.ReviewUniform("sampler", samplers);
 
-
             var fn_afterBind = this._afterBind.bind(this);
             this._afterBind = (m, e) => {
                 if (!e) {
                     return;
                 }
                 this.AttachAfterBind(m, e);
-                try { fn_afterBind(m, e); } catch (e) { };
+                try { fn_afterBind(m, e); }
+                catch (e) { }
             };
 
             BABYLON.Effect.ShadersStore[name + "VertexShader"] = this.VertexShader
@@ -132,14 +141,9 @@ module BABYLON {
 
             this._isCreatedShader = true;
             this._createdShaderName = name;
-
             
             return name;
-        }
-
-
-
-        
+        }        
 
         constructor(name: string, scene: Scene) {
             super(name, scene);
@@ -147,10 +151,9 @@ module BABYLON {
             this.customShaderNameResolve = this.Builder;
 
             this.FragmentShader = BABYLON.Effect.ShadersStore["defaultPixelShader"];
-            this.VertexShader = BABYLON.Effect.ShadersStore["defaultVertexShader"];
-
-             
+            this.VertexShader = BABYLON.Effect.ShadersStore["defaultVertexShader"];             
         }
+        
         public AddUniform(name: string, kind: string, param: any): CustomMaterial {
             if (!this._customUniform) {
                 this._customUniform = new Array();
@@ -166,12 +169,12 @@ module BABYLON {
                     (<any>this._newUniformInstances)[kind + "-" + name] = param;
                 }
             }
-
             this._customUniform.push("uniform " + kind + " " + name + ";");
             this._newUniforms.push(name);
 
             return this;
         }
+        
         public Fragment_Begin(shaderPart: string): CustomMaterial {
             this.CustomParts.Fragment_Begin = shaderPart;
             return this;
@@ -186,30 +189,37 @@ module BABYLON {
             this.CustomParts.Fragment_MainBegin = shaderPart;
             return this;
         }
+        
         public Fragment_Custom_Diffuse(shaderPart: string): CustomMaterial {
             this.CustomParts.Fragment_Custom_Diffuse = shaderPart.replace("result", "diffuseColor");
             return this;
         }
+        
         public Fragment_Custom_Alpha(shaderPart: string): CustomMaterial {
             this.CustomParts.Fragment_Custom_Alpha = shaderPart.replace("result", "alpha");
             return this;
         }
+        
         public Fragment_Before_FragColor(shaderPart: string): CustomMaterial {
             this.CustomParts.Fragment_Before_FragColor = shaderPart.replace("result", "color");
             return this;
         }
+        
         public Vertex_Begin(shaderPart: string): CustomMaterial {
             this.CustomParts.Vertex_Begin = shaderPart;
             return this;
         }
+        
         public Vertex_Definitions(shaderPart: string): CustomMaterial {
             this.CustomParts.Vertex_Definitions = shaderPart;
             return this;
         }
+        
         public Vertex_MainBegin(shaderPart: string): CustomMaterial {
             this.CustomParts.Vertex_MainBegin = shaderPart;
             return this;
         }
+        
         public Vertex_Before_PositionUpdated(shaderPart: string): CustomMaterial {
             this.CustomParts.Vertex_Before_PositionUpdated = shaderPart.replace("result", "positionUpdated");
             return this;
@@ -218,8 +228,7 @@ module BABYLON {
         public Vertex_Before_NormalUpdated(shaderPart: string): CustomMaterial {
             this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace("result", "normalUpdated");
             return this;
-        }
-            
+        }            
     }
 }
 

+ 94 - 55
serializers/src/glTF/2.0/babylon.glTFMaterial.ts

@@ -594,8 +594,8 @@ module BABYLON.GLTF2 {
                 for (let w = 0; w < width; ++w) {
                     const offset = (width * h + w) * strideSize;
 
-                    const diffuseColor = Color3.FromInts(diffuseBuffer[offset], diffuseBuffer[offset + 1], diffuseBuffer[offset + 2]).multiply(factors.diffuseColor);
-                    const specularColor = Color3.FromInts(specularGlossinessBuffer[offset], specularGlossinessBuffer[offset + 1], specularGlossinessBuffer[offset + 2]).multiply(factors.specularColor);
+                    const diffuseColor = Color3.FromInts(diffuseBuffer[offset], diffuseBuffer[offset + 1], diffuseBuffer[offset + 2]).toLinearSpace().multiply(factors.diffuseColor);
+                    const specularColor = Color3.FromInts(specularGlossinessBuffer[offset], specularGlossinessBuffer[offset + 1], specularGlossinessBuffer[offset + 2]).toLinearSpace().multiply(factors.specularColor);
                     const glossiness = (specularGlossinessBuffer[offset + 3] / 255) * factors.glossiness;
 
                     const specularGlossiness: _IPBRSpecularGlossiness = {
@@ -616,7 +616,7 @@ module BABYLON.GLTF2 {
                     baseColorBuffer[offset + 2] = metallicRoughness.baseColor.b * 255;
                     baseColorBuffer[offset + 3] = resizedTextures.texture1.hasAlpha ? diffuseBuffer[offset + 3] : 255;
 
-                    metallicRoughnessBuffer[offset] = 255;
+                    metallicRoughnessBuffer[offset] = 0;
                     metallicRoughnessBuffer[offset + 1] = metallicRoughness.roughness * 255;
                     metallicRoughnessBuffer[offset + 2] = metallicRoughness.metallic * 255;
                     metallicRoughnessBuffer[offset + 3] = 255;
@@ -641,16 +641,20 @@ module BABYLON.GLTF2 {
                     baseColorBuffer[destinationOffset + 1] /= metallicRoughnessFactors.baseColor.g > this._epsilon ? metallicRoughnessFactors.baseColor.g : 1;
                     baseColorBuffer[destinationOffset + 2] /= metallicRoughnessFactors.baseColor.b > this._epsilon ? metallicRoughnessFactors.baseColor.b : 1;
 
-                    const baseColorPixel = new Color3(baseColorBuffer[destinationOffset], baseColorBuffer[destinationOffset + 1], baseColorBuffer[destinationOffset + 2]);
+                    const linearBaseColorPixel = Color3.FromInts(baseColorBuffer[destinationOffset], baseColorBuffer[destinationOffset + 1], baseColorBuffer[destinationOffset + 2]);
+                    const sRGBBaseColorPixel = linearBaseColorPixel.toGammaSpace();
+                    baseColorBuffer[destinationOffset] = sRGBBaseColorPixel.r * 255;
+                    baseColorBuffer[destinationOffset + 1] = sRGBBaseColorPixel.g * 255;
+                    baseColorBuffer[destinationOffset + 2] = sRGBBaseColorPixel.b * 255;
 
-                    if (!this.FuzzyEquals(baseColorPixel, Color3.White(), this._epsilon)) {
+                    if (!this.FuzzyEquals(sRGBBaseColorPixel, Color3.White(), this._epsilon)) {
                         writeOutBaseColorTexture = true;
                     }
 
                     metallicRoughnessBuffer[destinationOffset + 1] /= metallicRoughnessFactors.roughness > this._epsilon ? metallicRoughnessFactors.roughness : 1;
                     metallicRoughnessBuffer[destinationOffset + 2] /= metallicRoughnessFactors.metallic > this._epsilon ? metallicRoughnessFactors.metallic : 1;
 
-                    const metallicRoughnessPixel = new Color3(metallicRoughnessBuffer[destinationOffset], metallicRoughnessBuffer[destinationOffset + 1], metallicRoughnessBuffer[destinationOffset + 2]);
+                    const metallicRoughnessPixel = Color3.FromInts(255, metallicRoughnessBuffer[destinationOffset + 1], metallicRoughnessBuffer[destinationOffset + 2]);
 
                     if (!this.FuzzyEquals(metallicRoughnessPixel, Color3.White(), this._epsilon)) {
                         writeOutMetallicRoughnessTexture = true;
@@ -719,6 +723,86 @@ module BABYLON.GLTF2 {
         }
 
         /**
+         * Convert a PBRMaterial (Metallic/Roughness) to Metallic Roughness factors.
+         * @param babylonPBRMaterial - BJS PBR Metallic Roughness Material.
+         * @param mimeType - mime type to use for the textures.
+         * @param images - array of glTF image interfaces.
+         * @param textures - array of glTF texture interfaces.
+         * @param glTFPbrMetallicRoughness - glTF PBR Metallic Roughness interface.
+         * @param imageData - map of image file name to data.
+         * @param hasTextureCoords - specifies if texture coordinates are present on the submesh to determine if textures should be applied.
+         * @returns - glTF PBR Metallic Roughness factors.
+         */
+        private static _ConvertMetalRoughFactorsToMetallicRoughness(babylonPBRMaterial: PBRMaterial, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], glTFPbrMetallicRoughness: IMaterialPbrMetallicRoughness, imageData: { [fileName: string]: { data: Uint8Array, mimeType: ImageMimeType } }, hasTextureCoords: boolean): _IPBRMetallicRoughness {
+            const metallicRoughness = {
+                baseColor: babylonPBRMaterial.albedoColor,
+                metallic: babylonPBRMaterial.metallic,
+                roughness: babylonPBRMaterial.roughness
+            };
+
+            if (hasTextureCoords) {
+                if (babylonPBRMaterial.albedoTexture) {
+                    const glTFTexture = _GLTFMaterial._ExportTexture(babylonPBRMaterial.albedoTexture, mimeType, images, textures, imageData);
+                    if (glTFTexture) {
+                        glTFPbrMetallicRoughness.baseColorTexture = glTFTexture;
+                    }
+                }
+                if (babylonPBRMaterial.metallicTexture) {
+                    const glTFTexture = _GLTFMaterial._ExportTexture(babylonPBRMaterial.metallicTexture, mimeType, images, textures, imageData);
+                    if (glTFTexture != null) {
+                        glTFPbrMetallicRoughness.metallicRoughnessTexture = glTFTexture;
+                    }
+                }
+            }
+            return metallicRoughness;
+        }
+
+        /**
+         * Convert a PBRMaterial (Specular/Glossiness) to Metallic Roughness factors.
+         * @param babylonPBRMaterial - BJS PBR Metallic Roughness Material.
+         * @param mimeType - mime type to use for the textures.
+         * @param images - array of glTF image interfaces.
+         * @param textures - array of glTF texture interfaces.
+         * @param glTFPbrMetallicRoughness - glTF PBR Metallic Roughness interface.
+         * @param imageData - map of image file name to data.
+         * @param hasTextureCoords - specifies if texture coordinates are present on the submesh to determine if textures should be applied.
+         * @returns - glTF PBR Metallic Roughness factors.
+         */
+        private static _ConvertSpecGlossFactorsToMetallicRoughness(babylonPBRMaterial: PBRMaterial, mimeType: ImageMimeType, images: IImage[], textures: ITexture[], glTFPbrMetallicRoughness: IMaterialPbrMetallicRoughness, imageData: { [fileName: string]: { data: Uint8Array, mimeType: ImageMimeType } }, hasTextureCoords: boolean): _IPBRMetallicRoughness {
+            const specGloss: _IPBRSpecularGlossiness = {
+                diffuseColor: babylonPBRMaterial.albedoColor || Color3.White(),
+                specularColor: babylonPBRMaterial.reflectivityColor || Color3.White(),
+                glossiness: babylonPBRMaterial.microSurface || 1,
+            };
+            if (babylonPBRMaterial.reflectivityTexture && !babylonPBRMaterial.useMicroSurfaceFromReflectivityMapAlpha) {
+                throw new Error("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture currently not supported");
+            }
+
+            let metallicRoughnessFactors = this._ConvertSpecularGlossinessTexturesToMetallicRoughness(babylonPBRMaterial.albedoTexture, babylonPBRMaterial.reflectivityTexture, specGloss, mimeType);
+
+            if (!metallicRoughnessFactors) {
+                metallicRoughnessFactors = this._ConvertSpecularGlossinessToMetallicRoughness(specGloss);
+            }
+            else {
+                if (hasTextureCoords) {
+                    if (metallicRoughnessFactors.baseColorTextureBase64) {
+                        const glTFBaseColorTexture = _GLTFMaterial._GetTextureInfoFromBase64(metallicRoughnessFactors.baseColorTextureBase64, "bjsBaseColorTexture_" + (textures.length) + ".png", mimeType, images, textures, imageData);
+                        if (glTFBaseColorTexture != null) {
+                            glTFPbrMetallicRoughness.baseColorTexture = glTFBaseColorTexture;
+                        }
+                    }
+                    if (metallicRoughnessFactors.metallicRoughnessTextureBase64) {
+                        const glTFMRColorTexture = _GLTFMaterial._GetTextureInfoFromBase64(metallicRoughnessFactors.metallicRoughnessTextureBase64, "bjsMetallicRoughnessTexture_" + (textures.length) + ".png", mimeType, images, textures, imageData);
+                        if (glTFMRColorTexture != null) {
+                            glTFPbrMetallicRoughness.metallicRoughnessTexture = glTFMRColorTexture;
+                        }
+                    }
+                }
+            }
+            return metallicRoughnessFactors
+        }
+
+        /**
          * Converts a Babylon PBR Metallic Roughness Material to a glTF Material.
          * @param babylonPBRMaterial - BJS PBR Metallic Roughness Material.
          * @param mimeType - mime type to use for the textures.
@@ -736,44 +820,11 @@ module BABYLON.GLTF2 {
             };
             const useMetallicRoughness = babylonPBRMaterial.isMetallicWorkflow();
 
-            if (!useMetallicRoughness) {
-                const specGloss: _IPBRSpecularGlossiness = {
-                    diffuseColor: babylonPBRMaterial.albedoColor || Color3.White(),
-                    specularColor: babylonPBRMaterial.reflectivityColor || Color3.White(),
-                    glossiness: babylonPBRMaterial.microSurface || 1,
-                };
-                if (babylonPBRMaterial.reflectivityTexture && !babylonPBRMaterial.useMicroSurfaceFromReflectivityMapAlpha) {
-                    throw new Error("_ConvertPBRMaterial: Glossiness values not included in the reflectivity texture currently not supported");
-                }
-
-                metallicRoughness = this._ConvertSpecularGlossinessTexturesToMetallicRoughness(babylonPBRMaterial.albedoTexture, babylonPBRMaterial.reflectivityTexture, specGloss, mimeType);
-
-                if (!metallicRoughness) {
-                    metallicRoughness = this._ConvertSpecularGlossinessToMetallicRoughness(specGloss);
-                }
-                else {
-                    if (hasTextureCoords) {
-                        if (metallicRoughness.baseColorTextureBase64) {
-                            const glTFBaseColorTexture = _GLTFMaterial._GetTextureInfoFromBase64(metallicRoughness.baseColorTextureBase64, "bjsBaseColorTexture_" + (textures.length) + ".png", mimeType, images, textures, imageData);
-                            if (glTFBaseColorTexture != null) {
-                                glTFPbrMetallicRoughness.baseColorTexture = glTFBaseColorTexture;
-                            }
-                        }
-                        if (metallicRoughness.metallicRoughnessTextureBase64) {
-                            const glTFMRColorTexture = _GLTFMaterial._GetTextureInfoFromBase64(metallicRoughness.metallicRoughnessTextureBase64, "bjsMetallicRoughnessTexture_" + (textures.length) + ".png", mimeType, images, textures, imageData);
-                            if (glTFMRColorTexture != null) {
-                                glTFPbrMetallicRoughness.metallicRoughnessTexture = glTFMRColorTexture;
-                            }
-                        }
-                    }
-                }
+            if (useMetallicRoughness) {
+                metallicRoughness = this._ConvertMetalRoughFactorsToMetallicRoughness(babylonPBRMaterial, mimeType, images, textures, glTFPbrMetallicRoughness, imageData, hasTextureCoords);
             }
             else {
-                metallicRoughness = {
-                    baseColor: babylonPBRMaterial.albedoColor,
-                    metallic: babylonPBRMaterial.metallic,
-                    roughness: babylonPBRMaterial.roughness
-                };
+                metallicRoughness = this._ConvertSpecGlossFactorsToMetallicRoughness(babylonPBRMaterial, mimeType, images, textures, glTFPbrMetallicRoughness, imageData, hasTextureCoords);
             }
 
             if (!(this.FuzzyEquals(metallicRoughness.baseColor, Color3.White(), this._epsilon) && babylonPBRMaterial.alpha >= this._epsilon)) {
@@ -799,12 +850,6 @@ module BABYLON.GLTF2 {
                 glTFMaterial.doubleSided = true;
             }
             if (hasTextureCoords) {
-                if (useMetallicRoughness && babylonPBRMaterial.albedoTexture) {
-                    const glTFTexture = _GLTFMaterial._ExportTexture(babylonPBRMaterial.albedoTexture, mimeType, images, textures, imageData);
-                    if (glTFTexture) {
-                        glTFPbrMetallicRoughness.baseColorTexture = glTFTexture;
-                    }
-                }
                 if (babylonPBRMaterial.bumpTexture) {
                     const glTFTexture = _GLTFMaterial._ExportTexture(babylonPBRMaterial.bumpTexture, mimeType, images, textures, imageData);
                     if (glTFTexture) {
@@ -830,13 +875,7 @@ module BABYLON.GLTF2 {
                     if (glTFTexture != null) {
                         glTFMaterial.emissiveTexture = glTFTexture;
                     }
-                }
-                if (babylonPBRMaterial.metallicTexture) {
-                    const glTFTexture = _GLTFMaterial._ExportTexture(babylonPBRMaterial.metallicTexture, mimeType, images, textures, imageData);
-                    if (glTFTexture != null) {
-                        glTFPbrMetallicRoughness.metallicRoughnessTexture = glTFTexture;
-                    }
-                }
+                }       
             }
             if (!this.FuzzyEquals(babylonPBRMaterial.emissiveColor, Color3.Black(), this._epsilon)) {
                 glTFMaterial.emissiveFactor = babylonPBRMaterial.emissiveColor.asArray();

+ 58 - 34
src/Engine/babylon.engine.ts

@@ -209,11 +209,20 @@
      * Define options used to create a render target texture
      */
     export class RenderTargetCreationOptions {
+        /**
+         * Specifies is mipmaps must be generated
+         */
         generateMipMaps?: boolean;
+        /** Specifies whether or not a depth should be allocated in the texture (true by default) */
         generateDepthBuffer?: boolean;
+        /** Specifies whether or not a stencil should be allocated in the texture (false by default)*/
         generateStencilBuffer?: boolean;
+        /** Defines texture type (int by default) */
         type?: number;
+        /** Defines sampling mode (trilinear by default) */
         samplingMode?: number;
+        /** Defines format (RGBA by default) */
+        format?: number;
     }
 
     /**
@@ -957,7 +966,7 @@
                         }
                     }
                 }
-
+                
                 // GL
                 if (!options.disableWebGL2Support) {
                     try {
@@ -3435,37 +3444,6 @@
             });
         }
 
-        private _getInternalFormat(format: number): number {
-            var internalFormat = this._gl.RGBA;
-            switch (format) {
-                case Engine.TEXTUREFORMAT_ALPHA:
-                    internalFormat = this._gl.ALPHA;
-                    break;
-                case Engine.TEXTUREFORMAT_LUMINANCE:
-                    internalFormat = this._gl.LUMINANCE;
-                    break;
-                case Engine.TEXTUREFORMAT_LUMINANCE_ALPHA:
-                    internalFormat = this._gl.LUMINANCE_ALPHA;
-                    break;
-                case Engine.TEXTUREFORMAT_RGB:
-                case Engine.TEXTUREFORMAT_RGB32F:
-                    internalFormat = this._gl.RGB;
-                    break;
-                case Engine.TEXTUREFORMAT_RGBA:
-                case Engine.TEXTUREFORMAT_RGBA32F:
-                    internalFormat = this._gl.RGBA;
-                    break;
-                case Engine.TEXTUREFORMAT_R32F:
-                    internalFormat = this._gl.RED;
-                    break;       
-                case Engine.TEXTUREFORMAT_RG32F:
-                    internalFormat = this._gl.RG;
-                    break;                                    
-            }
-
-            return internalFormat;
-        }
-
         public updateRawTexture(texture: Nullable<InternalTexture>, data: Nullable<ArrayBufferView>, format: number, invertY: boolean, compression: Nullable<string> = null, type = Engine.TEXTURETYPE_UNSIGNED_INT): void {
             if (!texture) {
                 return;
@@ -3902,12 +3880,14 @@
                 fullOptions.generateStencilBuffer = fullOptions.generateDepthBuffer && options.generateStencilBuffer;
                 fullOptions.type = options.type === undefined ? Engine.TEXTURETYPE_UNSIGNED_INT : options.type;
                 fullOptions.samplingMode = options.samplingMode === undefined ? Texture.TRILINEAR_SAMPLINGMODE : options.samplingMode;
+                fullOptions.format = options.format === undefined ? Engine.TEXTUREFORMAT_RGBA : options.format;
             } else {
                 fullOptions.generateMipMaps = <boolean>options;
                 fullOptions.generateDepthBuffer = true;
                 fullOptions.generateStencilBuffer = false;
                 fullOptions.type = Engine.TEXTURETYPE_UNSIGNED_INT;
                 fullOptions.samplingMode = Texture.TRILINEAR_SAMPLINGMODE;
+                fullOptions.format = Engine.TEXTUREFORMAT_RGBA;
             }
 
             if (fullOptions.type === Engine.TEXTURETYPE_FLOAT && !this._caps.textureFloatLinearFiltering) {
@@ -3938,7 +3918,7 @@
             gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
             gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
 
-            gl.texImage2D(gl.TEXTURE_2D, 0, this._getRGBABufferInternalSizedFormat(fullOptions.type), width, height, 0, gl.RGBA, this._getWebGLTextureType(fullOptions.type), null);
+            gl.texImage2D(gl.TEXTURE_2D, 0, this._getRGBABufferInternalSizedFormat(fullOptions.type, fullOptions.format), width, height, 0, this._getInternalFormat(fullOptions.format), this._getWebGLTextureType(fullOptions.type), null);
 
             // Create the framebuffer
             var framebuffer = gl.createFramebuffer();
@@ -4321,6 +4301,7 @@
               generateStencilBuffer: false,
               type: Engine.TEXTURETYPE_UNSIGNED_INT,
               samplingMode: Texture.TRILINEAR_SAMPLINGMODE,
+              format: Engine.TEXTUREFORMAT_RGBA,
               ...options
             };
             fullOptions.generateStencilBuffer = fullOptions.generateDepthBuffer && fullOptions.generateStencilBuffer;
@@ -4351,7 +4332,7 @@
             gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
 
             for (var face = 0; face < 6; face++) {
-                gl.texImage2D((gl.TEXTURE_CUBE_MAP_POSITIVE_X + face), 0, this._getRGBABufferInternalSizedFormat(fullOptions.type), size, size, 0, gl.RGBA, this._getWebGLTextureType(fullOptions.type), null);
+                gl.texImage2D((gl.TEXTURE_CUBE_MAP_POSITIVE_X + face), 0, this._getRGBABufferInternalSizedFormat(fullOptions.type, fullOptions.format), size, size, 0, this._getInternalFormat(fullOptions.format), this._getWebGLTextureType(fullOptions.type), null);
             }
 
             // Create the framebuffer
@@ -5895,9 +5876,46 @@
             return this._gl.UNSIGNED_BYTE;
         };
 
+        private _getInternalFormat(format: number): number {
+            var internalFormat = this._gl.RGBA;
+            switch (format) {
+                case Engine.TEXTUREFORMAT_ALPHA:
+                    internalFormat = this._gl.ALPHA;
+                    break;
+                case Engine.TEXTUREFORMAT_LUMINANCE:
+                    internalFormat = this._gl.LUMINANCE;
+                    break;
+                case Engine.TEXTUREFORMAT_LUMINANCE_ALPHA:
+                    internalFormat = this._gl.LUMINANCE_ALPHA;
+                    break;
+                case Engine.TEXTUREFORMAT_RGB:
+                case Engine.TEXTUREFORMAT_RGB32F:
+                    internalFormat = this._gl.RGB;
+                    break;
+                case Engine.TEXTUREFORMAT_RGBA:
+                case Engine.TEXTUREFORMAT_RGBA32F:
+                    internalFormat = this._gl.RGBA;
+                    break;
+                case Engine.TEXTUREFORMAT_R32F:
+                    internalFormat = this._gl.RED;
+                    break;       
+                case Engine.TEXTUREFORMAT_RG32F:
+                    internalFormat = this._gl.RG;
+                    break;                                    
+            }
+
+            return internalFormat;
+        }        
+
         /** @ignore */
         public _getRGBABufferInternalSizedFormat(type: number, format?: number): number {
             if (this._webGLVersion === 1) {
+                if (format) {
+                    switch(format) {
+                        case Engine.TEXTUREFORMAT_LUMINANCE:
+                            return this._gl.LUMINANCE;
+                    }                    
+                }
                 return this._gl.RGBA;
             }
 
@@ -5918,6 +5936,12 @@
                 return this._gl.RGBA16F;
             }
 
+            if (format) {
+                switch(format) {
+                    case Engine.TEXTUREFORMAT_LUMINANCE:
+                        return this._gl.LUMINANCE;
+                }                    
+            }
             return this._gl.RGBA;
         };
 

+ 5 - 4
src/Particles/babylon.gpuParticleSystem.ts

@@ -496,12 +496,13 @@
          * Animates the particle system for the current frame by emitting new particles and or animating the living ones.
          */
         public animate(): void {           
-            if (!this._stopped) {
-                this._timeDelta = this.updateSpeed * this._scene.getAnimationRatio();   
-                this._actualFrame += this._timeDelta;
+            this._timeDelta = this.updateSpeed * this._scene.getAnimationRatio();   
+            this._actualFrame += this._timeDelta;
 
-                if (this.targetStopDuration && this._actualFrame >= this.targetStopDuration)
+            if (!this._stopped) {
+                if (this.targetStopDuration && this._actualFrame >= this.targetStopDuration) {
                     this.stop();
+                }
             }             
         }        
 

+ 1 - 1
src/Shaders/gpuUpdateParticles.vertex.fx

@@ -74,7 +74,7 @@ void main() {
       outLife = life;
       outSeed = seed;
       outColor = vec4(0.,0.,0.,0.);
-      outSize = size;
+      outSize = 0.;
       outDirection = direction;
       return;
     }

+ 8 - 0
src/babylon.scene.ts

@@ -3237,6 +3237,14 @@
          * Use this function to stop evaluating active meshes. The current list will be keep alive between frames
          */
         public freezeActiveMeshes(): Scene {
+            if (!this.activeCamera) {
+                return this;
+            }
+            
+            if (!this._frustumPlanes) {
+                this.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix());
+            }
+
             this._evaluateActiveMeshes();
             this._activeMeshesFrozen = true;
             return this;

BIN
tests/validation/ReferenceImages/SpaceDeK.png


+ 1 - 0
tests/validation/config.json

@@ -386,6 +386,7 @@
     },
     {
       "title": "Instances",
+      "renderCount": 2,
       "scriptToRun": "/Demos/Instances/instances.js",
       "functionToCall": "CreateInstancesTestScene",
       "referenceImage": "instances.png",