Pārlūkot izejas kodu

added shaders for geometry + fixed rendering bugs

Benjamin Guignabert 8 gadi atpakaļ
vecāks
revīzija
8d0d2791b3

+ 22 - 2
Tools/Gulp/config.json

@@ -15,7 +15,7 @@
                 "pointLight", "directionalLight", "spotLight", "animations", "actions", "sprites", "picking", "collisions",
                 "particles", "solidParticles", "additionalMeshes", "meshBuilder", "audio", "additionalTextures", "shadows",
                 "loader", "userData", "offline", "fresnel", "multiMaterial", "touchCamera", "procedural", "gamepad",
-                "additionalCameras", "postProcesses", "renderingPipeline", "additionalRenderingPipeline", "depthRenderer", "additionalPostProcesses",
+                "additionalCameras", "postProcesses", "renderingPipeline", "additionalRenderingPipeline", "depthRenderer", "geometryRenderer", "additionalPostProcesses",
                 "bones", "hdr", "polygonMesh", "csg", "lensFlares", "physics", "textureFormats", "debug", "morphTargets",
                 "colorCurves", "octrees", "simd", "vr", "virtualJoystick", "optimizations", "highlights", "assetsManager",
                 "mapTexture", "dynamicFloatArray", "serialization", "probes", "layer"
@@ -376,6 +376,7 @@
             "files": [
                 "../../src/Materials/Textures/babylon.cubeTexture.js",
                 "../../src/Materials/Textures/babylon.renderTargetTexture.js",
+                "../../src/Materials/Textures/babylon.multiRenderTarget.js",
                 "../../src/Materials/Textures/babylon.mirrorTexture.js",
                 "../../src/Materials/Textures/babylon.refractionTexture.js",
                 "../../src/Materials/Textures/babylon.dynamicTexture.js",
@@ -514,7 +515,26 @@
                 "instancesVertex",
                 "bonesVertex"
             ]
-        },      
+        },
+        "geometryRenderer" : 
+        {
+            "files": [
+                "../../src/Rendering/babylon.geometryRenderer.js"
+            ],
+            "dependUpon" : [
+                "core"
+            ], 
+            "shaders" : [
+                "geometry.vertex",
+                "geometry.fragment"
+            ],
+            "shaderIncludes": [
+                "bonesDeclaration",
+                "instancesDeclaration",
+                "instancesVertex",
+                "bonesVertex"
+            ]
+        },            
         "postProcesses" : 
         {
             "files": [

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 4048 - 4044
dist/preview release/babylon.d.ts


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 4048 - 4044
dist/preview release/babylon.module.d.ts


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

@@ -12,6 +12,10 @@ module BABYLON {
         private _doNotChangeAspectRatio: boolean;
         private _size: number;
 
+        private _shouldRender(): boolean {
+            return true;
+        }
+
         public customRenderFunction: (opaqueSubMeshes: SmartArray<SubMesh>, transparentSubMeshes: SmartArray<SubMesh>, alphaTestSubMeshes: SmartArray<SubMesh>, beforeTransparents?: () => void) => void;
 
         constructor(name: string, size: any, count: number, scene: Scene, options?: any) {
@@ -36,6 +40,9 @@ module BABYLON {
                 type: type,
                 textureCount: count
             });
+
+            // Rendering groups
+            this._renderingManager = new RenderingManager(scene);
         }
 
         public render(useCameraPostProcess?: boolean, dumpForDebug?: boolean) {

+ 1 - 1
src/Materials/babylon.effect.ts

@@ -352,7 +352,7 @@
 
             // Already converted
             if (preparedSourceCode.indexOf("#version 3") !== -1) {
-                callback(preparedSourceCode);
+                callback(preparedSourceCode.replace("#version 300 es", ""));
                 return;
             }
             

+ 11 - 50
src/Rendering/babylon.geometryRenderer.ts

@@ -1,7 +1,7 @@
 module BABYLON {
     export class GeometryRenderer {
         private _scene: Scene;
-        private _multiRenderTarger: MultiRenderTarget;
+        private _multiRenderTarget: MultiRenderTarget;
         private _effect: Effect;
 
         private _viewMatrix = Matrix.Zero();
@@ -16,7 +16,7 @@ module BABYLON {
             var engine = scene.getEngine();
 
             // Render target
-            this._multiRenderTarger = new MultiRenderTarget("gBuffer", { width: engine.getRenderWidth(), height: engine.getRenderHeight() }, 4, this._scene);
+            this._multiRenderTarget = new MultiRenderTarget("gBuffer", { width: engine.getRenderWidth(), height: engine.getRenderHeight() }, 2, this._scene);
             
             // Custom render function
             var renderSubMesh = (subMesh: SubMesh): void => {
@@ -45,25 +45,13 @@ 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));
                 }
             };
 
-            this._multiRenderTarger.customRenderFunction = (opaqueSubMeshes: SmartArray<SubMesh>, alphaTestSubMeshes: SmartArray<SubMesh>): void => {
+            this._multiRenderTarget.customRenderFunction = (opaqueSubMeshes: SmartArray<SubMesh>, alphaTestSubMeshes: SmartArray<SubMesh>): void => {
                 var index;
 
                 for (index = 0; index < opaqueSubMeshes.length; index++) {
@@ -91,37 +79,10 @@ module BABYLON {
             var mesh = subMesh.getMesh();
             var scene = mesh.getScene();
 
-            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");
-            }
+            // if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
+            //     attribs.push(VertexBuffer.UVKind);
+            //     defines.push("#define UV1");
+            // }
 
             // Get correct effect      
             var join = defines.join("\n");
@@ -129,20 +90,20 @@ module BABYLON {
                 this._cachedDefines = join;
                 this._effect = this._scene.getEngine().createEffect("geometry",
                     attribs,
-                    ["world", "mBones", "viewProjection", "diffuseMatrix", "far"],
-                    ["diffuseSampler"], join);
+                    ["world", "viewProjection", "far"],
+                    [], join);
             }
 
             return this._effect.isReady();
         }
 
         public getGBuffer(): MultiRenderTarget {
-            return this._multiRenderTarger;
+            return this._multiRenderTarget;
         }
 
         // Methods
         public dispose(): void {
-            this.getGBuffer.dispose();
+            this.getGBuffer().dispose();
         }
     }
 } 

+ 15 - 0
src/Shaders/geometry.fragment.fx

@@ -0,0 +1,15 @@
+#version 300 es
+
+precision highp float;
+precision highp int;
+
+layout(location = 0) out vec4 color0;
+layout(location = 1) out vec4 color1;
+
+uniform float far;
+
+void main() {
+    float depth = (gl_FragCoord.z / gl_FragCoord.w) / far;
+    color0 = vec4(depth, depth * depth, 0.0, 1.0);
+    color1 = vec4(1.0, 0.0, 0.0, 1.0);
+}

+ 15 - 0
src/Shaders/geometry.vertex.fx

@@ -0,0 +1,15 @@
+#version 300 es
+
+precision highp float;
+precision highp int;
+
+in vec3 position;
+
+// Uniform
+uniform mat4 viewProjection;
+uniform mat4 world;
+
+void main(void)
+{
+	gl_Position = viewProjection * world * vec4(position, 1.0);
+}

+ 25 - 0
src/babylon.scene.ts

@@ -706,6 +706,7 @@
         private _debugLayer: DebugLayer;
 
         private _depthRenderer: DepthRenderer;
+        private _geometryRenderer: GeometryRenderer;
 
         private _uniqueIdCounter = 0;
 
@@ -2911,6 +2912,11 @@
                 this._renderTargets.push(this._depthRenderer.getDepthMap());
             }
 
+            // Geometry renderer
+            if (this._geometryRenderer) {
+                this._renderTargets.push(this._geometryRenderer.getGBuffer());
+            }
+
             // RenderPipeline
             if (this._postProcessRenderPipelineManager) {
                 this._postProcessRenderPipelineManager.update();
@@ -3105,6 +3111,25 @@
             this._depthRenderer = null;
         }
 
+        public enableGeometryRenderer(): GeometryRenderer {
+            if (this._geometryRenderer) {
+                return this._geometryRenderer;
+            }
+
+            this._geometryRenderer = new GeometryRenderer(this);
+
+            return this._geometryRenderer;
+        }
+
+        public disableGeometryRenderer(): void {
+            if (!this._geometryRenderer) {
+                return;
+            }
+
+            this._geometryRenderer.dispose();
+            this._geometryRenderer = null;
+        }
+
         public freezeMaterials(): void {
             for (var i = 0; i < this.materials.length; i++) {
                 this.materials[i].freeze();