Browse Source

Now writing geometry shader using webgl 1 glsl language and added hasDrawBuffersExtension check in effect.ts

Julien Moreau-Mathis 8 năm trước cách đây
mục cha
commit
ace63189e6

+ 5 - 2
src/Materials/babylon.effect.ts

@@ -378,12 +378,15 @@
                 callback(preparedSourceCode.replace("#version 300 es", ""));
                 return;
             }
+
+            var hasDrawBuffersExtension = preparedSourceCode.search(/#extension.+GL_EXT_draw_buffers.+require/) !== -1;
             
             // Remove extensions 
             // #extension GL_OES_standard_derivatives : enable
             // #extension GL_EXT_shader_texture_lod : enable
             // #extension GL_EXT_frag_depth : enable
-            var regex = /#extension.+(GL_OES_standard_derivatives|GL_EXT_shader_texture_lod|GL_EXT_frag_depth).+enable/g;
+            // #extension GL_EXT_draw_buffers : require
+            var regex = /#extension.+(GL_OES_standard_derivatives|GL_EXT_shader_texture_lod|GL_EXT_frag_depth|GL_EXT_draw_buffers).+(enable|require)/g;
             var result = preparedSourceCode.replace(regex, "");
 
             // Migrate to GLSL v300
@@ -398,7 +401,7 @@
                 result = result.replace(/textureCube\(/g, "texture(");
                 result = result.replace(/gl_FragDepthEXT/g, "gl_FragDepth");
                 result = result.replace(/gl_FragColor/g, "glFragColor");
-                result = result.replace(/void\s+?main\(/g, "out vec4 glFragColor;\nvoid main(");
+                result = result.replace(/void\s+?main\(/g, (hasDrawBuffersExtension ? "" : "out vec4 glFragColor;\n") + "void main(");
             }
             
             callback(result);

+ 0 - 9
src/Rendering/babylon.geometryBufferRenderer.ts

@@ -38,10 +38,6 @@ module BABYLON {
             this._scene = scene;
             this._ratio = ratio;
 
-            // Multiple color attachment support
-            var engine = scene.getEngine();
-            this._needsDrawBuffersExtension = engine.webGLVersion < 2 && engine.getCaps().drawBuffersExtension;
-
             // Render target
             this._createRenderTargets();
         }
@@ -60,11 +56,6 @@ module BABYLON {
             var mesh = subMesh.getMesh();
             var scene = mesh.getScene();
 
-            // Draw buffers extension
-            if (this._needsDrawBuffersExtension) {
-                defines.push("#define DRAW_BUFFERS_EXTENSION");
-            }
-
             // Alpha test
             if (material && material.needAlphaTesting()) {
                 defines.push("#define ALPHATEST");

+ 6 - 14
src/Shaders/geometry.fragment.fx

@@ -1,29 +1,21 @@
-#ifndef DRAW_BUFFERS_EXTENSION
-#version 300 es
-#else
 #extension GL_EXT_draw_buffers : require
-#endif
 
 precision highp float;
 precision highp int;
 
-#ifdef DRAW_BUFFERS_EXTENSION
-#define in varying
-#endif
-
-in vec3 vNormalV;
-in vec4 vViewPos;
+varying vec3 vNormalV;
+varying vec4 vViewPos;
 
 #ifdef POSITION
-in vec3 vPosition;
+varying vec3 vPosition;
 #endif
 
 #ifdef ALPHATEST
-in vec2 vUV;
+varying vec2 vUV;
 uniform sampler2D diffuseSampler;
 #endif
 
-#ifndef DRAW_BUFFERS_EXTENSION
+#if __VERSION__ >= 200
     layout(location = 0) out vec4 color0;
     layout(location = 1) out vec4 color1;
 
@@ -38,7 +30,7 @@ uniform sampler2D diffuseSampler;
 
 void main() {
 #ifdef ALPHATEST
-	if (texture(diffuseSampler, vUV).a < 0.4)
+	if (texture2D(diffuseSampler, vUV).a < 0.4)
 		discard;
 #endif
 

+ 10 - 19
src/Shaders/geometry.vertex.fx

@@ -1,29 +1,20 @@
-#ifndef DRAW_BUFFERS_EXTENSION
-#version 300 es
-#endif
-
 precision highp float;
 precision highp int;
 
-#include<bones300Declaration>
-#include<instances300Declaration>
-
-#ifdef DRAW_BUFFERS_EXTENSION
-#define in attribute
-#define out varying
-#endif
+#include<bonesDeclaration>
+#include<instancesDeclaration>
 
-in vec3 position;
-in vec3 normal;
+attribute vec3 position;
+attribute vec3 normal;
 
 #if defined(ALPHATEST) || defined(NEED_UV)
-out vec2 vUV;
+varying vec2 vUV;
 uniform mat4 diffuseMatrix;
 #ifdef UV1
-in vec2 uv;
+varying vec2 uv;
 #endif
 #ifdef UV2
-in vec2 uv2;
+varying vec2 uv2;
 #endif
 #endif
 
@@ -31,11 +22,11 @@ in vec2 uv2;
 uniform mat4 viewProjection;
 uniform mat4 view;
 
-out vec3 vNormalV;
-out vec4 vViewPos;
+varying vec3 vNormalV;
+varying vec4 vViewPos;
 
 #ifdef POSITION
-out vec3 vPosition;
+varying vec3 vPosition;
 #endif
 
 void main(void)