Explorar o código

More precise SSAO
Fixing camera billboarding

David Catuhe %!s(int64=10) %!d(string=hai) anos
pai
achega
281709407b

+ 10 - 0
Babylon/Cameras/babylon.camera.js

@@ -32,6 +32,7 @@ var BABYLON;
             this._postProcesses = new Array();
             this._postProcessesTakenIndices = [];
             this._activeMeshes = new BABYLON.SmartArray(256);
+            this._globalPosition = BABYLON.Vector3.Zero();
             scene.addCamera(this);
             if (!scene.activeCamera) {
                 scene.activeCamera = this;
@@ -65,6 +66,13 @@ var BABYLON;
             enumerable: true,
             configurable: true
         });
+        Object.defineProperty(Camera.prototype, "globalPosition", {
+            get: function () {
+                return this._globalPosition;
+            },
+            enumerable: true,
+            configurable: true
+        });
         Camera.prototype.getActiveMeshes = function () {
             return this._activeMeshes;
         };
@@ -221,6 +229,7 @@ var BABYLON;
         Camera.prototype.getViewMatrix = function () {
             this._computedViewMatrix = this._computeViewMatrix();
             if (!this.parent || !this.parent.getWorldMatrix || this.isSynchronized()) {
+                this._globalPosition.copyFrom(this.position);
                 return this._computedViewMatrix;
             }
             if (!this._worldMatrix) {
@@ -230,6 +239,7 @@ var BABYLON;
             this._worldMatrix.multiplyToRef(this.parent.getWorldMatrix(), this._computedViewMatrix);
             this._computedViewMatrix.invert();
             this._currentRenderId = this.getScene().getRenderId();
+            this._globalPosition.copyFromFloats(this._computedViewMatrix.m[12], this._computedViewMatrix.m[13], this._computedViewMatrix.m[14]);
             return this._computedViewMatrix;
         };
         Camera.prototype._computeViewMatrix = function (force) {

+ 11 - 0
Babylon/Cameras/babylon.camera.ts

@@ -48,6 +48,8 @@
 
         public _activeMeshes = new SmartArray<Mesh>(256);
 
+        private _globalPosition = Vector3.Zero();
+
         constructor(name: string, public position: Vector3, scene: Scene) {
             super(name, scene);
 
@@ -58,6 +60,10 @@
             }
         }
 
+        public get globalPosition(): Vector3 {
+            return this._globalPosition;
+        }
+
         public getActiveMeshes(): SmartArray<Mesh> {
             return this._activeMeshes;
         }
@@ -281,6 +287,9 @@
             if (!this.parent
                 || !this.parent.getWorldMatrix
                 || this.isSynchronized()) {
+
+                this._globalPosition.copyFrom(this.position);
+
                 return this._computedViewMatrix;
             }
 
@@ -295,6 +304,8 @@
             this._computedViewMatrix.invert();
 
             this._currentRenderId = this.getScene().getRenderId();
+            this._globalPosition.copyFromFloats(this._computedViewMatrix.m[12], this._computedViewMatrix.m[13], this._computedViewMatrix.m[14]);
+
             return this._computedViewMatrix;
         }
 

+ 3 - 1
Babylon/Loading/Plugins/babylon.babylonFileLoader.js

@@ -780,7 +780,9 @@ var BABYLON;
                 var triggerParams;
                 var trigger = parsedActions.children[i];
                 if (trigger.properties.length > 0) {
-                    triggerParams = { trigger: BABYLON.ActionManager[trigger.name], parameter: scene.getMeshByName(trigger.properties[0].value) };
+                    var param = trigger.properties[0].value;
+                    var value = trigger.properties[0].targetType == null ? param : scene.getMeshByName(param);
+                    triggerParams = { trigger: BABYLON.ActionManager[trigger.name], parameter: value };
                 }
                 else
                     triggerParams = BABYLON.ActionManager[trigger.name];

+ 3 - 1
Babylon/Loading/Plugins/babylon.babylonFileLoader.ts

@@ -971,7 +971,9 @@
             var trigger = parsedActions.children[i];
 
             if (trigger.properties.length > 0) {
-                triggerParams = { trigger: BABYLON.ActionManager[trigger.name], parameter: scene.getMeshByName(trigger.properties[0].value) };
+                var param = trigger.properties[0].value;
+                var value = trigger.properties[0].targetType == null ? param : scene.getMeshByName(param);
+                triggerParams = { trigger: BABYLON.ActionManager[trigger.name], parameter: value };
             }
             else
                 triggerParams = BABYLON.ActionManager[trigger.name];

+ 3 - 3
Babylon/Mesh/babylon.meshSimplification.ts

@@ -401,7 +401,7 @@
             this.triangles = [];
 
             var positionData = this._mesh.getVerticesData(VertexBuffer.PositionKind);
-            
+
             var indices = this._mesh.getIndices();
             var submesh = this._mesh.subMeshes[submeshIndex];
 
@@ -431,7 +431,7 @@
             };
             //var totalVertices = mesh.getTotalVertices();
             var totalVertices = submesh.verticesCount;
-            AsyncLoop.SyncAsyncForLoop(totalVertices, (this.syncIterations / 4) >> 0, vertexInit,() => {
+            AsyncLoop.SyncAsyncForLoop(totalVertices,(this.syncIterations / 4) >> 0, vertexInit,() => {
 
                 var indicesInit = (i) => {
                     var offset = (submesh.indexStart / 3) + i;
@@ -494,7 +494,7 @@
                     newTriangles.push(t);
                 }
             }
-            
+
             var newPositionData = this._reconstructedMesh.getVerticesData(VertexBuffer.PositionKind) || [];
             var newNormalData = this._reconstructedMesh.getVerticesData(VertexBuffer.NormalKind) || [];
             var newUVsData = this._reconstructedMesh.getVerticesData(VertexBuffer.UVKind) || [];

+ 8 - 8
Babylon/PostProcess/babylon.ssaoRenderingPipeline.js

@@ -50,7 +50,7 @@ var BABYLON;
             */
             this.totalStrength = 1.0;
             /**
-            * The radius around the analyzed pixel used by the SSAO post-process. Default value is 0.002
+            * The radius around the analyzed pixel used by the SSAO post-process. Default value is 0.0002
             * @type {number}
             */
             this.radius = 0.0002;
@@ -64,10 +64,10 @@ var BABYLON;
             /**
             * Related to area, used to interpolate SSAO samples (second interpolate function input) based on the occlusion difference of each pixel
             * Must not be equal to area and inferior to area.
-            * Default value is 0.0003
+            * Default value is 0.0002
             * @type {number}
             */
-            this.fallOff = 0.0003;
+            this.fallOff = 0.0002;
             this._firstUpdate = true;
             this._scene = scene;
             // Set up assets
@@ -77,8 +77,8 @@ var BABYLON;
             var combineRatio = ratio.combineRatio || ratio;
             this._originalColorPostProcess = new BABYLON.PassPostProcess("SSAOOriginalSceneColor", combineRatio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
             this._createSSAOPostProcess(ssaoRatio);
-            this._blurHPostProcess = new BABYLON.BlurPostProcess("SSAOBlurH", new BABYLON.Vector2(1.0, 0.0), 2.0, ssaoRatio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
-            this._blurVPostProcess = new BABYLON.BlurPostProcess("SSAOBlurV", new BABYLON.Vector2(0.0, 1.0), 2.0, ssaoRatio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
+            this._blurHPostProcess = new BABYLON.BlurPostProcess("SSAOBlurH", new BABYLON.Vector2(2.0, 0.0), 2.0, ssaoRatio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
+            this._blurVPostProcess = new BABYLON.BlurPostProcess("SSAOBlurV", new BABYLON.Vector2(0.0, 2.0), 2.0, ssaoRatio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
             this._createSSAOCombinePostProcess(combineRatio);
             // Set up pipeline
             this.addEffect(new BABYLON.PostProcessRenderEffect(scene.getEngine(), this.SSAOOriginalSceneColorEffect, function () {
@@ -220,9 +220,9 @@ var BABYLON;
             for (var x = 0; x < size; x++) {
                 for (var y = 0; y < size; y++) {
                     var randVector = BABYLON.Vector3.Zero();
-                    randVector.x = randVector.y = randVector.z = Math.floor(rand(0.0, 1.0) * 255);
-                    //randVector.y = Math.floor(rand(0.0, 1.0) * 255);
-                    //randVector.z = Math.floor(rand(0.0, 1.0) * 255);
+                    randVector.x = Math.floor(rand(0.0, 1.0) * 255);
+                    randVector.y = Math.floor(rand(0.0, 1.0) * 255);
+                    randVector.z = Math.floor(rand(0.0, 1.0) * 255);
                     context.fillStyle = 'rgb(' + randVector.x + ', ' + randVector.y + ', ' + randVector.z + ')';
                     context.fillRect(x, y, 1, 1);
                 }

+ 8 - 8
Babylon/PostProcess/babylon.ssaoRenderingPipeline.ts

@@ -35,7 +35,7 @@
         public totalStrength: number = 1.0;
 
         /**
-        * The radius around the analyzed pixel used by the SSAO post-process. Default value is 0.002
+        * The radius around the analyzed pixel used by the SSAO post-process. Default value is 0.0002
         * @type {number}
         */
         public radius: number = 0.0002;
@@ -51,10 +51,10 @@
         /**
         * Related to area, used to interpolate SSAO samples (second interpolate function input) based on the occlusion difference of each pixel
         * Must not be equal to area and inferior to area.
-        * Default value is 0.0003
+        * Default value is 0.0002
         * @type {number}
         */
-        public fallOff: number = 0.0003;
+        public fallOff: number = 0.0002;
 
         private _scene: Scene;
         private _depthTexture: RenderTargetTexture;
@@ -89,8 +89,8 @@
 
             this._originalColorPostProcess = new PassPostProcess("SSAOOriginalSceneColor", combineRatio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
             this._createSSAOPostProcess(ssaoRatio);
-            this._blurHPostProcess = new BlurPostProcess("SSAOBlurH", new Vector2(1.0, 0.0), 2.0, ssaoRatio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
-            this._blurVPostProcess = new BlurPostProcess("SSAOBlurV", new Vector2(0.0, 1.0), 2.0, ssaoRatio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
+            this._blurHPostProcess = new BlurPostProcess("SSAOBlurH", new Vector2(2.0, 0.0), 2.0, ssaoRatio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
+            this._blurVPostProcess = new BlurPostProcess("SSAOBlurV", new Vector2(0.0, 2.0), 2.0, ssaoRatio, null, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
             this._createSSAOCombinePostProcess(combineRatio);
 
             // Set up pipeline
@@ -213,9 +213,9 @@
                 for (var y = 0; y < size; y++) {
                     var randVector = Vector3.Zero();
 
-                    randVector.x = randVector.y = randVector.z = Math.floor(rand(0.0, 1.0) * 255);
-                    //randVector.y = Math.floor(rand(0.0, 1.0) * 255);
-                    //randVector.z = Math.floor(rand(0.0, 1.0) * 255);
+                    randVector.x = Math.floor(rand(0.0, 1.0) * 255);
+                    randVector.y = Math.floor(rand(0.0, 1.0) * 255);
+                    randVector.z = Math.floor(rand(0.0, 1.0) * 255);
 
                     context.fillStyle = 'rgb(' + randVector.x + ', ' + randVector.y + ', ' + randVector.z + ')';
                     context.fillRect(x, y, 1, 1);

+ 2 - 2
Babylon/Shaders/ssao.fragment.fx

@@ -18,8 +18,8 @@ uniform float fallOff;
 
 varying vec2 vUV;
 
-const vec2 offset1 = vec2(0.0, 0.01);
-const vec2 offset2 = vec2(0.01, 0.0);
+const vec2 offset1 = vec2(0.0, 0.001);
+const vec2 offset2 = vec2(0.001, 0.0);
 
 vec3 normalFromDepth(const float depth, const vec2 coords) {
 	float depth1 = texture2D(textureSampler, coords + offset1).r;

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 129 - 140
babylon.2.1-alpha.debug.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 11 - 11
babylon.2.1-alpha.js