From a095b7da968533120306ff9ef019685b6698272c Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 4 Oct 2011 02:48:22 +0200 Subject: Graph Shader Simplification, 'a'/'b' redefined; GraphUI 2-pass demo; Graph Shader Simplification - remove enable factor and 2nd 'discard' branch - use build-in 'max'/'clamp' functions, supposed to be faster Graph Shader 'a'/'b' redefined - 'a' is 1-pass shader only - 'b' is 2-pass incl. (1st pass + 2nd pass) - Works well on ARM Mali-400 MP (Galaxy S2). - Doesn't work on NV tegra2 (P1202: Texture's gl states do not match with shader's), however 2-pass on mobile seems to be overkill for now. We may create a workaround (switch shader ..). GraphUI 2-pass demo; - Propagate renderModes and texSize to UIShape's render(..) - TODO: Remove GL dependency in UIShape, maybe use a callback or visitor model - Adding GarpUI 2-pass launcher (Android and Standalone) --- .../graph/curve/opengl/RegionRendererImpl01.java | 11 +-- .../jogamp/graph/curve/opengl/shader/consts.glsl | 8 -- .../curve/opengl/shader/curverenderer01a-xxx.fp | 47 ++++------ .../curve/opengl/shader/curverenderer01b-xxx.fp | 99 ++++++++++++++-------- .../curve/opengl/shader/curverenderer02-es2.fp | 14 --- .../curve/opengl/shader/curverenderer02-gl2.fp | 6 -- .../curve/opengl/shader/curverenderer02-xxx.fp | 93 -------------------- .../curve/opengl/shader/curverenderer02a-es2.fp | 14 +++ .../curve/opengl/shader/curverenderer02a-gl2.fp | 6 ++ .../curve/opengl/shader/curverenderer02a-xxx.fp | 48 +++++++++++ .../curve/opengl/shader/curverenderer02b-es2.fp | 14 +++ .../curve/opengl/shader/curverenderer02b-gl2.fp | 6 ++ .../curve/opengl/shader/curverenderer02b-xxx.fp | 88 +++++++++++++++++++ .../jogamp/graph/curve/opengl/shader/uniforms.glsl | 2 + 14 files changed, 263 insertions(+), 193 deletions(-) delete mode 100644 src/jogl/classes/jogamp/graph/curve/opengl/shader/consts.glsl delete mode 100644 src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-es2.fp delete mode 100644 src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-gl2.fp delete mode 100644 src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-xxx.fp create mode 100644 src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02a-es2.fp create mode 100644 src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02a-gl2.fp create mode 100644 src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02a-xxx.fp create mode 100644 src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02b-es2.fp create mode 100644 src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02b-gl2.fp create mode 100644 src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02b-xxx.fp (limited to 'src/jogl/classes/jogamp/graph/curve') diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java b/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java index 0218c729a..0217a6369 100755 --- a/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/RegionRendererImpl01.java @@ -46,16 +46,11 @@ public class RegionRendererImpl01 extends RegionRenderer { } - /** - * FIXME: 2nd pass shader ! - */ @Override protected String getFragmentShaderName(GL2ES2 gl) { - if(Region.isNonUniformWeight(renderModes)){ - // FIXME: split shader ! - return "curverenderer02" + getShaderGLVersionSuffix(gl); - } - return "curverenderer01a" + getShaderGLVersionSuffix(gl); + final String type = Region.isNonUniformWeight(renderModes) ? "02" : "01" ; + final String pass = Region.isVBAA(renderModes) ? "b" : "a" ; + return "curverenderer" + type + pass + getShaderGLVersionSuffix(gl); } protected boolean initShaderProgram(GL2ES2 gl) { diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/consts.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/consts.glsl deleted file mode 100644 index 58c4fe50c..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/consts.glsl +++ /dev/null @@ -1,8 +0,0 @@ - -#ifndef consts_glsl -#define consts_glsl - -const int MAX_TEXTURE_UNITS = 8; // <= gl_MaxTextureImageUnits -// const int MAX_LIGHTS = 8; - -#endif // consts_glsl 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 index b51ec5808..f3a88adef 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01a-xxx.fp +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01a-xxx.fp @@ -1,51 +1,40 @@ //Copyright 2010 JogAmp Community. All rights reserved. +// +// 1-pass shader w/o weight +// + #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; - float enable = 1.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) { - if(gcv_TexCoord.y < 0.0) { - // discard; // freezes NV tegra2 compiler (TODO: dbl check) - enable = 0.0; - } 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 * enable; - } else if (a <= 0.0) { - // discard; // freezes NV tegra2 compiler (TODO: dbl check) + if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) { + // discard; // freezes NV tegra2 compiler alpha = 0.0; - } else { - alpha = gcu_Alpha * a * enable; - // ?? mix(b_color,gcu_ColorStatic.rgb, a); + } else { + rtex.y = max(rtex.y, 0.0); + + vec2 dtx = dFdx(rtex); + vec2 dty = dFdy(rtex); + + 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)); + + // FIXME: will we ever set gcu_Alpha != 1.0 ? If not, a==alpha! + float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0); + alpha = gcu_Alpha * a; } } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01b-xxx.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01b-xxx.fp index 4bef33dbe..879e41e4c 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01b-xxx.fp +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01b-xxx.fp @@ -1,10 +1,12 @@ //Copyright 2010 JogAmp Community. All rights reserved. +// +// 2-pass shader w/o weight +// + #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); void main (void) @@ -13,41 +15,68 @@ void main (void) vec3 c = gcu_ColorStatic.rgb; float alpha = 0.0; + float enable = 1.0; - vec2 dfx = dFdx(gcv_TexCoord); - vec2 dfy = dFdy(gcv_TexCoord); - - vec2 size = 1.0/gcu_TextureSize; + 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 = 1.0/gcu_TextureSize; - rtex -= 5.0; - vec4 t = texture2D(gcu_TextureUnit, rtex)* 0.18; + rtex -= 5.0; + vec4 t = texture2D(gcu_TextureUnit, rtex)* 0.18; + + t += texture2D(gcu_TextureUnit, rtex + size*(vec2(1, 0)))*tex_weights.x; + t += texture2D(gcu_TextureUnit, rtex - size*(vec2(1, 0)))*tex_weights.x; + t += texture2D(gcu_TextureUnit, rtex + size*(vec2(0, 1)))*tex_weights.x; + t += texture2D(gcu_TextureUnit, rtex - size*(vec2(0, 1)))*tex_weights.x; + + t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(1, 0)))*tex_weights.y; + t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(1, 0)))*tex_weights.y; + t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(0, 1)))*tex_weights.y; + t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(0, 1)))*tex_weights.y; + + t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(1, 0)))*tex_weights.z; + t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(1, 0)))*tex_weights.z; + t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(0, 1)))*tex_weights.z; + t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(0, 1)))*tex_weights.z; + + t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(1, 0)))*tex_weights.w; + t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(1, 0)))*tex_weights.w; + 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 + 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)) { + rtex.y -= 0.1; + + if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) { + // discard; // freezes NV tegra2 compiler + alpha = 0.0; + } else { + rtex.y = max(rtex.y, 0.0); + + vec2 dtx = dFdx(rtex); + vec2 dty = dFdy(rtex); + + 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)); + + // FIXME: will we ever set gcu_Alpha != 1.0 ? If not, a==alpha! + float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0); + alpha = gcu_Alpha * a; + } + } - t += texture2D(gcu_TextureUnit, rtex + size*(vec2(1, 0)))*tex_weights.x; - t += texture2D(gcu_TextureUnit, rtex - size*(vec2(1, 0)))*tex_weights.x; - t += texture2D(gcu_TextureUnit, rtex + size*(vec2(0, 1)))*tex_weights.x; - t += texture2D(gcu_TextureUnit, rtex - size*(vec2(0, 1)))*tex_weights.x; - - t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(1, 0)))*tex_weights.y; - t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(1, 0)))*tex_weights.y; - t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(0, 1)))*tex_weights.y; - t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(0, 1)))*tex_weights.y; - - t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(1, 0)))*tex_weights.z; - t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(1, 0)))*tex_weights.z; - t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(0, 1)))*tex_weights.z; - t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(0, 1)))*tex_weights.z; - - t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(1, 0)))*tex_weights.w; - t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(1, 0)))*tex_weights.w; - 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; gl_FragColor = vec4(c, alpha); } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-es2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-es2.fp deleted file mode 100644 index 9a2128765..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-es2.fp +++ /dev/null @@ -1,14 +0,0 @@ -//Copyright 2010 JogAmp Community. All rights reserved. - -#version 100 - -// we require dFdx/dFdy -// #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/curverenderer02-gl2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-gl2.fp deleted file mode 100644 index d7fe31a08..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-gl2.fp +++ /dev/null @@ -1,6 +0,0 @@ -//Copyright 2010 JogAmp Community. All rights reserved. - -#version 110 - -#include curverenderer02-xxx.fp - diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-xxx.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-xxx.fp deleted file mode 100644 index 4f66cb41e..000000000 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02-xxx.fp +++ /dev/null @@ -1,93 +0,0 @@ -//Copyright 2010 JogAmp Community. All rights reserved. - -#include uniforms.glsl -#include varyings.glsl - -const vec3 b_color = vec3(0.0, 0.0, 0.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 >= 5.0)) { - vec2 dfx = dFdx(gcv_TexCoord); - vec2 dfy = dFdy(gcv_TexCoord); - - // vec2 size; - //#if __VERSION__ < 130 - vec2 size = 1.0/gcu_TextureSize; - //#else - // size = 1.0/textureSize(gcu_TextureUnit,0); - //#endif - rtex -= 5.0; - vec4 t = texture2D(gcu_TextureUnit, rtex)* 0.18; - - t += texture2D(gcu_TextureUnit, rtex + size*(vec2(1, 0)))*tex_weights.x; - t += texture2D(gcu_TextureUnit, rtex - size*(vec2(1, 0)))*tex_weights.x; - t += texture2D(gcu_TextureUnit, rtex + size*(vec2(0, 1)))*tex_weights.x; - t += texture2D(gcu_TextureUnit, rtex - size*(vec2(0, 1)))*tex_weights.x; - - t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(1, 0)))*tex_weights.y; - t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(1, 0)))*tex_weights.y; - t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(0, 1)))*tex_weights.y; - t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(0, 1)))*tex_weights.y; - - t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(1, 0)))*tex_weights.z; - t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(1, 0)))*tex_weights.z; - t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(0, 1)))*tex_weights.z; - t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(0, 1)))*tex_weights.z; - - t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(1, 0)))*tex_weights.w; - t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(1, 0)))*tex_weights.w; - 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; - - 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)) { - rtex.y -= 0.1; - - if(rtex.y < 0.0) { - if(gcv_TexCoord.y < 0.0) { - discard; - } else { - rtex.y = 0.0; - } - } - vec2 dtx = dFdx(rtex); - vec2 dty = dFdy(rtex); - - float w = gcu_Weight; - float pd = ((2.0 - (2.0*w))*rtex.x*rtex.x) + 2.0*(w-1.0)*rtex.x + 1.0; - float position = rtex.y - ((w*rtex.x*(1.0 - rtex.x))/pd); - - float aph = 2.0 - 2.0*w; - - float gd = (aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0)*(aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0); - vec2 f = vec2((dtx.y - (w*dtx.x*(1.0 - 2.0*rtex.x))/gd), (dty.y - (w*dty.x*(1.0 - 2.0*rtex.x))/gd)); - - 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; - } - } - gl_FragColor = vec4(c, alpha); -} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02a-es2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02a-es2.fp new file mode 100644 index 000000000..b52420350 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02a-es2.fp @@ -0,0 +1,14 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#version 100 + +// we require dFdx/dFdy +// #extension OES_standard_derivatives : require +#extension GL_OES_standard_derivatives : enable + +precision mediump float; +precision mediump int; +precision mediump sampler2D; + +#include curverenderer02a-xxx.fp + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02a-gl2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02a-gl2.fp new file mode 100644 index 000000000..01715daa5 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02a-gl2.fp @@ -0,0 +1,6 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#version 110 + +#include curverenderer02a-xxx.fp + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02a-xxx.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02a-xxx.fp new file mode 100644 index 000000000..d31bafb5a --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02a-xxx.fp @@ -0,0 +1,48 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +// +// 1-pass shader w/ weight +// + +#include uniforms.glsl +#include varyings.glsl + +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)) { + rtex.y -= 0.1; + + if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) { + // discard; // freezes NV tegra2 compiler + alpha = 0.0; + } else { + rtex.y = max(rtex.y, 0.0); + + vec2 dtx = dFdx(rtex); + vec2 dty = dFdy(rtex); + + float w = gcu_Weight; + float pd = ((2.0 - (2.0*w))*rtex.x*rtex.x) + 2.0*(w-1.0)*rtex.x + 1.0; + float position = rtex.y - ((w*rtex.x*(1.0 - rtex.x))/pd); + + float aph = 2.0 - 2.0*w; + + float gd = (aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0)*(aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0); + vec2 f = vec2((dtx.y - (w*dtx.x*(1.0 - 2.0*rtex.x))/gd), (dty.y - (w*dty.x*(1.0 - 2.0*rtex.x))/gd)); + + // FIXME: will we ever set gcu_Alpha != 1.0 ? If not, a==alpha! + float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0); + alpha = gcu_Alpha * a; + } + } + + gl_FragColor = vec4(c, alpha); +} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02b-es2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02b-es2.fp new file mode 100644 index 000000000..e0486dd7b --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02b-es2.fp @@ -0,0 +1,14 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#version 100 + +// we require dFdx/dFdy +// #extension OES_standard_derivatives : require +#extension GL_OES_standard_derivatives : enable + +precision mediump float; +precision mediump int; +precision mediump sampler2D; + +#include curverenderer02b-xxx.fp + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02b-gl2.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02b-gl2.fp new file mode 100644 index 000000000..b1cc72188 --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02b-gl2.fp @@ -0,0 +1,6 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#version 110 + +#include curverenderer02b-xxx.fp + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02b-xxx.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02b-xxx.fp new file mode 100644 index 000000000..be738498c --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer02b-xxx.fp @@ -0,0 +1,88 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +// +// 2-pass shader w/ weight +// + +#include uniforms.glsl +#include varyings.glsl + +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 >= 5.0)) { + vec2 dfx = dFdx(gcv_TexCoord); + vec2 dfy = dFdy(gcv_TexCoord); + + vec2 size = 1.0/gcu_TextureSize; + + rtex -= 5.0; + vec4 t = texture2D(gcu_TextureUnit, rtex)* 0.18; + + t += texture2D(gcu_TextureUnit, rtex + size*(vec2(1, 0)))*tex_weights.x; + t += texture2D(gcu_TextureUnit, rtex - size*(vec2(1, 0)))*tex_weights.x; + t += texture2D(gcu_TextureUnit, rtex + size*(vec2(0, 1)))*tex_weights.x; + t += texture2D(gcu_TextureUnit, rtex - size*(vec2(0, 1)))*tex_weights.x; + + t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(1, 0)))*tex_weights.y; + t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(1, 0)))*tex_weights.y; + t += texture2D(gcu_TextureUnit, rtex + 2.0*size*(vec2(0, 1)))*tex_weights.y; + t += texture2D(gcu_TextureUnit, rtex - 2.0*size*(vec2(0, 1)))*tex_weights.y; + + t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(1, 0)))*tex_weights.z; + t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(1, 0)))*tex_weights.z; + t += texture2D(gcu_TextureUnit, rtex + 3.0*size*(vec2(0, 1)))*tex_weights.z; + t += texture2D(gcu_TextureUnit, rtex - 3.0*size*(vec2(0, 1)))*tex_weights.z; + + t += texture2D(gcu_TextureUnit, rtex + 4.0*size*(vec2(1, 0)))*tex_weights.w; + t += texture2D(gcu_TextureUnit, rtex - 4.0*size*(vec2(1, 0)))*tex_weights.w; + 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 + 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)) { + rtex.y -= 0.1; + + if(rtex.y < 0.0 && gcv_TexCoord.y < 0.0) { + // discard; // freezes NV tegra2 compiler + alpha = 0.0; + } else { + rtex.y = max(rtex.y, 0.0); + + vec2 dtx = dFdx(rtex); + vec2 dty = dFdy(rtex); + + float w = gcu_Weight; + float pd = ((2.0 - (2.0*w))*rtex.x*rtex.x) + 2.0*(w-1.0)*rtex.x + 1.0; + float position = rtex.y - ((w*rtex.x*(1.0 - rtex.x))/pd); + + float aph = 2.0 - 2.0*w; + + float gd = (aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0)*(aph*rtex.x*rtex.x + 2.0*rtex.x + 1.0); + vec2 f = vec2((dtx.y - (w*dtx.x*(1.0 - 2.0*rtex.x))/gd), (dty.y - (w*dty.x*(1.0 - 2.0*rtex.x))/gd)); + + // FIXME: will we ever set gcu_Alpha != 1.0 ? If not, a==alpha! + float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_TexCoord.y), 0.0, 1.0); + alpha = gcu_Alpha * a; + } + } + + gl_FragColor = vec4(c, alpha); +} diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl index 9d8ea75ea..5bbd5de14 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl @@ -12,6 +12,8 @@ uniform sampler2D gcu_TextureUnit; uniform vec2 gcu_TextureSize; // #endif +// const int MAX_TEXTURE_UNITS = 8; // <= gl_MaxTextureImageUnits +// const int MAX_LIGHTS = 8; // uniform mat3 gcu_NormalMatrix; // transpose(inverse(ModelView)).3x3 // uniform int gcu_ColorEnabled; // uniform int gcu_TexCoordEnabled[MAX_TEXTURE_UNITS]; -- cgit v1.2.3