Forráskód Böngészése

LOD update
New effect.onBind callback

David Catuhe 10 éve
szülő
commit
cd964595fa

+ 1 - 0
Babylon/Materials/babylon.effect.ts

@@ -44,6 +44,7 @@
         public defines: string;
         public onCompiled: (effect: Effect) => void;
         public onError: (effect: Effect, errors: string) => void;
+        public onBind: (effect: Effect) => void;
 
         private _engine: Engine;
         private _uniformsNames: string[];

+ 50 - 36
Babylon/Materials/textures/Procedurals/babylon.standardProceduralTexture.js

@@ -10,10 +10,8 @@ var BABYLON;
         __extends(WoodProceduralTexture, _super);
         function WoodProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
             _super.call(this, name, size, "wood", scene, fallbackTexture, generateMipMaps);
-            this._ampScale = 0.03;
-            this._ringScale = 5;
-            this._woodColor1 = new BABYLON.Color3(0.80, 0.55, 0.01);
-            this._woodColor2 = new BABYLON.Color3(0.60, 0.41, 0.0);
+            this._ampScale = 100.0;
+            this._woodColor = new BABYLON.Color3(0.32, 0.17, 0.09);
 
             this.updateShaderUniforms();
 
@@ -22,9 +20,7 @@ var BABYLON;
         }
         WoodProceduralTexture.prototype.updateShaderUniforms = function () {
             this.setFloat("ampScale", this._ampScale);
-            this.setFloat("ringScale", this._ringScale);
-            this.setColor3("woodColor1", this._woodColor1);
-            this.setColor3("woodColor2", this._woodColor2);
+            this.setColor3("woodColor", this._woodColor);
         };
 
         Object.defineProperty(WoodProceduralTexture.prototype, "ampScale", {
@@ -40,38 +36,12 @@ var BABYLON;
         });
 
 
-        Object.defineProperty(WoodProceduralTexture.prototype, "ringScale", {
+        Object.defineProperty(WoodProceduralTexture.prototype, "woodColor", {
             get: function () {
-                return this._ringScale;
+                return this._woodColor;
             },
             set: function (value) {
-                this._ringScale = value;
-                this.updateShaderUniforms();
-            },
-            enumerable: true,
-            configurable: true
-        });
-
-
-        Object.defineProperty(WoodProceduralTexture.prototype, "woodColor1", {
-            get: function () {
-                return this._woodColor1;
-            },
-            set: function (value) {
-                this._woodColor1 = value;
-                this.updateShaderUniforms();
-            },
-            enumerable: true,
-            configurable: true
-        });
-
-
-        Object.defineProperty(WoodProceduralTexture.prototype, "woodColor2", {
-            get: function () {
-                return this._woodColor2;
-            },
-            set: function (value) {
-                this._woodColor2 = value;
+                this._woodColor = value;
                 this.updateShaderUniforms();
             },
             enumerable: true,
@@ -253,12 +223,56 @@ var BABYLON;
         __extends(CloudProceduralTexture, _super);
         function CloudProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
             _super.call(this, name, size, "cloud", scene, fallbackTexture, generateMipMaps);
+            this._skyColor = new BABYLON.Color3(0.15, 0.68, 1.0);
+            this._cloudColor = new BABYLON.Color3(1, 1, 1);
 
             // Use 0 to render just once, 1 to render on every frame, 2 to render every two frames and so on...
             this.refreshRate = 0;
         }
+        CloudProceduralTexture.prototype.updateShaderUniforms = function () {
+            this.setColor3("skyColor", this._skyColor);
+            this.setColor3("cloudColor", this._cloudColor);
+        };
+
+        Object.defineProperty(CloudProceduralTexture.prototype, "skyColor", {
+            get: function () {
+                return this._skyColor;
+            },
+            set: function (value) {
+                this._skyColor = value;
+                this.updateShaderUniforms();
+            },
+            enumerable: true,
+            configurable: true
+        });
+
+
+        Object.defineProperty(CloudProceduralTexture.prototype, "cloudColor", {
+            get: function () {
+                return this._cloudColor;
+            },
+            set: function (value) {
+                this._cloudColor = value;
+                this.updateShaderUniforms();
+            },
+            enumerable: true,
+            configurable: true
+        });
+
         return CloudProceduralTexture;
     })(BABYLON.ProceduralTexture);
     BABYLON.CloudProceduralTexture = CloudProceduralTexture;
+
+    var GrassProceduralTexture = (function (_super) {
+        __extends(GrassProceduralTexture, _super);
+        function GrassProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
+            _super.call(this, name, size, "grass", 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 GrassProceduralTexture;
+    })(BABYLON.ProceduralTexture);
+    BABYLON.GrassProceduralTexture = GrassProceduralTexture;
 })(BABYLON || (BABYLON = {}));
 //# sourceMappingURL=babylon.standardProceduralTexture.js.map

+ 45 - 29
Babylon/Materials/textures/Procedurals/babylon.standardProceduralTexture.ts

@@ -1,12 +1,10 @@
 module BABYLON {
     export class WoodProceduralTexture extends ProceduralTexture {
 
-        private _ampScale: number = 0.03;
-        private _ringScale: number = 5;
-        private _woodColor1: BABYLON.Color3 = new BABYLON.Color3(0.80, 0.55, 0.01);
-        private _woodColor2: BABYLON.Color3 = new BABYLON.Color3(0.60, 0.41, 0.0);
+        private _ampScale: number = 100.0;
+        private _woodColor: BABYLON.Color3 = new BABYLON.Color3(0.32, 0.17, 0.09);
 
-        constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture,  generateMipMaps?: boolean) {
+        constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean) {
             super(name, size, "wood", scene, fallbackTexture, generateMipMaps);
 
             this.updateShaderUniforms();
@@ -18,9 +16,7 @@
 
         public updateShaderUniforms() {
             this.setFloat("ampScale", this._ampScale);
-            this.setFloat("ringScale", this._ringScale);
-            this.setColor3("woodColor1", this._woodColor1);
-            this.setColor3("woodColor2", this._woodColor2);
+            this.setColor3("woodColor", this._woodColor);
         }
 
         public get ampScale(): number {
@@ -32,30 +28,13 @@
             this.updateShaderUniforms();
         }
 
-        public get ringScale(): number {
-            return this._ringScale;
-        }
-
-        public set ringScale(value: number) {
-            this._ringScale = value;
-            this.updateShaderUniforms();
-        }
 
-        public get woodColor1(): BABYLON.Color3 {
-            return this._woodColor1;
+        public get woodColor(): BABYLON.Color3 {
+            return this._woodColor;
         }
 
-        public set woodColor1(value: BABYLON.Color3) {
-            this._woodColor1 = value;
-            this.updateShaderUniforms();
-        }
-
-        public get woodColor2(): BABYLON.Color3 {
-            return this._woodColor2;
-        }
-
-        public set woodColor2(value: BABYLON.Color3) {
-            this._woodColor2 = value;
+        public set woodColor(value: BABYLON.Color3) {
+            this._woodColor = value;
             this.updateShaderUniforms();
         }
 
@@ -201,9 +180,46 @@
 
     export class CloudProceduralTexture extends ProceduralTexture {
 
+        private _skyColor: BABYLON.Color3 = new BABYLON.Color3(0.15, 0.68, 1.0);
+        private _cloudColor: BABYLON.Color3 = new BABYLON.Color3(1, 1, 1);
+
         constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean) {
             super(name, size, "cloud", 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;
+
+        }
+
+        public updateShaderUniforms() {
+
+            this.setColor3("skyColor", this._skyColor);
+            this.setColor3("cloudColor", this._cloudColor);
+        }
+
+        public get skyColor(): BABYLON.Color3 {
+            return this._skyColor;
+        }
+
+        public set skyColor(value: BABYLON.Color3) {
+            this._skyColor = value;
+            this.updateShaderUniforms();
+        }
+
+        public get cloudColor(): BABYLON.Color3 {
+            return this._cloudColor;
+        }
+
+        public set cloudColor(value: BABYLON.Color3) {
+            this._cloudColor = value;
+            this.updateShaderUniforms();
+        }
+    }
+
+    export class GrassProceduralTexture extends ProceduralTexture {
+
+        constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean) {
+            super(name, size, "grass", 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;

+ 8 - 0
Babylon/Mesh/babylon.mesh.js

@@ -109,6 +109,14 @@ var BABYLON;
             return this;
         };
 
+        Object.defineProperty(Mesh.prototype, "geometry", {
+            get: function () {
+                return this._geometry;
+            },
+            enumerable: true,
+            configurable: true
+        });
+
         Mesh.prototype.getTotalVertices = function () {
             if (!this._geometry) {
                 return 0;

+ 4 - 0
Babylon/Mesh/babylon.mesh.ts

@@ -111,6 +111,10 @@
             return this;
         }
 
+        public get geometry(): Geometry {
+            return this._geometry;
+        }
+
         public getTotalVertices(): number {
             if (!this._geometry) {
                 return 0;

+ 15 - 0
Babylon/Mesh/babylon.meshLODLevel.js

@@ -0,0 +1,15 @@
+var BABYLON;
+(function (BABYLON) {
+    (function (Internals) {
+        var MeshLODLevel = (function () {
+            function MeshLODLevel(distance, mesh) {
+                this.distance = distance;
+                this.mesh = mesh;
+            }
+            return MeshLODLevel;
+        })();
+        Internals.MeshLODLevel = MeshLODLevel;
+    })(BABYLON.Internals || (BABYLON.Internals = {}));
+    var Internals = BABYLON.Internals;
+})(BABYLON || (BABYLON = {}));
+//# sourceMappingURL=babylon.meshLODLevel.js.map

+ 4 - 12
Babylon/Shaders/cloud.fragment.fx

@@ -2,19 +2,11 @@
 precision highp float;
 #endif
 
-uniform float iGlobalTime;
-uniform vec3 c1;
-uniform vec3 c2;
-uniform vec3 c3;
-uniform vec3 c4;
-uniform vec3 c5;
-uniform vec3 c6;
-uniform vec2 speed;
-uniform float shift;
-uniform float alpha;
-
 varying vec2 vUV;
 
+uniform vec3 skyColor;
+uniform vec3 cloudColor;
+
 float rand(vec2 n) {
 	return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
 }
@@ -38,7 +30,7 @@ float fbm(vec2 n) {
 void main() {
 
 	vec2 p = vUV * 12.0;
-	vec3 c = mix(vec3(0.15, 0.68, 1.0), vec3(1,1,1), fbm(p));
+	vec3 c = mix(skyColor, cloudColor, fbm(p));
 	gl_FragColor = vec4(c, 1);
 
 }

+ 49 - 0
Babylon/Shaders/grass.fragment.fx

@@ -0,0 +1,49 @@
+#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) {
+
+	float amplifier = 100.0;
+
+	vec3 dirt = vec3(0.47, 0.27, 0.09);
+	vec3 herb = vec3(0.0, 0.39, 0.09);
+
+	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));
+
+	gl_FragColor = vec4(ground, 1.0);
+}

+ 6 - 11
Babylon/Shaders/wood.fragment.fx

@@ -2,13 +2,11 @@
 precision highp float;
 #endif
 
-varying vec2 vPosition;              
-varying vec2 vUV;                    
+varying vec2 vPosition;
+varying vec2 vUV;
 
 uniform float ampScale;
-uniform float ringScale;
-uniform vec3 woodColor1;
-uniform vec3 woodColor2;
+uniform vec3 woodColor;
 
 
 float rand(vec2 n) {
@@ -33,11 +31,8 @@ float fbm(vec2 n) {
 
 void main(void) {
 
-	vec2 positionWood = vPosition;
-	float r = ringScale * sqrt(dot(positionWood.xy, positionWood.xy));
-	r = r + fbm(vPosition);
-	r = r - floor(r);
-	r = smoothstep(0.0, 0.8, r) - smoothstep(0.8, 1.0, r);
+	float ratioy = mod(vUV.x * ampScale, 2.0 + fbm(vUV * 0.8));
+	vec3 wood = woodColor * ratioy;
 
-	gl_FragColor = vec4(mix(woodColor1, woodColor2, r), 1.0);
+	gl_FragColor = vec4(wood, 1.0);
 }

+ 7 - 0
Babylon/babylon.engine.js

@@ -1005,6 +1005,9 @@
 
         Engine.prototype.enableEffect = function (effect) {
             if (!effect || !effect.getAttributesCount() || this._currentEffect === effect) {
+                if (effect && effect.onBind) {
+                    effect.onBind(effect);
+                }
                 return;
             }
 
@@ -1033,6 +1036,10 @@
             }
 
             this._currentEffect = effect;
+
+            if (effect.onBind) {
+                effect.onBind(effect);
+            }
         };
 
         Engine.prototype.setArray = function (uniform, array) {

+ 8 - 0
Babylon/babylon.engine.ts

@@ -1019,6 +1019,10 @@
 
         public enableEffect(effect: Effect): void {
             if (!effect || !effect.getAttributesCount() || this._currentEffect === effect) {
+
+                if (effect && effect.onBind) {
+                    effect.onBind(effect);
+                }
                 return;
             }
 
@@ -1047,6 +1051,10 @@
             }
 
             this._currentEffect = effect;
+
+            if (effect.onBind) {
+                effect.onBind(effect);
+            }
         }
 
         public setArray(uniform: WebGLUniformLocation, array: number[]): void {

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 68 - 38
babylon.2.0-alpha.debug.js


A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 8 - 8
babylon.2.0-alpha.js


+ 12 - 6
babylon.2.0.d.ts

@@ -1518,6 +1518,7 @@ declare module BABYLON {
         public defines: string;
         public onCompiled: (effect: Effect) => void;
         public onError: (effect: Effect, errors: string) => void;
+        public onBind: (effect: Effect) => void;
         private _engine;
         private _uniformsNames;
         private _samplers;
@@ -1954,15 +1955,11 @@ declare module BABYLON {
 declare module BABYLON {
     class WoodProceduralTexture extends ProceduralTexture {
         private _ampScale;
-        private _ringScale;
-        private _woodColor1;
-        private _woodColor2;
+        private _woodColor;
         constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean);
         public updateShaderUniforms(): void;
         public ampScale : number;
-        public ringScale : number;
-        public woodColor1 : Color3;
-        public woodColor2 : Color3;
+        public woodColor : Color3;
     }
     class FireProceduralTexture extends ProceduralTexture {
         private _time;
@@ -1985,6 +1982,14 @@ declare module BABYLON {
         public alpha : number;
     }
     class CloudProceduralTexture extends ProceduralTexture {
+        private _skyColor;
+        private _cloudColor;
+        constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean);
+        public updateShaderUniforms(): void;
+        public skyColor : Color3;
+        public cloudColor : Color3;
+    }
+    class GrassProceduralTexture extends ProceduralTexture {
         constructor(name: string, size: number, scene: Scene, fallbackTexture?: Texture, generateMipMaps?: boolean);
     }
 }
@@ -2710,6 +2715,7 @@ declare module BABYLON {
         public addLODLevel(distance: number, mesh: Mesh): Mesh;
         public removeLODLevel(mesh: Mesh): Mesh;
         public getLOD(camera: Camera): AbstractMesh;
+        public geometry : Geometry;
         public getTotalVertices(): number;
         public getVerticesData(kind: string): number[];
         public getVertexBuffer(kind: any): VertexBuffer;