Jogamp
tegra2: split fragment shaders into two (a - 1st pass, b - 2nd pass) ; disabled discard
authorRami Santina <rami.santina@gmail.com>
Sun, 2 Oct 2011 00:35:46 +0000 (02:35 +0200)
committerSven Gothel <sgothel@jausoft.com>
Sun, 2 Oct 2011 00:35:46 +0000 (02:35 +0200)
- 1st pass (a) and 2nd pass (b), split at branch.
- all include are on one level.
- disabled discard, as it seems to be problematic

Todo:
 - verify discard / pass-split on tegra2
 - refect second pass usage (b) in implementation

src/jogl/classes/jogamp/graph/curve/opengl/shader/attributes.glsl
src/jogl/classes/jogamp/graph/curve/opengl/shader/consts.glsl
src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2.fp
src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-es2.vp
src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-sp-xxx.vp
src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01a-xxx.fp [new file with mode: 0644]
src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01b-xxx.fp [moved from src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-xxx.fp with 60% similarity]
src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-es2.fp
src/jogl/classes/jogamp/graph/curve/opengl/shader/precision.glsl [deleted file]
src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl
src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl

index c8c076b..108247c 100644 (file)
@@ -2,8 +2,6 @@
 #ifndef attributes_glsl
 #define attributes_glsl
 
-#include precision.glsl
-
 // attribute vec3    gca_Vertices;
 attribute vec4    gca_Vertices;
 attribute vec2    gca_TexCoords;
index c399f0f..58c4fe5 100644 (file)
@@ -2,8 +2,6 @@
 #ifndef consts_glsl
 #define consts_glsl
 
-#include precision.glsl
-
 const   int     MAX_TEXTURE_UNITS = 8; // <= gl_MaxTextureImageUnits 
 // const   int     MAX_LIGHTS = 8; 
 
index 94e62c0..adf2c62 100644 (file)
@@ -6,5 +6,9 @@
 // #extension OES_standard_derivatives : require
 #extension GL_OES_standard_derivatives : enable
 
+precision mediump float;
+precision mediump int;
+precision mediump sampler2D;
+
 #include curverenderer01-xxx.fp
 
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01a-xxx.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01a-xxx.fp
new file mode 100644 (file)
index 0000000..fba2edb
--- /dev/null
@@ -0,0 +1,53 @@
+//Copyright 2010 JogAmp Community. All rights reserved.
+
+#include uniforms.glsl
+#include varyings.glsl
+
+const vec3 b_color = vec3(1.0, 1.0, 1.0);
+const vec4 tex_weights = vec4(0.075, 0.06, 0.045, 0.025);
+
+void main (void)
+{
+    vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
+    vec3 c = gcu_ColorStatic.rgb;
+    
+    float alpha = 0.0;
+    
+    if((gcv_TexCoord.x == 0.0) && (gcv_TexCoord.y == 0.0)) {
+         alpha = gcu_Alpha;
+    }
+    else if ((gcv_TexCoord.x > 0.0) && (rtex.y > 0.0 || rtex.x == 1.0)) {
+        vec2 dtx = dFdx(rtex);
+        vec2 dty = dFdy(rtex);
+          
+        rtex.y -= 0.1;
+          
+        if(rtex.y < 0.0) {
+            /** discard freezes NV tegra2 compiler (TODO: dbl check)
+            if(gcv_TexCoord.y < 0.0) {
+                discard;
+            } else {
+                rtex.y = 0.0;
+            }*/
+            rtex.y = 0.0;
+        }
+          
+        vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x));
+        float position = rtex.y - (rtex.x * (1.0 - rtex.x));
+        float d = position/(length(f));
+
+        float a = (0.5 - d * sign(gcv_TexCoord.y));  
+        
+        if (a >= 1.0)  { 
+            alpha = gcu_Alpha;
+        } else if (a <= 0.0) {
+            // discard; // freezes NV tegra2 compiler (TODO: dbl check)
+            alpha = 0.0;
+        } else {           
+            alpha = gcu_Alpha * a;
+            // ?? mix(b_color,gcu_ColorStatic.rgb, a);
+        }
+    }
+    
+    gl_FragColor = vec4(c, alpha);
+}
@@ -2,6 +2,7 @@
 
 #include uniforms.glsl
 #include varyings.glsl
+#include consts.glsl
 
 const vec3 b_color = vec3(1.0, 1.0, 1.0);
 const vec4 tex_weights = vec4(0.075, 0.06, 0.045, 0.025);
@@ -10,22 +11,14 @@ void main (void)
 {
     vec2 rtex = vec2(abs(gcv_TexCoord.x),abs(gcv_TexCoord.y));
     vec3 c = gcu_ColorStatic.rgb;
-    
+
     float alpha = 0.0;
     
-    if((gcv_TexCoord.x == 0.0) && (gcv_TexCoord.y == 0.0)) {
-         alpha = gcu_Alpha;
-    }
-    else if((gcv_TexCoord.x >= 5.0)) {
         vec2 dfx = dFdx(gcv_TexCoord);
         vec2 dfy = dFdy(gcv_TexCoord);
         
-        vec2 size;
-        //#if __VERSION__ < 130
-            size = 1.0/gcu_TextureSize;
-        //#else
-        //    size = 1.0/textureSize(gcu_TextureUnit,0);
-        //#endif
+        vec2 size = 1.0/gcu_TextureSize;
+
         rtex -= 5.0;
         vec4 t = texture2D(gcu_TextureUnit, rtex)* 0.18;
 
@@ -49,43 +42,12 @@ void main (void)
         t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(0, 1)))*tex_weights.w;
         t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(0, 1)))*tex_weights.w;
         
+        /** discard freezes NV tegra2 compiler (TODO: dbl check)
         if(t.w == 0.0){
             discard;
-        }
+        } */
         
         c = t.xyz;
         alpha = gcu_Alpha * t.w;
-    }
-    ///////////////////////////////////////////////////////////
-    else if ((gcv_TexCoord.x > 0.0) && (rtex.y > 0.0 || rtex.x == 1.0)) {
-        vec2 dtx = dFdx(rtex);
-        vec2 dty = dFdy(rtex);
-          
-        rtex.y -= 0.1;
-          
-        if(rtex.y < 0.0) {
-            if(gcv_TexCoord.y < 0.0) {
-                discard;
-            } else {
-                rtex.y = 0.0;
-            }
-        }
-          
-        vec2 f = vec2((dtx.y - dtx.x + 2.0*rtex.x*dtx.x), (dty.y - dty.x + 2.0*rtex.x*dty.x));
-        float position = rtex.y - (rtex.x * (1.0 - rtex.x));
-        float d = position/(length(f));
-
-        float a = (0.5 - d * sign(gcv_TexCoord.y));  
-        
-        if (a >= 1.0)  { 
-            alpha = gcu_Alpha;
-        } else if (a <= 0.0) {
-            discard;
-        } else {           
-            alpha = gcu_Alpha * a;
-            // ?? mix(b_color,gcu_ColorStatic.rgb, a);
-        }
-    }
-    
-    gl_FragColor = vec4(c, alpha);
+        gl_FragColor = vec4(c, alpha);
 }
index 80702d7..9a21287 100644 (file)
@@ -6,5 +6,9 @@
 // #extension OES_standard_derivatives : require
 #extension GL_OES_standard_derivatives : enable
 
+precision mediump float;
+precision mediump int;
+precision mediump sampler2D;
+
 #include curverenderer02-xxx.fp
 
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/precision.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/precision.glsl
deleted file mode 100644 (file)
index 9924bd7..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef precision_glsl
-#define precision_glsl
-
-#ifdef GL_ES
-  precision mediump float;
-  precision mediump int;
-  precision mediump sampler2D;
-#endif
-
-#endif // precision_glsl
index 5d11773..9d8ea75 100644 (file)
@@ -2,10 +2,6 @@
 #ifndef uniforms_glsl
 #define uniforms_glsl
 
-#include precision.glsl
-
-// #include consts.glsl
-
 uniform mat4    gcu_PMVMatrix[3]; // P, Mv, and Mvi
 uniform vec3    gcu_ColorStatic;
 uniform float   gcu_Alpha;
index adb40ad..7a9bc5a 100644 (file)
@@ -2,10 +2,6 @@
 #ifndef varyings_glsl
 #define varyings_glsl
 
-#include precision.glsl
-
-#include consts.glsl
-
 //varying vec4    gcv_FrontColor;
 varying vec2    gcv_TexCoord;
 
http://JogAmp.org git info: FAQ, tutorial and man pages.