David Catuhe 9 lat temu
rodzic
commit
ae97c95db6

Plik diff jest za duży
+ 26 - 26
dist/preview release/babylon.core.js


Plik diff jest za duży
+ 1422 - 1399
dist/preview release/babylon.d.ts


Plik diff jest za duży
+ 39 - 39
dist/preview release/babylon.js


Plik diff jest za duży
+ 107 - 22
dist/preview release/babylon.max.js


Plik diff jest za duży
+ 29 - 29
dist/preview release/babylon.noworker.js


+ 2 - 0
src/Debug/babylon.debugLayer.js

@@ -252,6 +252,7 @@ var BABYLON;
             BABYLON.StandardMaterial.ReflectionTextureEnabled = true;
             BABYLON.StandardMaterial.LightmapTextureEnabled = true;
             BABYLON.StandardMaterial.RefractionTextureEnabled = true;
+            BABYLON.StandardMaterial.ColorGradingTextureEnabled = true;
             this._scene.shadowsEnabled = true;
             this._scene.particlesEnabled = true;
             this._scene.postProcessesEnabled = true;
@@ -541,6 +542,7 @@ var BABYLON;
                 this._generateCheckBox(this._optionsSubsetDiv, "Opacity", BABYLON.StandardMaterial.OpacityTextureEnabled, function (element) { BABYLON.StandardMaterial.OpacityTextureEnabled = element.checked; });
                 this._generateCheckBox(this._optionsSubsetDiv, "Reflection", BABYLON.StandardMaterial.ReflectionTextureEnabled, function (element) { BABYLON.StandardMaterial.ReflectionTextureEnabled = element.checked; });
                 this._generateCheckBox(this._optionsSubsetDiv, "Refraction", BABYLON.StandardMaterial.RefractionTextureEnabled, function (element) { BABYLON.StandardMaterial.RefractionTextureEnabled = element.checked; });
+                this._generateCheckBox(this._optionsSubsetDiv, "ColorGrading", BABYLON.StandardMaterial.ColorGradingTextureEnabled, function (element) { BABYLON.StandardMaterial.ColorGradingTextureEnabled = element.checked; });
                 this._generateCheckBox(this._optionsSubsetDiv, "Lightmap", BABYLON.StandardMaterial.LightmapTextureEnabled, function (element) { BABYLON.StandardMaterial.LightmapTextureEnabled = element.checked; });
                 this._generateCheckBox(this._optionsSubsetDiv, "Fresnel", BABYLON.StandardMaterial.FresnelEnabled, function (element) { BABYLON.StandardMaterial.FresnelEnabled = element.checked; });
                 this._optionsSubsetDiv.appendChild(document.createElement("br"));

+ 29 - 0
src/Materials/Textures/babylon.colorGradingTexture.js

@@ -145,6 +145,35 @@ var BABYLON;
             }
         };
         /**
+        * Binds the color grading to the shader.
+        * @param colorGrading The texture to bind
+        * @param effect The effect to bind to
+        */
+        ColorGradingTexture.Bind = function (colorGrading, effect) {
+            effect.setTexture("cameraColorGrading2DSampler", colorGrading);
+            var x = colorGrading.level; // Texture Level
+            var y = colorGrading.getSize().height; // Texture Size example with 8
+            var z = y - 1.0; // SizeMinusOne 8 - 1
+            var w = 1 / y; // Space of 1 slice 1 / 8
+            effect.setFloat4("vCameraColorGradingInfos", x, y, z, w);
+            var slicePixelSizeU = w / y; // Space of 1 pixel in U direction, e.g. 1/64
+            var slicePixelSizeV = w; // Space of 1 pixel in V direction, e.g. 1/8					    // Space of 1 pixel in V direction, e.g. 1/8
+            var x2 = z * slicePixelSizeU; // Extent of lookup range in U for a single slice so that range corresponds to (size-1) texels, for example 7/64
+            var y2 = z / y; // Extent of lookup range in V for a single slice so that range corresponds to (size-1) texels, for example 7/8
+            var z2 = 0.5 * slicePixelSizeU; // Offset of lookup range in U to align sample position with texel centre, for example 0.5/64 
+            var w2 = 0.5 * slicePixelSizeV; // Offset of lookup range in V to align sample position with texel centre, for example 0.5/8
+            effect.setFloat4("vCameraColorGradingScaleOffset", x2, y2, z2, w2);
+        };
+        /**
+         * Prepare the list of uniforms associated with the ColorGrading effects.
+         * @param uniformsList The list of uniforms used in the effect
+         * @param samplersList The list of samplers used in the effect
+         */
+        ColorGradingTexture.PrepareUniformsAndSamplers = function (uniformsList, samplersList) {
+            uniformsList.push("vCameraColorGradingInfos", "vCameraColorGradingScaleOffset");
+            samplersList.push("cameraColorGrading2DSampler");
+        };
+        /**
          * Parses a color grading texture serialized by Babylon.
          * @param parsedTexture The texture information being parsedTexture
          * @param scene The scene to load the texture in

+ 6 - 21
src/Materials/babylon.pbrMaterial.js

@@ -153,8 +153,6 @@ var BABYLON;
              * This allows special effects like sepia, black and white to sixties rendering style.
              */
             this.cameraColorGradingTexture = null;
-            this._cameraColorGradingScaleOffset = new BABYLON.Vector4(1.0, 1.0, 0.0, 0.0);
-            this._cameraColorGradingInfos = new BABYLON.Vector4(1.0, 1.0, 0.0, 0.0);
             /**
              * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
              * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.
@@ -593,7 +591,7 @@ var BABYLON;
                         }
                     }
                 }
-                if (this.cameraColorGradingTexture) {
+                if (this.cameraColorGradingTexture && BABYLON.StandardMaterial.ColorGradingTextureEnabled) {
                     if (!this.cameraColorGradingTexture.isReady()) {
                         return false;
                     }
@@ -791,11 +789,11 @@ var BABYLON;
                     "vSphericalXX", "vSphericalYY", "vSphericalZZ",
                     "vSphericalXY", "vSphericalYZ", "vSphericalZX",
                     "vMicrosurfaceTextureLods",
-                    "vCameraInfos", "vCameraColorGradingInfos", "vCameraColorGradingScaleOffset"
+                    "vCameraInfos"
                 ];
-                var samplers = ["albedoSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "reflectivitySampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler",
-                    "cameraColorGrading2DSampler"];
+                var samplers = ["albedoSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "reflectivitySampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"];
                 BABYLON.ColorCurves.PrepareUniforms(uniforms);
+                BABYLON.ColorGradingTexture.PrepareUniformsAndSamplers(uniforms, samplers);
                 BABYLON.MaterialHelper.PrepareUniformsAndSamplersList(uniforms, samplers, this._defines, this.maxSimultaneousLights);
                 this._effect = scene.getEngine().createEffect(shaderName, attribs, uniforms, samplers, join, fallbacks, this.onCompiled, this.onError, { maxSimultaneousLights: this.maxSimultaneousLights });
             }
@@ -918,21 +916,8 @@ var BABYLON;
                     if ((this.reflectionTexture || this.refractionTexture)) {
                         this._effect.setFloat2("vMicrosurfaceTextureLods", this._microsurfaceTextureLods.x, this._microsurfaceTextureLods.y);
                     }
-                    if (this.cameraColorGradingTexture) {
-                        this._effect.setTexture("cameraColorGrading2DSampler", this.cameraColorGradingTexture);
-                        this._cameraColorGradingInfos.x = this.cameraColorGradingTexture.level; // Texture Level
-                        this._cameraColorGradingInfos.y = this.cameraColorGradingTexture.getSize().height; // Texture Size example with 8
-                        this._cameraColorGradingInfos.z = this._cameraColorGradingInfos.y - 1.0; // SizeMinusOne 8 - 1
-                        this._cameraColorGradingInfos.w = 1 / this._cameraColorGradingInfos.y; // Space of 1 slice 1 / 8
-                        this._effect.setFloat4("vCameraColorGradingInfos", this._cameraColorGradingInfos.x, this._cameraColorGradingInfos.y, this._cameraColorGradingInfos.z, this._cameraColorGradingInfos.w);
-                        var slicePixelSizeU = this._cameraColorGradingInfos.w / this._cameraColorGradingInfos.y; // Space of 1 pixel in U direction, e.g. 1/64
-                        var slicePixelSizeV = 1.0 / this._cameraColorGradingInfos.y; // Space of 1 pixel in V direction, e.g. 1/8
-                        this._cameraColorGradingScaleOffset.x = this._cameraColorGradingInfos.z * slicePixelSizeU; // Extent of lookup range in U for a single slice so that range corresponds to (size-1) texels, for example 7/64
-                        this._cameraColorGradingScaleOffset.y = this._cameraColorGradingInfos.z /
-                            this._cameraColorGradingInfos.y; // Extent of lookup range in V for a single slice so that range corresponds to (size-1) texels, for example 7/8
-                        this._cameraColorGradingScaleOffset.z = 0.5 * slicePixelSizeU; // Offset of lookup range in U to align sample position with texel centre, for example 0.5/64 
-                        this._cameraColorGradingScaleOffset.w = 0.5 * slicePixelSizeV; // Offset of lookup range in V to align sample position with texel centre, for example 0.5/8
-                        this._effect.setFloat4("vCameraColorGradingScaleOffset", this._cameraColorGradingScaleOffset.x, this._cameraColorGradingScaleOffset.y, this._cameraColorGradingScaleOffset.z, this._cameraColorGradingScaleOffset.w);
+                    if (this.cameraColorGradingTexture && BABYLON.StandardMaterial.ColorGradingTextureEnabled) {
+                        BABYLON.ColorGradingTexture.Bind(this.cameraColorGradingTexture, this._effect);
                     }
                 }
                 // Clip plane

+ 47 - 0
src/Materials/babylon.standardMaterial.js

@@ -70,6 +70,8 @@ var BABYLON;
             this.INVERTNORMALMAPX = false;
             this.INVERTNORMALMAPY = false;
             this.SHADOWFULLFLOAT = false;
+            this.CAMERACOLORGRADING = false;
+            this.CAMERACOLORCURVES = false;
             this.rebuild();
         }
         return StandardMaterialDefines;
@@ -108,6 +110,18 @@ var BABYLON;
              * If sets to true, y component of normal map value will invert (y = 1.0 - y).
              */
             this.invertNormalMapY = false;
+            /**
+             * Color Grading 2D Lookup Texture.
+             * This allows special effects like sepia, black and white to sixties rendering style.
+             */
+            this.cameraColorGradingTexture = null;
+            /**
+             * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
+             * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.
+             * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;
+             * corresponding to low luminance, medium luminance, and high luminance areas respectively.
+             */
+            this.cameraColorCurves = null;
             this._renderTargets = new BABYLON.SmartArray(16);
             this._worldViewProjectionMatrix = BABYLON.Matrix.Zero();
             this._globalAmbientColor = new BABYLON.Color3(0, 0, 0);
@@ -316,6 +330,14 @@ var BABYLON;
                         this._defines.REFRACTIONMAP_3D = this.refractionTexture.isCube;
                     }
                 }
+                if (this.cameraColorGradingTexture && StandardMaterial.ColorGradingTextureEnabled) {
+                    if (!this.cameraColorGradingTexture.isReady()) {
+                        return false;
+                    }
+                    else {
+                        this._defines.CAMERACOLORGRADING = true;
+                    }
+                }
             }
             // Effect
             if (scene.clipPlane) {
@@ -336,6 +358,9 @@ var BABYLON;
             if (this.useLogarithmicDepth) {
                 this._defines.LOGARITHMICDEPTH = true;
             }
+            if (this.cameraColorCurves) {
+                this._defines.CAMERACOLORCURVES = true;
+            }
             // Point size
             if (this.pointsCloud || scene.forcePointsCloud) {
                 this._defines.POINTSIZE = true;
@@ -491,6 +516,8 @@ var BABYLON;
                     "logarithmicDepthConstant"
                 ];
                 var samplers = ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"];
+                BABYLON.ColorCurves.PrepareUniforms(uniforms);
+                BABYLON.ColorGradingTexture.PrepareUniformsAndSamplers(uniforms, samplers);
                 BABYLON.MaterialHelper.PrepareUniformsAndSamplersList(uniforms, samplers, this._defines, this.maxSimultaneousLights);
                 this._effect = scene.getEngine().createEffect(shaderName, attribs, uniforms, samplers, join, fallbacks, this.onCompiled, this.onError, { maxSimultaneousLights: this.maxSimultaneousLights - 1 });
             }
@@ -610,6 +637,9 @@ var BABYLON;
                         }
                         this._effect.setFloat4("vRefractionInfos", this.refractionTexture.level, this.indexOfRefraction, depth, this.invertRefractionY ? -1 : 1);
                     }
+                    if (this.cameraColorGradingTexture && StandardMaterial.ColorGradingTextureEnabled) {
+                        BABYLON.ColorGradingTexture.Bind(this.cameraColorGradingTexture, this._effect);
+                    }
                 }
                 // Clip plane
                 BABYLON.MaterialHelper.BindClipPlane(this._effect, scene);
@@ -641,6 +671,10 @@ var BABYLON;
                 BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._effect);
                 // Log. depth
                 BABYLON.MaterialHelper.BindLogDepth(this._defines, this._effect, scene);
+                // Color Curves
+                if (this.cameraColorCurves) {
+                    BABYLON.ColorCurves.Bind(this.cameraColorCurves, this._effect);
+                }
             }
             _super.prototype.bind.call(this, world, mesh);
         };
@@ -673,6 +707,9 @@ var BABYLON;
             if (this.refractionTexture && this.refractionTexture.animations && this.refractionTexture.animations.length > 0) {
                 results.push(this.refractionTexture);
             }
+            if (this.cameraColorGradingTexture && this.cameraColorGradingTexture.animations && this.cameraColorGradingTexture.animations.length > 0) {
+                results.push(this.cameraColorGradingTexture);
+            }
             return results;
         };
         StandardMaterial.prototype.dispose = function (forceDisposeEffect, forceDisposeTextures) {
@@ -704,6 +741,9 @@ var BABYLON;
                 if (this.refractionTexture) {
                     this.refractionTexture.dispose();
                 }
+                if (this.cameraColorGradingTexture) {
+                    this.cameraColorGradingTexture.dispose();
+                }
             }
             _super.prototype.dispose.call(this, forceDisposeEffect, forceDisposeTextures);
         };
@@ -729,6 +769,7 @@ var BABYLON;
         StandardMaterial.FresnelEnabled = true;
         StandardMaterial.LightmapTextureEnabled = true;
         StandardMaterial.RefractionTextureEnabled = true;
+        StandardMaterial.ColorGradingTextureEnabled = true;
         __decorate([
             BABYLON.serializeAsTexture()
         ], StandardMaterial.prototype, "diffuseTexture", void 0);
@@ -841,6 +882,12 @@ var BABYLON;
             BABYLON.serialize()
         ], StandardMaterial.prototype, "invertNormalMapY", void 0);
         __decorate([
+            BABYLON.serializeAsTexture()
+        ], StandardMaterial.prototype, "cameraColorGradingTexture", void 0);
+        __decorate([
+            BABYLON.serializeAsColorCurves()
+        ], StandardMaterial.prototype, "cameraColorCurves", void 0);
+        __decorate([
             BABYLON.serialize()
         ], StandardMaterial.prototype, "useLogarithmicDepth", null);
         return StandardMaterial;

+ 22 - 0
src/Mesh/babylon.meshBuilder.js

@@ -99,6 +99,8 @@ var BABYLON;
             if (instance) {
                 // positionFunction : ribbon case
                 // only pathArray and sideOrientation parameters are taken into account for positions update
+                BABYLON.Vector3.FromFloatsToRef(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE, BABYLON.Tmp.Vector3[0]); // minimum
+                BABYLON.Vector3.FromFloatsToRef(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE, BABYLON.Tmp.Vector3[1]);
                 var positionFunction = function (positions) {
                     var minlg = pathArray[0].length;
                     var i = 0;
@@ -113,6 +115,24 @@ var BABYLON;
                                 positions[i] = path[j].x;
                                 positions[i + 1] = path[j].y;
                                 positions[i + 2] = path[j].z;
+                                if (path[j].x < BABYLON.Tmp.Vector3[0].x) {
+                                    BABYLON.Tmp.Vector3[0].x = path[j].x;
+                                }
+                                if (path[j].x > BABYLON.Tmp.Vector3[1].x) {
+                                    BABYLON.Tmp.Vector3[1].x = path[j].x;
+                                }
+                                if (path[j].y < BABYLON.Tmp.Vector3[0].y) {
+                                    BABYLON.Tmp.Vector3[0].y = path[j].y;
+                                }
+                                if (path[j].y > BABYLON.Tmp.Vector3[1].y) {
+                                    BABYLON.Tmp.Vector3[1].y = path[j].y;
+                                }
+                                if (path[j].z < BABYLON.Tmp.Vector3[0].z) {
+                                    BABYLON.Tmp.Vector3[0].z = path[j].z;
+                                }
+                                if (path[j].z > BABYLON.Tmp.Vector3[1].z) {
+                                    BABYLON.Tmp.Vector3[1].z = path[j].z;
+                                }
                                 j++;
                                 i += 3;
                             }
@@ -127,6 +147,8 @@ var BABYLON;
                 };
                 var positions = instance.getVerticesData(BABYLON.VertexBuffer.PositionKind);
                 positionFunction(positions);
+                instance._boundingInfo = new BABYLON.BoundingInfo(BABYLON.Tmp.Vector3[0], BABYLON.Tmp.Vector3[1]);
+                instance._boundingInfo.update(instance._worldMatrix);
                 instance.updateVerticesData(BABYLON.VertexBuffer.PositionKind, positions, false, false);
                 if (!(instance.areNormalsFrozen)) {
                     var indices = instance.getIndices();