Explorar el Código

Adding multiple render target include to fit glFragData identifier including array size

Julien Moreau-Mathis hace 8 años
padre
commit
0e9b42764c

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

@@ -401,6 +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(/gl_FragData/g, "glFragData");
                 result = result.replace(/void\s+?main\(/g, (hasDrawBuffersExtension ? "" : "out vec4 glFragColor;\n") + "void main(");
             }
             

+ 3 - 1
src/Rendering/babylon.geometryBufferRenderer.ts

@@ -104,7 +104,9 @@ module BABYLON {
                 this._effect = this._scene.getEngine().createEffect("geometry",
                     attribs,
                     ["world", "mBones", "viewProjection", "diffuseMatrix", "view"],
-                    ["diffuseSampler"], join);
+                    ["diffuseSampler"], join,
+                    null, null, null,
+                    { buffersCount: this._enablePosition ? 3 : 2 });
             }
 
             return this._effect.isReady();

+ 3 - 0
src/Shaders/ShadersInclude/mrtFragmentDeclaration.fx

@@ -0,0 +1,3 @@
+#if __VERSION__ >= 200
+layout(location = 0) out vec4 glFragData[{X}];
+#endif

+ 7 - 13
src/Shaders/geometry.fragment.fx

@@ -15,17 +15,10 @@ varying vec2 vUV;
 uniform sampler2D diffuseSampler;
 #endif
 
-#if __VERSION__ >= 200
-    layout(location = 0) out vec4 color0;
-    layout(location = 1) out vec4 color1;
-
-    #ifdef POSITION
-    layout(location = 2) out vec4 color2;
-    #endif
+#ifdef POSITION
+#include<mrtFragmentDeclaration>[3]
 #else
-    #define color0 gl_FragData[0]
-    #define color1 gl_FragData[1]
-    #define color2 gl_FragData[2]
+#include<mrtFragmentDeclaration>[2]
 #endif
 
 void main() {
@@ -34,11 +27,12 @@ void main() {
 		discard;
 #endif
 
-    color0 = vec4(vViewPos.z / vViewPos.w, 0.0, 0.0, 1.0);
-    color1 = vec4(normalize(vNormalV), 1.0);
+    gl_FragData[0] = vec4(vViewPos.z / vViewPos.w, 0.0, 0.0, 1.0);
+    //color0 = vec4(vViewPos.z / vViewPos.w, 0.0, 0.0, 1.0);
+    gl_FragData[1] = vec4(normalize(vNormalV), 1.0);
     //color2 = vec4(vPositionV, 1.0);
 
     #ifdef POSITION
-    color2 = vec4(vPosition, 1.0);
+    gl_FragData[2] = vec4(vPosition, 1.0);
     #endif
 }