瀏覽代碼

Fixing performance.now for Safari

David Catuhe 10 年之前
父節點
當前提交
20d5b6af18

+ 26 - 0
Babylon/Materials/textures/Procedurals/babylon.standardProceduralTexture.js

@@ -226,6 +226,8 @@ var BABYLON;
             this._skyColor = new BABYLON.Color3(0.15, 0.68, 1.0);
             this._cloudColor = new BABYLON.Color3(1, 1, 1);
 
+            this.updateShaderUniforms();
+
             // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
             this.refreshRate = 0;
         }
@@ -274,5 +276,29 @@ var BABYLON;
         return GrassProceduralTexture;
     })(BABYLON.ProceduralTexture);
     BABYLON.GrassProceduralTexture = GrassProceduralTexture;
+
+    var RockProceduralTexture = (function (_super) {
+        __extends(RockProceduralTexture, _super);
+        function RockProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
+            _super.call(this, name, size, "rock", scene, fallbackTexture, generateMipMaps);
+
+            // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
+            this.refreshRate = 0;
+        }
+        return RockProceduralTexture;
+    })(BABYLON.ProceduralTexture);
+    BABYLON.RockProceduralTexture = RockProceduralTexture;
+
+    var RoadProceduralTexture = (function (_super) {
+        __extends(RoadProceduralTexture, _super);
+        function RoadProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
+            _super.call(this, name, size, "road", scene, fallbackTexture, generateMipMaps);
+
+            // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
+            this.refreshRate = 0;
+        }
+        return RoadProceduralTexture;
+    })(BABYLON.ProceduralTexture);
+    BABYLON.RoadProceduralTexture = RoadProceduralTexture;
 })(BABYLON || (BABYLON = {}));
 //# sourceMappingURL=babylon.standardProceduralTexture.js.map

+ 25 - 0
Babylon/Materials/textures/Procedurals/babylon.standardProceduralTexture.ts

@@ -186,6 +186,8 @@
         constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean) {
             super(name, size, "cloud", scene, fallbackTexture, generateMipMaps);
 
+            this.updateShaderUniforms();
+
             // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
             this.refreshRate = 0;
 
@@ -227,4 +229,27 @@
         }
     }
 
+
+    export class RockProceduralTexture extends ProceduralTexture {
+
+        constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean) {
+            super(name, size, "rock", scene, fallbackTexture, generateMipMaps);
+
+            // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
+            this.refreshRate = 0;
+
+        }
+    }
+
+    export class RoadProceduralTexture extends ProceduralTexture {
+
+        constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean) {
+            super(name, size, "road", scene, fallbackTexture, generateMipMaps);
+
+            // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
+            this.refreshRate = 0;
+
+        }
+    }
+
 }

+ 18 - 10
Babylon/Shaders/grass.fragment.fx

@@ -2,8 +2,8 @@
 precision highp float;
 #endif
 
-varying vec2 vPosition;              
-varying vec2 vUV;                    
+varying vec2 vPosition;
+varying vec2 vUV;
 
 uniform float ampScale;
 uniform float ringScale;
@@ -33,17 +33,25 @@ float fbm(vec2 n) {
 
 void main(void) {
 
-	float amplifier = 100.0;
+	float herbwidth = 8.0;
 
-	vec3 dirt = vec3(0.47, 0.27, 0.09);
+	vec3 dirt = vec3(0.32, 0.17, 0.09);
 	vec3 herb = vec3(0.0, 0.39, 0.09);
+	vec3 ground = dirt;
 
-	float ratioy = mod(vUV.y * amplifier, 2.0 + fbm(vPosition * 2.0));
-	float ratiox = mod(vUV.x * amplifier, 2.0 + fbm(vUV * 2.0));
-		
-	dirt = dirt * ratioy;
-	herb = herb * ratiox;
-	vec3 ground = mix(dirt, herb, fbm(vUV * 2.0));
+	herbwidth = floor(herbwidth - noise(vUV * 8.0 ));
+
+	float ratioy = mod(floor(gl_FragCoord.y), herbwidth);
+	float ratiox = mod(floor(gl_FragCoord.x), herbwidth);
+
+	/*herb = herb * ratiox;
+	dirt = dirt * ratioy;*/
+
+	if (ratioy >= 0.0 && ratioy < herbwidth / fbm(vUV * 2.0))
+		ground = herb;
+
+	if (ratiox >= 0.0 && ratiox < herbwidth / 2.0)
+		ground = herb;
 
 	gl_FragColor = vec4(ground, 1.0);
 }

+ 37 - 0
Babylon/Shaders/road.fragment.fx

@@ -0,0 +1,37 @@
+#ifdef GL_ES
+precision highp float;
+#endif
+
+varying vec2 vUV;                    
+
+float rand(vec2 n) {
+	return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
+}
+
+float noise(vec2 n) {
+	const vec2 d = vec2(0.0, 1.0);
+	vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));
+	return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);
+}
+
+float fbm(vec2 n) {
+	float total = 0.0, amplitude = 1.0;
+	for (int i = 0; i < 4; i++) {
+		total += noise(n) * amplitude;
+		n += n;
+		amplitude *= 0.5;
+	}
+	return total;
+}
+
+void main(void) {
+
+
+	vec3 gray = vec3(0.53, 0.53, 0.53);
+
+	float ratioy = mod(gl_FragCoord.y * 100.0 , fbm(vUV * 2.0));
+		
+	gray = gray * ratioy;
+
+	gl_FragColor = vec4(gray, 1.0);
+}

+ 114 - 0
Babylon/Shaders/rock.fragment.fx

@@ -0,0 +1,114 @@
+#ifdef GL_ES
+precision highp float;
+#endif
+
+varying vec2 vPosition;
+varying vec2 vUV;
+
+uniform float ampScale;
+uniform float ringScale;
+uniform vec3 woodColor1;
+uniform vec3 woodColor2;
+
+
+float rand(vec2 n) {
+	return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
+}
+
+float noise(vec2 n) {
+	const vec2 d = vec2(0.0, 1.0);
+	vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));
+	return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);
+}
+
+float fbm(vec2 n) {
+	float total = 0.0, amplitude = 1.0;
+	for (int i = 0; i < 4; i++) {
+		total += noise(n) * amplitude;
+		n += n;
+		amplitude *= 0.5;
+	}
+	return total;
+}
+
+
+
+void main(void) {
+
+
+	/*vec3 rock = vec3(0.53, 0.53, 0.53);
+	vec3 roll = vec3(0.18, 0.18, 0.18);
+
+	float ratioy = mod(vUV.y * 50.0, fbm(vUV * 8.0));
+
+	rock = rock * ratioy;
+	roll = roll * ratioy;
+
+	vec3 stone = mix(rock, roll, 0.5);
+
+
+	gl_FragColor = vec4(stone, 1.0);*/
+
+
+	/* voronoi.frag */
+
+
+	vec2 seeds[16];
+	vec3 colors[16];
+
+	colors[0] = vec3(0.53, 0.53, 0.53);
+	colors[1] = vec3(0.28, 0.28, 0.28);
+	colors[2] = vec3(0.23, 0.23, 0.23);
+	colors[3] = vec3(0.38, 0.38, 0.38);
+	colors[4] = vec3(0.63, 0.63, 0.63);
+	colors[5] = vec3(0.78, 0.78, 0.78);
+	colors[6] = vec3(0.93, 0.93, 0.93);
+	colors[7] = vec3(0.73, 0.73, 0.73);
+	colors[8] = vec3(0.43, 0.43, 0.43);
+	colors[9] = vec3(0.11, 0.11, 0.11);
+	colors[10] = vec3(0.12, 0.12, 0.12);
+	colors[11] = vec3(0.64, 0.64, 0.64);
+	colors[12] = vec3(0.79, 0.79, 0.79);
+	colors[13] = vec3(0.43, 0.43, 0.43);
+	colors[14] = vec3(0.21, 0.21, 0.21);
+	colors[15] = vec3(0.37, 0.37, 0.37);
+
+	seeds[0] = vec2(0.1, 0.9);
+	seeds[1] = vec2(0.2, 0.8);
+	seeds[2] = vec2(0.3, 0.7);
+	seeds[3] = vec2(0.4, 0.4);
+	seeds[4] = vec2(0.5, 0.5);
+	seeds[5] = vec2(0.6, 0.3);
+	seeds[6] = vec2(0.7, 0.2);
+	seeds[7] = vec2(0.8, 0.3);
+	seeds[8] = vec2(0.9, 0.4);
+	seeds[9] = vec2(1.0, 0.3);
+	seeds[10] = vec2(0.5, 0.4);
+	seeds[11] = vec2(0.7, 0.8);
+	seeds[12] = vec2(0.5, 0.3);
+	seeds[13] = vec2(0.7, 0.7);
+	seeds[14] = vec2(0.3, 0.3);
+	seeds[15] = vec2(0.7, 0.7);
+
+	float dist = distance(seeds[0], vPosition);
+	vec3 color = colors[0];
+
+	float hotpoint = 1.0;
+	float current = 1.0;
+	for (int i = 1; i < 16; i++) {
+		current = distance(seeds[i], vPosition);
+		if (current < dist) {
+			hotpoint++;
+			color = colors[i];
+			dist = current;
+		}
+	}
+
+	if (hotpoint > 3.0)
+		color = mix(vec3(0.39, 0.32, 0), color, 1.0 / hotpoint);
+
+	gl_FragColor = vec4(color, 1.0);
+
+
+
+}

+ 1 - 1
Babylon/Tools/babylon.tools.js

@@ -747,7 +747,7 @@
 
         Object.defineProperty(Tools, "Now", {
             get: function () {
-                if (window.performance.now) {
+                if (window.performance && window.performance.now) {
                     return window.performance.now();
                 }
 

+ 1 - 1
Babylon/Tools/babylon.tools.ts

@@ -775,7 +775,7 @@
         public static EndPerformanceCounter: (counterName: string, condition?: boolean) => void = Tools._EndPerformanceCounterDisabled;
 
         public static get Now(): number {
-            if (window.performance.now) {
+            if (window.performance && window.performance.now) {
                 return window.performance.now();
             }
 

文件差異過大導致無法顯示
+ 30 - 2
babylon.2.0-alpha.debug.js


文件差異過大導致無法顯示
+ 3 - 3
babylon.2.0-alpha.js


+ 6 - 44
babylon.2.0.d.ts

@@ -1776,50 +1776,6 @@ declare module BABYLON {
     }
 }
 declare module BABYLON {
-    class ProceduralTexture extends Texture {
-        private _size;
-        public _generateMipMaps: boolean;
-        private _doNotChangeAspectRatio;
-        private _currentRefreshId;
-        private _refreshRate;
-        private _vertexBuffer;
-        private _indexBuffer;
-        private _effect;
-        private _vertexDeclaration;
-        private _vertexStrideSize;
-        private _uniforms;
-        private _samplers;
-        private _fragment;
-        private _textures;
-        private _floats;
-        private _floatsArrays;
-        private _colors3;
-        private _colors4;
-        private _vectors2;
-        private _vectors3;
-        private _matrices;
-        constructor(name: string, size: any, fragment: any, scene: Scene, generateMipMaps?: boolean);
-        public isReady(): boolean;
-        public resetRefreshCounter(): void;
-        public refreshRate : number;
-        public _shouldRender(): boolean;
-        public getRenderSize(): number;
-        public resize(size: any, generateMipMaps: any): void;
-        private _checkUniform(uniformName);
-        public setTexture(name: string, texture: Texture): ProceduralTexture;
-        public setFloat(name: string, value: number): ProceduralTexture;
-        public setFloats(name: string, value: number[]): ProceduralTexture;
-        public setColor3(name: string, value: Color3): ProceduralTexture;
-        public setColor4(name: string, value: Color4): ProceduralTexture;
-        public setVector2(name: string, value: Vector2): ProceduralTexture;
-        public setVector3(name: string, value: Vector3): ProceduralTexture;
-        public setMatrix(name: string, value: Matrix): ProceduralTexture;
-        public render(useCameraPostProcess?: boolean): void;
-        public clone(): ProceduralTexture;
-        public dispose(): void;
-    }
-}
-declare module BABYLON {
     class RenderTargetTexture extends Texture {
         public renderList: AbstractMesh[];
         public renderParticles: boolean;
@@ -1992,6 +1948,12 @@ declare module BABYLON {
     class GrassProceduralTexture extends ProceduralTexture {
         constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean);
     }
+    class RockProceduralTexture extends ProceduralTexture {
+        constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean);
+    }
+    class RoadProceduralTexture extends ProceduralTexture {
+        constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean);
+    }
 }
 declare module BABYLON {
     class Color3 {