Benjamin Guignabert 8 лет назад
Родитель
Сommit
670c62ac61

Разница между файлами не показана из-за своего большого размера
+ 4001 - 4026
dist/preview release/babylon.d.ts


Разница между файлами не показана из-за своего большого размера
+ 4001 - 4026
dist/preview release/babylon.module.d.ts


+ 7 - 4
src/Materials/Textures/babylon.multiRenderTarget.ts

@@ -66,17 +66,19 @@ module BABYLON {
 
             this._webGLTextures = scene.getEngine().createMultipleRenderTarget(size, this._renderTargetOptions);
 
+            this._createInternalTextures();
+        }
+
+        private _createInternalTextures(): void {
             this._textures = [];
             for (var i = 0; i < this._webGLTextures.length; i++) {
-                var texture = new BABYLON.Texture(null, scene);
+                var texture = new BABYLON.Texture(null, this.getScene());
                 texture._texture = this._webGLTextures[i];
                 this._textures.push(texture);
             }
 
             // Keeps references to frame buffer and stencil/depth buffer
             this._texture = this._webGLTextures[0];
-
-            // this.resize(size);
         }
 
         public get samples(): number {
@@ -96,6 +98,7 @@ module BABYLON {
         public resize(size: any) {
             this.releaseInternalTextures();
             this._webGLTextures = this.getScene().getEngine().createMultipleRenderTarget(size, this._renderTargetOptions);
+            this._createInternalTextures();
         }
 
         public dispose(): void {
@@ -104,7 +107,7 @@ module BABYLON {
             super.dispose();
         }
 
-        private releaseInternalTextures(): void {
+        public releaseInternalTextures(): void {
             for (var i = this._webGLTextures.length - 1; i >= 0; i--) {
                 if (this._webGLTextures[i] !== undefined) {
                     this.getScene().getEngine().releaseInternalTexture(this._webGLTextures[i]);

+ 1 - 20
src/PostProcess/babylon.ssaoRenderingPipeline.ts

@@ -101,8 +101,7 @@
             // Set up assets
             this._createRandomTexture();
             this._depthTexture = scene.enableGeometryRenderer().getGBuffer().depthTexture; 
-            // this._depthTexture = scene.enableGeometryRenderer().getGBuffer().textures[0]; // Force depth renderer "on"
-            this._normalTexture = scene.enableGeometryRenderer().getGBuffer().textures[1]; // Force depth renderer "on"
+            this._normalTexture = scene.enableGeometryRenderer().getGBuffer().textures[1];
 
             var ssaoRatio = ratio.ssaoRatio || ratio;
             var combineRatio = ratio.combineRatio || ratio;
@@ -224,24 +223,6 @@
 
         private _createSSAOPostProcess(ratio: number): void {
             var numSamples = this.samples;
-/*            var sampleSphere = [
-                0.5381, 0.1856, 0.4319,
-                0.1379, 0.2486, 0.4430,
-                0.3371, 0.5679, 0.0057,
-                -0.6999, -0.0451, 0.0019,
-                0.0689, -0.1598, 0.8547,
-                0.0560, 0.0069, 0.1843,
-                -0.0146, 0.1402, 0.0762,
-                0.0100, -0.1924, 0.0344,
-                -0.3577, -0.5301, 0.4358,
-                -0.3169, 0.1063, 0.0158,
-                0.0103, -0.5869, 0.0046,
-                -0.0897, -0.4940, 0.3287,
-                0.7119, -0.0154, 0.0918,
-                -0.0533, 0.0596, 0.5411,
-                0.0352, -0.0631, 0.5460,
-                -0.4776, 0.2847, 0.0271
-            ];*/
 
             var sampleSphere = this.generateHemisphere();
             var samplesFactor = 1.0 / numSamples;

+ 58 - 5
src/Rendering/babylon.geometryRenderer.ts

@@ -17,6 +17,12 @@ module BABYLON {
 
             // Render target
             this._multiRenderTarget = new MultiRenderTarget("gBuffer", { width: engine.getRenderWidth(), height: engine.getRenderHeight() }, 2, this._scene, { generateMipMaps : true, generateDepthTexture: true });
+            this._multiRenderTarget.wrapU = Texture.CLAMP_ADDRESSMODE;
+            this._multiRenderTarget.wrapV = Texture.CLAMP_ADDRESSMODE;
+            this._multiRenderTarget.refreshRate = 1;
+            this._multiRenderTarget.renderParticles = false;
+            this._multiRenderTarget.renderList = null;
+            
             // set default depth value to 1.0 (far away)
             this._multiRenderTarget.onClearObservable.add((engine: Engine) => {
                 engine.clear(new Color4(1.0, 1.0, 1.0, 1.0), true, true, true);
@@ -50,6 +56,18 @@ module BABYLON {
 
                     this._effect.setFloat("far", scene.activeCamera.maxZ);
 
+                    // Alpha test
+                    if (material && material.needAlphaTesting()) {
+                        var alphaTexture = material.getAlphaTestTexture();
+                        this._effect.setTexture("diffuseSampler", alphaTexture);
+                        this._effect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
+                    }
+
+                    // Bones
+                    if (mesh.useBones && mesh.computeBonesUsingShaders) {
+                        this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
+                    }
+
                     // Draw
                     mesh._processRendering(subMesh, this._effect, Material.TriangleFillMode, batch, hardwareInstancedRendering,
                         (isInstance, world) => this._effect.setMatrix("world", world));
@@ -64,8 +82,7 @@ module BABYLON {
                 }
 
                 for (index = 0; index < alphaTestSubMeshes.length; index++) {
-                    // Cannot render alpha meshes this way
-                    // renderSubMesh(alphaTestSubMeshes.data[index]);
+                    renderSubMesh(alphaTestSubMeshes.data[index]);
                 }
             };
 
@@ -75,7 +92,7 @@ module BABYLON {
         public isReady(subMesh: SubMesh, useInstances: boolean): boolean {
             var material: any = subMesh.getMaterial();
 
-            if (material && (material.disableDepthWrite || material.needAlphaTesting())) {
+            if (material && material.disableDepthWrite) {
                 return false;
             }
 
@@ -86,14 +103,50 @@ module BABYLON {
             var mesh = subMesh.getMesh();
             var scene = mesh.getScene();
 
+            // Alpha test
+            if (material && material.needAlphaTesting()) {
+                defines.push("#define ALPHATEST");
+                if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
+                    attribs.push(VertexBuffer.UVKind);
+                    defines.push("#define UV1");
+                }
+                if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind)) {
+                    attribs.push(VertexBuffer.UV2Kind);
+                    defines.push("#define UV2");
+                }
+            }
+
+            // Bones
+            if (mesh.useBones && mesh.computeBonesUsingShaders) {
+                attribs.push(VertexBuffer.MatricesIndicesKind);
+                attribs.push(VertexBuffer.MatricesWeightsKind);
+                if (mesh.numBoneInfluencers > 4) {
+                    attribs.push(VertexBuffer.MatricesIndicesExtraKind);
+                    attribs.push(VertexBuffer.MatricesWeightsExtraKind);
+                }
+                defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
+                defines.push("#define BonesPerMesh " + (mesh.skeleton.bones.length + 1));
+            } else {
+                defines.push("#define NUM_BONE_INFLUENCERS 0");
+            }
+
+            // Instances
+            if (useInstances) {
+                defines.push("#define INSTANCES");
+                attribs.push("world0");
+                attribs.push("world1");
+                attribs.push("world2");
+                attribs.push("world3");
+            }
+
             // Get correct effect      
             var join = defines.join("\n");
             if (this._cachedDefines !== join) {
                 this._cachedDefines = join;
                 this._effect = this._scene.getEngine().createEffect("geometry",
                     attribs,
-                    ["world", "viewProjection", "view", "far"],
-                    [], join);
+                    ["world", "mBones", "viewProjection", "diffuseMatrix", "view", "far"],
+                    ["diffuseSampler"], join);
             }
 
             return this._effect.isReady();

+ 10 - 1
src/Shaders/geometry.fragment.fx

@@ -4,7 +4,11 @@ precision highp float;
 precision highp int;
 
 in vec3 vNormalV;
-//in vec3 vPositionV;
+
+#ifdef ALPHATEST
+in vec2 vUV;
+uniform sampler2D diffuseSampler;
+#endif
 
 layout(location = 0) out vec4 color0;
 layout(location = 1) out vec4 color1;
@@ -12,6 +16,11 @@ layout(location = 1) out vec4 color1;
 uniform float far;
 
 void main() {
+#ifdef ALPHATEST
+	if (texture(diffuseSampler, vUV).a < 0.4)
+		discard;
+#endif
+
     float depth = (gl_FragCoord.z / gl_FragCoord.w) / far;
     color0 = vec4(depth, depth * depth, 0.0, 1.0);
     color1 = vec4(normalize(vNormalV), 1.0);

+ 29 - 3
src/Shaders/geometry.vertex.fx

@@ -3,18 +3,44 @@
 precision highp float;
 precision highp int;
 
+#include<bonesDeclaration>
+#include<instancesDeclaration>
+
 in vec3 position;
 in vec3 normal;
 
+#if defined(ALPHATEST) || defined(NEED_UV)
+out vec2 vUV;
+uniform mat4 diffuseMatrix;
+#ifdef UV1
+in vec2 uv;
+#endif
+#ifdef UV2
+in vec2 uv2;
+#endif
+#endif
+
 // Uniform
 uniform mat4 viewProjection;
-uniform mat4 world;
 uniform mat4 view;
 
 out vec3 vNormalV;
 
 void main(void)
 {
-	vNormalV = normalize(vec3((view * world) * vec4(normal, 0.0)));
-	gl_Position = viewProjection * world * vec4(position, 1.0);
+#include<instancesVertex>
+
+#include<bonesVertex>
+
+	vNormalV = normalize(vec3((view * finalWorld) * vec4(normal, 0.0)));
+	gl_Position = viewProjection * finalWorld * vec4(position, 1.0);
+
+#if defined(ALPHATEST) || defined(BASIC_RENDER)
+#ifdef UV1
+	vUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));
+#endif
+#ifdef UV2
+	vUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));
+#endif
+#endif
 }