Преглед на файлове

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

Conflicts:
	src/Tools/babylon.sceneSerializer.ts
David Catuhe преди 9 години
родител
ревизия
547c567f88

+ 41 - 42
loaders/glTF/README.md

@@ -1,42 +1,41 @@
-# Babylon.js glTF File Loader
-
-# Usage
-The glTF file loader is a SceneLoader plugin.
-Just reference the loader in your HTML file:
-
-```
-<script src="babylon.2.1.js"></script>
-<script src="babylon.glTFFileLoader.js"></script>
-```
-
-And then, call the scene loader:
-```
-BABYLON.SceneLoader.Load("./", "duck.gltf", engine, function (scene) { 
-   // do somethings with the scene
-});
-```
-
-## Supported features
-* Load scenes (SceneLoader.Load)
-* Import geometries
-    * From binary files
-    * From base64 buffers
-* Import lights
-* Import cameras
-* Import and set custom shaders (if no shaders, the Babylon.js default material is applied)
-    * Automatically bind attributes
-    * Automatically bind matrices
-    * Set uniforms
-* Import and set animations
-* Skinning
-    * Skeletons
-    * Hardware skinning (shaders support)
-* Handle dummy nodes (empty nodes)
-
-## Unsupported features
-* ImportMesh function
-* Skinning
-    * Bones animations
-
-## To improve
-* Bones import
+# Babylon.js glTF File Loader
+
+# Usage
+The glTF file loader is a SceneLoader plugin.
+Just reference the loader in your HTML file:
+
+```
+<script src="babylon.2.1.js"></script>
+<script src="babylon.glTFFileLoader.js"></script>
+```
+
+And then, call the scene loader:
+```
+BABYLON.SceneLoader.Load("./", "duck.gltf", engine, function (scene) { 
+   // do somethings with the scene
+});
+```
+
+## Supported features
+* Load scenes (SceneLoader.Load)
+* Import geometries
+    * From binary files
+    * From base64 buffers
+* Import lights
+* Import cameras
+* Import and set custom shaders (if no shaders, the Babylon.js default material is applied)
+    * Automatically bind attributes
+    * Automatically bind matrices
+    * Set uniforms
+* Import and set animations
+* Skinning
+    * Skeletons
+    * Hardware skinning (shaders support)
+    * Bones import
+* Handle dummy nodes (empty nodes)
+
+## Unsupported features
+* ImportMesh function
+
+## To improve
+* Test on more models

Файловите разлики са ограничени, защото са твърде много
+ 1306 - 1166
loaders/glTF/babylon.glTFFileLoader.js


Файловите разлики са ограничени, защото са твърде много
+ 1533 - 1388
loaders/glTF/babylon.glTFFileLoader.ts


+ 263 - 279
loaders/glTF/babylon.glTFFileLoaderInterfaces.ts

@@ -1,280 +1,264 @@
-module BABYLON {
-    /**
-    * Interfaces
-    */
-    export interface IGLTFChildRootProperty {
-        name?: string;
-    }
-
-    export interface IGLTFAccessor extends IGLTFChildRootProperty {
-        bufferView: string;
-        byteOffset: number;
-        byteStride: number;
-        count: number;
-        type: string;
-        componentType: EComponentType;
-
-        max?: number[],
-        min?: number[],
-        name?: string;
-    }
-
-    export interface IGLTFBufferView extends IGLTFChildRootProperty {
-        buffer: string;
-        byteOffset: number;
-        byteLength: number;
-
-        target?: number;
-    }
-
-    export interface IGLTFBuffer extends IGLTFChildRootProperty {
-        uri: string;
-
-        byteLength?: number;
-        type?: string;
-    }
-
-    export interface IGLTFShader extends IGLTFChildRootProperty {
-        uri: string;
-        type: EShaderType;
-    }
-
-    export interface IGLTFProgram extends IGLTFChildRootProperty {
-        attributes: string[];
-        fragmentShader: string;
-        vertexShader: string;
-    }
-
-    export interface IGLTFTechniqueParameter {
-        type: number;
-
-        count?: number;
-        semantic?: string;
-        node?: string;
-        value?: number|boolean|string|Array<any>;
-        source?: string;
-
-        babylonValue?: any;
-    }
-
-    export interface IGLTFTechniquePassCommonProfile {
-        lightingModel: string;
-        texcoordBindings: Object;
-
-        parameters?: Array<any>;
-    }
-
-    export interface IGLTFTechniquePassInstanceProgram {
-        program: string;
-
-        attributes?: Object;
-        uniforms: Object;
-    }
-
-    export interface IGLTFTechniquePassStatesFunctions {
-        blendColor?: number[];
-        blendEquationSeparate?: number[];
-        blendFuncSeparate?: number[];
-    }
-
-    export interface IGLTFTechniquePassStates {
-        enable: number[];
-        functions: IGLTFTechniquePassStatesFunctions;
-    }
-
-    export interface IGLTFTechniquePassDetails {
-        commonProfile: IGLTFTechniquePassCommonProfile;
-        type: string;
-    }
-
-    export interface IGLTFTechniquePass {
-        details: IGLTFTechniquePassDetails;
-        instanceProgram: IGLTFTechniquePassInstanceProgram;
-        states: IGLTFTechniquePassStates;
-    }
-
-    export interface IGLTFTechnique extends IGLTFChildRootProperty {
-        parameters: Object;
-        pass: string;
-        passes: Object;
-    }
-
-    export interface IGLTFMaterialInstanceTechnique {
-        technique: string;
-
-        values?: Object;
-    }
-
-    export interface IGLTFMaterial extends IGLTFChildRootProperty {
-        instanceTechnique: IGLTFMaterialInstanceTechnique;
-    }
-
-    export interface IGLTFMeshPrimitive {
-        attributes: Object;
-        indices: string;
-        material: string;
-
-        primitive?: number;
-    }
-
-    export interface IGLTFMesh extends IGLTFChildRootProperty {
-        primitives: IGLTFMeshPrimitive[];
-    }
-
-    export interface IGLTFImage extends IGLTFChildRootProperty {
-        uri: string;
-    }
-
-    export interface IGLTFSampler extends IGLTFChildRootProperty {
-        magFilter?: number;
-        minFilter?: number;
-        wrapS?: number;
-        wrapT?: number;
-    }
-
-    export interface IGLTFTexture extends IGLTFChildRootProperty {
-        sampler: string;
-        source: string;
-
-        format?: ETextureFormat;
-        internalFormat?: ETextureFormat;
-        target?: number;
-        type?: number;
-        
-        // Babylon.js values (optimize)
-        babylonTexture?: Texture;
-    }
-
-    export interface IGLTFAmbienLight {
-        color?: number[];
-    }
-
-    export interface IGLTFDirectionalLight {
-        color?: number[];
-    }
-
-    export interface IGLTFPointLight {
-        color?: number[];
-        constantAttenuation?: number;
-        linearAttenuation?: number;
-        quadraticAttenuation?: number;
-    }
-
-    export interface IGLTFSpotLight {
-        color?: number[];
-        constantAttenuation?: number;
-        fallOfAngle?: number;
-        fallOffExponent?: number;
-        linearAttenuation?: number;
-        quadraticAttenuation?: number;
-    }
-
-    export interface IGLTFLight extends IGLTFChildRootProperty {
-        type: string;
-    }
-
-    export interface IGLTFCameraOrthographic {
-        xmag: number;
-        ymag: number;
-        zfar: number;
-        znear: number;
-    }
-
-    export interface IGLTFCameraPerspective {
-        aspectRatio: number;
-        yfov: number;
-        zfar: number;
-        znear: number;
-    }
-
-    export interface IGLTFCamera extends IGLTFChildRootProperty {
-        type: string;
-    }
-
-    export interface IGLTFAnimationChannelTarget {
-        id: string;
-        path: string;
-    }
-
-    export interface IGLTFAnimationChannel {
-        sampler: string;
-        target: IGLTFAnimationChannelTarget;
-    }
-
-    export interface IGLTFAnimationSampler {
-        input: string;
-        output: string;
-
-        interpolation?: string;
-    }
-
-    export interface IGLTFAnimation extends IGLTFChildRootProperty {
-        channels?: IGLTFAnimationChannel[];
-        parameters?: Object;
-        samplers?: Object;
-    }
-
-    export interface IGLTFNodeInstanceSkin {
-        skeletons: string[];
-        skin: string;
-        meshes: string[];
-    }
-
-    export interface IGLTFSkins extends IGLTFChildRootProperty {
-        bindShapeMatrix: number[];
-        inverseBindMatrices: string;
-        jointNames: string[];
-    }
-
-    export interface IGLTFNode extends IGLTFChildRootProperty {
-        camera?: string;
-        children: string[];
-        instanceSkin?: IGLTFNodeInstanceSkin;
-        jointName?: string;
-        light?: string;
-        matrix: number[];
-        mesh?: string;
-        meshes?: string[];
-        rotation?: number[];
-        scale?: number[];
-        translation?: number[];
-    }
-
-    export interface IGLTFScene extends IGLTFChildRootProperty {
-        nodes: string[];
-    }
-
-    /**
-    * Runtime
-    */
-    export interface IGLTFRuntime {
-        accessors: Object;
-        buffers: Object;
-        bufferViews: Object;
-        meshes: Object;
-        lights: Object;
-        cameras: Object;
-        nodes: Object;
-        images: Object;
-        textures: Object;
-        shaders: Object;
-        programs: Object;
-        samplers: Object;
-        techniques: Object;
-        materials: Object;
-        animations: Object;
-        skins: Object;
-        currentScene: Object;
-
-        buffersCount: number;
-        shaderscount: number;
-
-        scene: Scene;
-        rootUrl: string;
-        loadedBuffers: number;
-        loadedShaders: number;
-        arrayBuffers: Object;
-
-        dummyNodes: Node[];
-    }
+module BABYLON {
+    /**
+    * Interfaces
+    */
+    export interface IGLTFChildRootProperty {
+        name?: string;
+    }
+
+    export interface IGLTFAccessor extends IGLTFChildRootProperty {
+        bufferView: string;
+        byteOffset: number;
+        byteStride: number;
+        count: number;
+        type: string;
+        componentType: EComponentType;
+
+        max?: number[],
+        min?: number[],
+        name?: string;
+    }
+
+    export interface IGLTFBufferView extends IGLTFChildRootProperty {
+        buffer: string;
+        byteOffset: number;
+        byteLength: number;
+
+        target?: number;
+    }
+
+    export interface IGLTFBuffer extends IGLTFChildRootProperty {
+        uri: string;
+
+        byteLength?: number;
+        type?: string;
+    }
+
+    export interface IGLTFShader extends IGLTFChildRootProperty {
+        uri: string;
+        type: EShaderType;
+    }
+
+    export interface IGLTFProgram extends IGLTFChildRootProperty {
+        attributes: string[];
+        fragmentShader: string;
+        vertexShader: string;
+    }
+
+    export interface IGLTFTechniqueParameter {
+        type: number;
+
+        count?: number;
+        semantic?: string;
+        node?: string;
+        value?: number|boolean|string|Array<any>;
+        source?: string;
+
+        babylonValue?: any;
+    }
+
+    export interface IGLTFTechniqueCommonProfile {
+        lightingModel: string;
+        texcoordBindings: Object;
+
+        parameters?: Array<any>;
+    }
+
+    export interface IGLTFTechniqueStatesFunctions {
+        blendColor?: number[];
+        blendEquationSeparate?: number[];
+        blendFuncSeparate?: number[];
+        colorMask: boolean[];
+        cullFace: number[];
+    }
+
+    export interface IGLTFTechniqueStates {
+        enable: number[];
+        functions: IGLTFTechniqueStatesFunctions;
+    }
+
+    export interface IGLTFTechnique extends IGLTFChildRootProperty {
+        parameters: Object;
+        program: string;
+
+        attributes: Object;
+        uniforms: Object;
+        states: IGLTFTechniqueStates;
+    }
+
+    export interface IGLTFMaterial extends IGLTFChildRootProperty {
+        technique?: string;
+        values: string[];
+    }
+
+    export interface IGLTFMeshPrimitive {
+        attributes: Object;
+        indices: string;
+        material: string;
+
+        primitive?: number;
+    }
+
+    export interface IGLTFMesh extends IGLTFChildRootProperty {
+        primitives: IGLTFMeshPrimitive[];
+    }
+
+    export interface IGLTFImage extends IGLTFChildRootProperty {
+        uri: string;
+    }
+
+    export interface IGLTFSampler extends IGLTFChildRootProperty {
+        magFilter?: number;
+        minFilter?: number;
+        wrapS?: number;
+        wrapT?: number;
+    }
+
+    export interface IGLTFTexture extends IGLTFChildRootProperty {
+        sampler: string;
+        source: string;
+
+        format?: ETextureFormat;
+        internalFormat?: ETextureFormat;
+        target?: number;
+        type?: number;
+        
+        // Babylon.js values (optimize)
+        babylonTexture?: Texture;
+    }
+
+    export interface IGLTFAmbienLight {
+        color?: number[];
+    }
+
+    export interface IGLTFDirectionalLight {
+        color?: number[];
+    }
+
+    export interface IGLTFPointLight {
+        color?: number[];
+        constantAttenuation?: number;
+        linearAttenuation?: number;
+        quadraticAttenuation?: number;
+    }
+
+    export interface IGLTFSpotLight {
+        color?: number[];
+        constantAttenuation?: number;
+        fallOfAngle?: number;
+        fallOffExponent?: number;
+        linearAttenuation?: number;
+        quadraticAttenuation?: number;
+    }
+
+    export interface IGLTFLight extends IGLTFChildRootProperty {
+        type: string;
+    }
+
+    export interface IGLTFCameraOrthographic {
+        xmag: number;
+        ymag: number;
+        zfar: number;
+        znear: number;
+    }
+
+    export interface IGLTFCameraPerspective {
+        aspectRatio: number;
+        yfov: number;
+        zfar: number;
+        znear: number;
+    }
+
+    export interface IGLTFCamera extends IGLTFChildRootProperty {
+        type: string;
+    }
+
+    export interface IGLTFAnimationChannelTarget {
+        id: string;
+        path: string;
+    }
+
+    export interface IGLTFAnimationChannel {
+        sampler: string;
+        target: IGLTFAnimationChannelTarget;
+    }
+
+    export interface IGLTFAnimationSampler {
+        input: string;
+        output: string;
+
+        interpolation?: string;
+    }
+
+    export interface IGLTFAnimation extends IGLTFChildRootProperty {
+        channels?: IGLTFAnimationChannel[];
+        parameters?: Object;
+        samplers?: Object;
+    }
+
+    export interface IGLTFNodeInstanceSkin {
+        skeletons: string[];
+        skin: string;
+        meshes: string[];
+    }
+
+    export interface IGLTFSkins extends IGLTFChildRootProperty {
+        bindShapeMatrix: number[];
+        inverseBindMatrices: string;
+        jointNames: string[];
+    }
+
+    export interface IGLTFNode extends IGLTFChildRootProperty {
+        camera?: string;
+        children: string[];
+        skin?: string;
+        jointName?: string;
+        light?: string;
+        matrix: number[];
+        mesh?: string;
+        meshes?: string[];
+        rotation?: number[];
+        scale?: number[];
+        translation?: number[];
+    }
+
+    export interface IGLTFScene extends IGLTFChildRootProperty {
+        nodes: string[];
+    }
+
+    /**
+    * Runtime
+    */
+    export interface IGLTFRuntime {
+        accessors: Object;
+        buffers: Object;
+        bufferViews: Object;
+        meshes: Object;
+        lights: Object;
+        cameras: Object;
+        nodes: Object;
+        images: Object;
+        textures: Object;
+        shaders: Object;
+        programs: Object;
+        samplers: Object;
+        techniques: Object;
+        materials: Object;
+        animations: Object;
+        skins: Object;
+        currentScene: Object;
+
+        buffersCount: number;
+        shaderscount: number;
+
+        scene: Scene;
+        rootUrl: string;
+        loadedBuffers: number;
+        loadedShaders: number;
+        arrayBuffers: Object;
+
+        importOnlyMeshes: boolean;
+
+        dummyNodes: Node[];
+    }
 }

Файловите разлики са ограничени, защото са твърде много
+ 1 - 1
materialsLibrary/dist/babylon.waterMaterial.js


Файловите разлики са ограничени, защото са твърде много
+ 1 - 1
materialsLibrary/dist/babylon.waterMaterial.min.js


+ 209 - 209
materialsLibrary/materials/water/water.vertex.fx

@@ -1,209 +1,209 @@
-precision highp float;
-
-// Attributes
-attribute vec3 position;
-#ifdef NORMAL
-attribute vec3 normal;
-#endif
-#ifdef UV1
-attribute vec2 uv;
-#endif
-#ifdef UV2
-attribute vec2 uv2;
-#endif
-#ifdef VERTEXCOLOR
-attribute vec4 color;
-#endif
-#ifdef BONES
-attribute vec4 matricesIndices;
-attribute vec4 matricesWeights;
-#endif
-
-// Uniforms
-
-#ifdef INSTANCES
-attribute vec4 world0;
-attribute vec4 world1;
-attribute vec4 world2;
-attribute vec4 world3;
-#else
-uniform mat4 world;
-#endif
-
-uniform mat4 view;
-uniform mat4 viewProjection;
-
-#ifdef BUMP
-varying vec2 vNormalUV;
-uniform mat4 normalMatrix;
-uniform vec2 vNormalInfos;
-#endif
-
-#ifdef BONES
-uniform mat4 mBones[BonesPerMesh];
-#endif
-
-#ifdef POINTSIZE
-uniform float pointSize;
-#endif
-
-// Output
-varying vec3 vPositionW;
-#ifdef NORMAL
-varying vec3 vNormalW;
-#endif
-
-#ifdef VERTEXCOLOR
-varying vec4 vColor;
-#endif
-
-#ifdef CLIPPLANE
-uniform vec4 vClipPlane;
-varying float fClipDistance;
-#endif
-
-#ifdef FOG
-varying float fFogDistance;
-#endif
-
-#ifdef SHADOWS
-#if defined(SPOTLIGHT0) || defined(DIRLIGHT0)
-uniform mat4 lightMatrix0;
-varying vec4 vPositionFromLight0;
-#endif
-#if defined(SPOTLIGHT1) || defined(DIRLIGHT1)
-uniform mat4 lightMatrix1;
-varying vec4 vPositionFromLight1;
-#endif
-#if defined(SPOTLIGHT2) || defined(DIRLIGHT2)
-uniform mat4 lightMatrix2;
-varying vec4 vPositionFromLight2;
-#endif
-#if defined(SPOTLIGHT3) || defined(DIRLIGHT3)
-uniform mat4 lightMatrix3;
-varying vec4 vPositionFromLight3;
-#endif
-#endif
-
-// Water uniforms
-uniform mat4 worldReflectionViewProjection;
-uniform vec2 windDirection;
-uniform float waveLength;
-uniform float time;
-uniform float windForce;
-uniform float waveHeight;
-uniform float waveSpeed;
-
-// Water varyings
-varying vec3 vPosition;
-varying vec3 vRefractionMapTexCoord;
-varying vec3 vReflectionMapTexCoord;
-
-void main(void) {
-	mat4 finalWorld;
-
-#ifdef INSTANCES
-	finalWorld = mat4(world0, world1, world2, world3);
-#else
-	finalWorld = world;
-#endif
-
-#ifdef BONES
-	mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;
-	mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;
-	mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;
-
-#ifdef BONES4
-	mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;
-	finalWorld = finalWorld * (m0 + m1 + m2 + m3);
-#else
-	finalWorld = finalWorld * (m0 + m1 + m2);
-#endif 
-
-#endif
-
-	vec4 worldPos = finalWorld * vec4(position, 1.0);
-	vPositionW = vec3(worldPos);
-
-#ifdef NORMAL
-	vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));
-#endif
-
-	// Texture coordinates
-#ifndef UV1
-	vec2 uv = vec2(0., 0.);
-#endif
-#ifndef UV2
-	vec2 uv2 = vec2(0., 0.);
-#endif
-
-#ifdef BUMP
-	if (vNormalInfos.x == 0.)
-	{
-		vNormalUV = vec2(normalMatrix * vec4((uv * 1.0) / waveLength + time * windForce * windDirection, 1.0, 0.0));
-	}
-	else
-	{
-		vNormalUV = vec2(normalMatrix * vec4((uv2 * 1.0) / waveLength + time * windForce * windDirection, 1.0, 0.0));
-	}
-#endif
-
-	// Clip plane
-#ifdef CLIPPLANE
-	fClipDistance = dot(worldPos, vClipPlane);
-#endif
-
-	// Fog
-#ifdef FOG
-	fFogDistance = (view * worldPos).z;
-#endif
-
-	// Shadows
-#ifdef SHADOWS
-#if defined(SPOTLIGHT0) || defined(DIRLIGHT0)
-	vPositionFromLight0 = lightMatrix0 * worldPos;
-#endif
-#if defined(SPOTLIGHT1) || defined(DIRLIGHT1)
-	vPositionFromLight1 = lightMatrix1 * worldPos;
-#endif
-#if defined(SPOTLIGHT2) || defined(DIRLIGHT2)
-	vPositionFromLight2 = lightMatrix2 * worldPos;
-#endif
-#if defined(SPOTLIGHT3) || defined(DIRLIGHT3)
-	vPositionFromLight3 = lightMatrix3 * worldPos;
-#endif
-#endif
-
-	// Vertex color
-#ifdef VERTEXCOLOR
-	vColor = color;
-#endif
-
-	// Point size
-#ifdef POINTSIZE
-	gl_PointSize = pointSize;
-#endif
-
-	vec3 p = position;
-	float newY = (sin(((p.x / 0.05) + time * waveSpeed * windForce) * windDirection.x) * waveHeight * 5.0)
-			   + (cos(((p.z / 0.05) + time * waveSpeed * windForce) * windDirection.y) * waveHeight * 5.0);
-	p.y += abs(newY);
-	
-	gl_Position = viewProjection * finalWorld * vec4(p, 1.0);
-
-#ifdef REFLECTION
-	worldPos = viewProjection * finalWorld * vec4(p, 1.0);
-	
-	// Water
-	vPosition = position;
-	
-	vRefractionMapTexCoord.x = 0.5 * (worldPos.w + worldPos.x);
-	vRefractionMapTexCoord.y = 0.5 * (worldPos.w + worldPos.y);
-	vRefractionMapTexCoord.z = worldPos.w;
-	
-	worldPos = worldReflectionViewProjection * vec4(position, 1.0);
-	vReflectionMapTexCoord.x = 0.5 * (worldPos.w + worldPos.x);
-	vReflectionMapTexCoord.y = 0.5 * (worldPos.w + worldPos.y);
-	vReflectionMapTexCoord.z = worldPos.w;
-#endif
-}
+precision highp float;
+
+// Attributes
+attribute vec3 position;
+#ifdef NORMAL
+attribute vec3 normal;
+#endif
+#ifdef UV1
+attribute vec2 uv;
+#endif
+#ifdef UV2
+attribute vec2 uv2;
+#endif
+#ifdef VERTEXCOLOR
+attribute vec4 color;
+#endif
+#ifdef BONES
+attribute vec4 matricesIndices;
+attribute vec4 matricesWeights;
+#endif
+
+// Uniforms
+
+#ifdef INSTANCES
+attribute vec4 world0;
+attribute vec4 world1;
+attribute vec4 world2;
+attribute vec4 world3;
+#else
+uniform mat4 world;
+#endif
+
+uniform mat4 view;
+uniform mat4 viewProjection;
+
+#ifdef BUMP
+varying vec2 vNormalUV;
+uniform mat4 normalMatrix;
+uniform vec2 vNormalInfos;
+#endif
+
+#ifdef BONES
+uniform mat4 mBones[BonesPerMesh];
+#endif
+
+#ifdef POINTSIZE
+uniform float pointSize;
+#endif
+
+// Output
+varying vec3 vPositionW;
+#ifdef NORMAL
+varying vec3 vNormalW;
+#endif
+
+#ifdef VERTEXCOLOR
+varying vec4 vColor;
+#endif
+
+#ifdef CLIPPLANE
+uniform vec4 vClipPlane;
+varying float fClipDistance;
+#endif
+
+#ifdef FOG
+varying float fFogDistance;
+#endif
+
+#ifdef SHADOWS
+#if defined(SPOTLIGHT0) || defined(DIRLIGHT0)
+uniform mat4 lightMatrix0;
+varying vec4 vPositionFromLight0;
+#endif
+#if defined(SPOTLIGHT1) || defined(DIRLIGHT1)
+uniform mat4 lightMatrix1;
+varying vec4 vPositionFromLight1;
+#endif
+#if defined(SPOTLIGHT2) || defined(DIRLIGHT2)
+uniform mat4 lightMatrix2;
+varying vec4 vPositionFromLight2;
+#endif
+#if defined(SPOTLIGHT3) || defined(DIRLIGHT3)
+uniform mat4 lightMatrix3;
+varying vec4 vPositionFromLight3;
+#endif
+#endif
+
+// Water uniforms
+uniform mat4 worldReflectionViewProjection;
+uniform vec2 windDirection;
+uniform float waveLength;
+uniform float time;
+uniform float windForce;
+uniform float waveHeight;
+uniform float waveSpeed;
+
+// Water varyings
+varying vec3 vPosition;
+varying vec3 vRefractionMapTexCoord;
+varying vec3 vReflectionMapTexCoord;
+
+void main(void) {
+	mat4 finalWorld;
+
+#ifdef INSTANCES
+	finalWorld = mat4(world0, world1, world2, world3);
+#else
+	finalWorld = world;
+#endif
+
+#ifdef BONES
+	mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;
+	mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;
+	mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;
+
+#ifdef BONES4
+	mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;
+	finalWorld = finalWorld * (m0 + m1 + m2 + m3);
+#else
+	finalWorld = finalWorld * (m0 + m1 + m2);
+#endif 
+
+#endif
+
+	vec4 worldPos = finalWorld * vec4(position, 1.0);
+	vPositionW = vec3(worldPos);
+
+#ifdef NORMAL
+	vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));
+#endif
+
+	// Texture coordinates
+#ifndef UV1
+	vec2 uv = vec2(0., 0.);
+#endif
+#ifndef UV2
+	vec2 uv2 = vec2(0., 0.);
+#endif
+
+#ifdef BUMP
+	if (vNormalInfos.x == 0.)
+	{
+		vNormalUV = vec2(normalMatrix * vec4((uv * 1.0) / waveLength + time * windForce * windDirection, 1.0, 0.0));
+	}
+	else
+	{
+		vNormalUV = vec2(normalMatrix * vec4((uv2 * 1.0) / waveLength + time * windForce * windDirection, 1.0, 0.0));
+	}
+#endif
+
+	// Clip plane
+#ifdef CLIPPLANE
+	fClipDistance = dot(worldPos, vClipPlane);
+#endif
+
+	// Fog
+#ifdef FOG
+	fFogDistance = (view * worldPos).z;
+#endif
+
+	// Shadows
+#ifdef SHADOWS
+#if defined(SPOTLIGHT0) || defined(DIRLIGHT0)
+	vPositionFromLight0 = lightMatrix0 * worldPos;
+#endif
+#if defined(SPOTLIGHT1) || defined(DIRLIGHT1)
+	vPositionFromLight1 = lightMatrix1 * worldPos;
+#endif
+#if defined(SPOTLIGHT2) || defined(DIRLIGHT2)
+	vPositionFromLight2 = lightMatrix2 * worldPos;
+#endif
+#if defined(SPOTLIGHT3) || defined(DIRLIGHT3)
+	vPositionFromLight3 = lightMatrix3 * worldPos;
+#endif
+#endif
+
+	// Vertex color
+#ifdef VERTEXCOLOR
+	vColor = color;
+#endif
+
+	// Point size
+#ifdef POINTSIZE
+	gl_PointSize = pointSize;
+#endif
+
+	vec3 p = position;
+	float newY = (sin(((p.x / 0.05) + time * waveSpeed)) * waveHeight * windDirection.x * 5.0)
+			   + (cos(((p.z / 0.05) +  time * waveSpeed)) * waveHeight * windDirection.y * 5.0);
+	p.y += abs(newY);
+	
+	gl_Position = viewProjection * finalWorld * vec4(p, 1.0);
+
+#ifdef REFLECTION
+	worldPos = viewProjection * finalWorld * vec4(p, 1.0);
+	
+	// Water
+	vPosition = position;
+	
+	vRefractionMapTexCoord.x = 0.5 * (worldPos.w + worldPos.x);
+	vRefractionMapTexCoord.y = 0.5 * (worldPos.w + worldPos.y);
+	vRefractionMapTexCoord.z = worldPos.w;
+	
+	worldPos = worldReflectionViewProjection * vec4(position, 1.0);
+	vReflectionMapTexCoord.x = 0.5 * (worldPos.w + worldPos.x);
+	vReflectionMapTexCoord.y = 0.5 * (worldPos.w + worldPos.y);
+	vReflectionMapTexCoord.z = worldPos.w;
+#endif
+}

+ 9 - 1
src/Materials/Textures/babylon.renderTargetTexture.ts

@@ -126,6 +126,10 @@
 
         public render(useCameraPostProcess?: boolean, dumpForDebug?: boolean) {
             var scene = this.getScene();
+            
+            if (this.activeCamera !== scene.activeCamera) {
+        		scene.setTransformMatrix(this.activeCamera.getViewMatrix(), this.activeCamera.getProjectionMatrix(true));
+        	}
 
             if (this._waitingRenderList) {
                 this.renderList = [];
@@ -179,6 +183,10 @@
             if (this.onAfterUnbind) {
                 this.onAfterUnbind();
             }
+            
+            if (this.activeCamera !== scene.activeCamera) {
+        		scene.setTransformMatrix(scene.activeCamera.getViewMatrix(), scene.activeCamera.getProjectionMatrix(true));
+        	}
 
             scene.resetCachedMaterial();
         }
@@ -276,4 +284,4 @@
             return serializationObject;
         }
     }
-} 
+} 

+ 1 - 1
src/Tools/babylon.sceneSerializer.ts

@@ -369,4 +369,4 @@
             return serializationObject;
         }
     }
-}
+}